feat: usaco
This commit is contained in:
parent
659cac6af3
commit
00d23dc313
106 changed files with 2569 additions and 52 deletions
9
usaco/bronze/simulation/.clang-format
Normal file
9
usaco/bronze/simulation/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
35
usaco/bronze/simulation/.clangd
Normal file
35
usaco/bronze/simulation/.clangd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-Wno-unknown-pragmas
|
||||
-std=c++17
|
||||
-std=c++17
|
||||
75
usaco/bronze/simulation/cbarn.cc
Normal file
75
usaco/bronze/simulation/cbarn.cc
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vector<u64> r(n);
|
||||
for (auto& e : r)
|
||||
cin >> e;
|
||||
|
||||
i64 ans = MAX<i64>;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
i64 moves = 0;
|
||||
i64 total = accumulate(all(r), 0LL);
|
||||
for (i32 j = 0; j < n; ++j) {
|
||||
total -= r[(i + j) % n];
|
||||
moves += total;
|
||||
}
|
||||
ans = min(ans, moves);
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "cbarn"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
30
usaco/bronze/simulation/compile_flags.txt
Normal file
30
usaco/bronze/simulation/compile_flags.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-std=c++17
|
||||
12
usaco/bronze/simulation/debug_flags.txt
Normal file
12
usaco/bronze/simulation/debug_flags.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
-g3
|
||||
-fsanitize=address,undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fno-sanitize-recover=all
|
||||
-fstack-protector-all
|
||||
-fstack-usage
|
||||
-fno-omit-frame-pointer
|
||||
-fno-inline
|
||||
-ffunction-sections
|
||||
-D_GLIBCXX_DEBUG
|
||||
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||
6
usaco/bronze/simulation/io/cbarn.in
Normal file
6
usaco/bronze/simulation/io/cbarn.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
4
|
||||
7
|
||||
8
|
||||
6
|
||||
4
|
||||
4
usaco/bronze/simulation/io/cbarn.out
Normal file
4
usaco/bronze/simulation/io/cbarn.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
48
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.08571 ms
|
||||
5
usaco/bronze/simulation/io/measurement.in
Normal file
5
usaco/bronze/simulation/io/measurement.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
7 Mildred +3
|
||||
4 Elsie -1
|
||||
9 Mildred -1
|
||||
1 Bessie +2
|
||||
4
usaco/bronze/simulation/io/measurement.out
Normal file
4
usaco/bronze/simulation/io/measurement.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.39191 ms
|
||||
3
usaco/bronze/simulation/io/mixmilk.in
Normal file
3
usaco/bronze/simulation/io/mixmilk.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
10 3
|
||||
11 4
|
||||
12 5
|
||||
6
usaco/bronze/simulation/io/mixmilk.out
Normal file
6
usaco/bronze/simulation/io/mixmilk.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
0
|
||||
10
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.54783 ms
|
||||
7
usaco/bronze/simulation/io/mowing.in
Normal file
7
usaco/bronze/simulation/io/mowing.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
N 10
|
||||
E 2
|
||||
S 3
|
||||
W 4
|
||||
S 5
|
||||
E 8
|
||||
4
usaco/bronze/simulation/io/mowing.out
Normal file
4
usaco/bronze/simulation/io/mowing.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
10
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.64821 ms
|
||||
7
usaco/bronze/simulation/io/rut.in
Normal file
7
usaco/bronze/simulation/io/rut.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
E 3 5
|
||||
N 5 3
|
||||
E 4 6
|
||||
E 10 4
|
||||
N 11 2
|
||||
N 8 1
|
||||
9
usaco/bronze/simulation/io/rut.out
Normal file
9
usaco/bronze/simulation/io/rut.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
5
|
||||
3
|
||||
Infinity
|
||||
Infinity
|
||||
2
|
||||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.8356 ms
|
||||
4
usaco/bronze/simulation/io/shell-game.in
Normal file
4
usaco/bronze/simulation/io/shell-game.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
1 2 1
|
||||
3 2 1
|
||||
1 3 1
|
||||
4
usaco/bronze/simulation/io/shell-game.out
Normal file
4
usaco/bronze/simulation/io/shell-game.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.1527 ms
|
||||
7
usaco/bronze/simulation/io/speeding.in
Normal file
7
usaco/bronze/simulation/io/speeding.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3 3
|
||||
40 75
|
||||
50 35
|
||||
10 45
|
||||
40 76
|
||||
20 30
|
||||
40 40
|
||||
4
usaco/bronze/simulation/io/speeding.out
Normal file
4
usaco/bronze/simulation/io/speeding.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.50397 ms
|
||||
5
usaco/bronze/simulation/io/traffic.in
Normal file
5
usaco/bronze/simulation/io/traffic.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
on 1 1
|
||||
none 10 14
|
||||
none 11 15
|
||||
off 2 3
|
||||
5
usaco/bronze/simulation/io/traffic.out
Normal file
5
usaco/bronze/simulation/io/traffic.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
10 13
|
||||
8 12
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.91054 ms
|
||||
3
usaco/bronze/simulation/io/ttt.in
Normal file
3
usaco/bronze/simulation/io/ttt.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
COW
|
||||
XXO
|
||||
ABC
|
||||
13
usaco/bronze/simulation/io/ttt.out
Normal file
13
usaco/bronze/simulation/io/ttt.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
2
|
||||
x=C is false
|
||||
x=C is false
|
||||
x=X is false
|
||||
x=O is true
|
||||
x=X is false
|
||||
x=A is false
|
||||
x=W is false
|
||||
x=C is false
|
||||
x=W is false
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.11177 ms
|
||||
3
usaco/bronze/simulation/io/tttt.in
Normal file
3
usaco/bronze/simulation/io/tttt.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
COW
|
||||
XCX
|
||||
ABC
|
||||
4
usaco/bronze/simulation/io/tttt.out
Normal file
4
usaco/bronze/simulation/io/tttt.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1
|
||||
1
|
||||
[code]: 0
|
||||
[time]: 4.28891 ms
|
||||
29
usaco/bronze/simulation/makefile
Normal file
29
usaco/bronze/simulation/makefile
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
.PHONY: run debug clean setup init
|
||||
|
||||
VERSION ?= 20
|
||||
|
||||
SRC = $(word 2,$(MAKECMDGOALS))
|
||||
|
||||
.SILENT:
|
||||
|
||||
run:
|
||||
sh scripts/run.sh $(SRC)
|
||||
|
||||
debug:
|
||||
sh scripts/debug.sh $(SRC)
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
|
||||
setup:
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
test -d scripts || mkdir -p scripts
|
||||
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
|
||||
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
|
||||
|
||||
init:
|
||||
make setup
|
||||
|
||||
%:
|
||||
@:
|
||||
112
usaco/bronze/simulation/measurement.cc
Normal file
112
usaco/bronze/simulation/measurement.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
map<u32, array<i32, 3>> deltas;
|
||||
|
||||
u32 day;
|
||||
string name;
|
||||
i32 delta;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> day >> name >> delta;
|
||||
|
||||
if (name[0] == 'M') {
|
||||
deltas[day][0] = delta;
|
||||
} else if (name[0] == 'E') {
|
||||
deltas[day][1] = delta;
|
||||
} else {
|
||||
deltas[day][2] = delta;
|
||||
}
|
||||
}
|
||||
|
||||
u32 last_winners = 0b111;
|
||||
vector<i64> vals(3, 0);
|
||||
i64 ans = 0;
|
||||
for (auto it = deltas.begin(); it != deltas.end(); ++it) {
|
||||
for (u32 j = 0; j < 3; ++j) {
|
||||
vals[j] += it->second[j];
|
||||
}
|
||||
i64 large = *max_element(all(vals));
|
||||
u32 winners = 0b000;
|
||||
for (u32 j = 0; j < 3; ++j) {
|
||||
winners |= u32(vals[j] == large) << j;
|
||||
}
|
||||
|
||||
ans += last_winners != winners;
|
||||
last_winners = winners;
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "measurement"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
90
usaco/bronze/simulation/mixmilk.cc
Normal file
90
usaco/bronze/simulation/mixmilk.cc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
vector<u64> c(3), m(3);
|
||||
for (u32 i = 0; i < 3; ++i) {
|
||||
cin >> c[i] >> m[i];
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < 100; ++i) {
|
||||
u64 pour = min(m[i % 3], c[(i + 1) % 3] - m[(i + 1) % 3]);
|
||||
m[i % 3] -= pour;
|
||||
m[(i + 1) % 3] += pour;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < 3; ++i) {
|
||||
cout << m[i] << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "mixmilk"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
101
usaco/bronze/simulation/mowing.cc
Normal file
101
usaco/bronze/simulation/mowing.cc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 n;
|
||||
cin >> n;
|
||||
map<pair<i64, i64>, i64> m;
|
||||
m[{0, 0}] = 0;
|
||||
char dir;
|
||||
i64 delta;
|
||||
i64 x = 0, y = 0;
|
||||
i64 ans = MAX<i64>, t = 0;
|
||||
while (n--) {
|
||||
cin >> dir >> delta;
|
||||
|
||||
i64 dx = 0, dy = 0;
|
||||
|
||||
switch (dir) {
|
||||
case 'N':
|
||||
dy = 1;
|
||||
break;
|
||||
case 'E':
|
||||
dx = 1;
|
||||
break;
|
||||
case 'S':
|
||||
dy = -1;
|
||||
break;
|
||||
case 'W':
|
||||
dx = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i64 i = 0; i < abs(delta); ++i) {
|
||||
++t;
|
||||
x += dx;
|
||||
y += dy;
|
||||
if (m.find({x, y}) != m.end()) {
|
||||
ans = min(ans, t - m[{x, y}]);
|
||||
}
|
||||
m[{x, y}] = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (ans == MAX<i64>)
|
||||
cout << "-1\n";
|
||||
else
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "mowing"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
112
usaco/bronze/simulation/rut.cc
Normal file
112
usaco/bronze/simulation/rut.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
struct Cow {
|
||||
u32 i;
|
||||
i64 x, y;
|
||||
};
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vector<Cow> east_cows, north_cows;
|
||||
vector<i64> ans(n, -1);
|
||||
|
||||
char dir;
|
||||
i64 x, y;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> dir >> x >> y;
|
||||
|
||||
Cow cow{i, x, y};
|
||||
if (dir == 'E') {
|
||||
east_cows.emplace_back(cow);
|
||||
} else {
|
||||
north_cows.emplace_back(cow);
|
||||
}
|
||||
}
|
||||
|
||||
sort(all(east_cows), [](auto const& c1, auto const& c2) {
|
||||
return c1.y < c2.y;
|
||||
});
|
||||
sort(all(north_cows), [](auto const& c1, auto const& c2) {
|
||||
return c1.x < c2.x;
|
||||
});
|
||||
|
||||
for (auto& nc : north_cows) {
|
||||
for (auto& ec : east_cows) {
|
||||
if (ec.x > nc.x || nc.y >= ec.y || ans[ec.i] != -1)
|
||||
continue;
|
||||
|
||||
auto et = nc.x - ec.x;
|
||||
auto nt = ec.y - nc.y;
|
||||
|
||||
if (nt < et) {
|
||||
ans[ec.i] = et;
|
||||
}
|
||||
if (et < nt) {
|
||||
ans[nc.i] = nt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& e : ans) {
|
||||
if (e == -1) {
|
||||
cout << "Infinity";
|
||||
} else {
|
||||
cout << e;
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "rut"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
29
usaco/bronze/simulation/scripts/debug.sh
Normal file
29
usaco/bronze/simulation/scripts/debug.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
DBG_BIN="${BASE}.debug"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
DBG_BIN="build/$DBG_BIN"
|
||||
|
||||
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
29
usaco/bronze/simulation/scripts/run.sh
Normal file
29
usaco/bronze/simulation/scripts/run.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
RUN_BIN="${BASE}.run"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
RUN_BIN="build/$RUN_BIN"
|
||||
|
||||
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
53
usaco/bronze/simulation/scripts/utils.sh
Normal file
53
usaco/bronze/simulation/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
CODE=$?
|
||||
end=$(date '+%s.%N')
|
||||
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||
|
||||
if [ $CODE -ge 124 ]; then
|
||||
MSG=''
|
||||
case $CODE in
|
||||
124) MSG='TIMEOUT' ;;
|
||||
128) MSG='SIGILL' ;;
|
||||
130) MSG='SIGABRT' ;;
|
||||
131) MSG='SIGBUS' ;;
|
||||
136) MSG='SIGFPE' ;;
|
||||
135) MSG='SIGSEGV' ;;
|
||||
137) MSG='SIGPIPE' ;;
|
||||
139) MSG='SIGTERM' ;;
|
||||
esac
|
||||
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||
else
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
fi
|
||||
|
||||
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||
return $CODE
|
||||
}
|
||||
|
||||
compile_source() {
|
||||
src="$1"
|
||||
bin="$2"
|
||||
output="$3"
|
||||
flags="$4"
|
||||
|
||||
test -f "$bin" && rm "$bin" || true
|
||||
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||
CODE=$?
|
||||
|
||||
if [ $CODE -gt 0 ]; then
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
return $CODE
|
||||
else
|
||||
echo '' >"$output"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
97
usaco/bronze/simulation/shell.cc
Normal file
97
usaco/bronze/simulation/shell.cc
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
vector<u32> shell_locs(3), shell_counts(3, 0);
|
||||
iota(all(shell_locs), 0);
|
||||
|
||||
u32 n, a, b, g;
|
||||
cin >> n;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a >> b >> g;
|
||||
|
||||
--a;
|
||||
--b;
|
||||
--g;
|
||||
for (u32 j = 0; j < shell_locs.size(); ++j) {
|
||||
if (shell_locs[j] == a)
|
||||
shell_locs[j] = b;
|
||||
else if (shell_locs[j] == b)
|
||||
shell_locs[j] = a;
|
||||
shell_counts[j] += shell_locs[j] == g;
|
||||
}
|
||||
}
|
||||
|
||||
cout << *max_element(all(shell_counts)) << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "shell"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
106
usaco/bronze/simulation/speeding.cc
Normal file
106
usaco/bronze/simulation/speeding.cc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
i32 n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vector<pair<i32, i32>> limit(n), cow(m);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> limit[i].ff >> limit[i].ss;
|
||||
if (i)
|
||||
limit[i].ff += limit[i - 1].ff;
|
||||
}
|
||||
for (u32 i = 0; i < m; ++i) {
|
||||
cin >> cow[i].ff >> cow[i].ss;
|
||||
if (i)
|
||||
cow[i].ff += cow[i - 1].ff;
|
||||
}
|
||||
|
||||
i32 i = -1, j = -1;
|
||||
|
||||
i32 ans = 0;
|
||||
while (j < m) {
|
||||
if (i == -1) {
|
||||
++i;
|
||||
++j;
|
||||
} else if (i + 1 < n && limit[i + 1].ff <= cow[j].ff) {
|
||||
++i;
|
||||
} else {
|
||||
++j;
|
||||
}
|
||||
ans = max(ans, cow[j].ss - limit[i].ss);
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "speeding"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
122
usaco/bronze/simulation/traffic.cc
Normal file
122
usaco/bronze/simulation/traffic.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
string type;
|
||||
i64 l, r;
|
||||
vector<tuple<string, i64, i64>> segments;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> type >> l >> r;
|
||||
segments.emplace_back(type, l, r);
|
||||
}
|
||||
|
||||
i64 lb = 0, ub = 1e9;
|
||||
for (auto it = segments.rbegin(); it != segments.rend(); ++it) {
|
||||
tie(type, l, r) = *it;
|
||||
if (type == "none") {
|
||||
lb = max(lb, l);
|
||||
ub = min(ub, r);
|
||||
} else if (type == "off") {
|
||||
lb += l;
|
||||
ub += r;
|
||||
} else if (type == "on") {
|
||||
lb = max(lb - r, (i64)0);
|
||||
ub = max(ub - l, (i64)0);
|
||||
}
|
||||
}
|
||||
cout << lb << ' ' << ub << '\n';
|
||||
|
||||
lb = 0, ub = 1e9;
|
||||
for (auto& segment : segments) {
|
||||
// NOTE: how does this work?
|
||||
tie(type, l, r) = segment;
|
||||
if (type == "none") {
|
||||
lb = max(lb, l);
|
||||
ub = min(ub, r);
|
||||
} else if (type == "off") {
|
||||
lb = max(lb - r, (i64)0);
|
||||
ub = max(ub - l, (i64)0);
|
||||
} else if (type == "on") {
|
||||
lb += l;
|
||||
ub += r;
|
||||
}
|
||||
}
|
||||
|
||||
cout << lb << ' ' << ub << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "traffic"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
107
usaco/bronze/simulation/tttt.cc
Normal file
107
usaco/bronze/simulation/tttt.cc
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
vector<string> grid(3);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
u64 single = 0, two = 0;
|
||||
|
||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
||||
i32 ccountr = 0, dcountr = 0, ccountc = 0, dcountc = 0;
|
||||
bool done = false;
|
||||
for (u32 i = 0; i < 3 && !done; ++i) {
|
||||
ccountr = (grid[i][0] == c) + (grid[i][1] == c) + (grid[i][2] == c);
|
||||
ccountc = (grid[0][i] == c) + (grid[1][i] == c) + (grid[2][i] == c);
|
||||
if (ccountr == 3 || ccountc == 3) {
|
||||
++single;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
ccountr = (grid[0][0] == c) + (grid[1][1] == c) + (grid[2][2] == c);
|
||||
ccountc = (grid[2][0] == c) + (grid[1][1] == c) + (grid[0][2] == c);
|
||||
if (!done && (ccountr == 3 || ccountc == 3))
|
||||
++single;
|
||||
for (char d = 'A'; d < c; ++d) {
|
||||
bool done = false;
|
||||
for (u32 i = 0; i < 3 && !done; ++i) {
|
||||
ccountr = (grid[i][0] == c) + (grid[i][1] == c) + (grid[i][2] == c);
|
||||
dcountr = (grid[i][0] == d) + (grid[i][1] == d) + (grid[i][2] == d);
|
||||
ccountc = (grid[0][i] == c) + (grid[1][i] == c) + (grid[2][i] == c);
|
||||
dcountc = (grid[0][i] == d) + (grid[1][i] == d) + (grid[2][i] == d);
|
||||
|
||||
if (ccountr + dcountr == 3 && ccountr && dcountr ||
|
||||
ccountc + dcountc == 3 && ccountc && dcountc) {
|
||||
++(c == d ? single : two);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
ccountr = (grid[0][0] == c) + (grid[1][1] == c) + (grid[2][2] == c);
|
||||
dcountr = (grid[0][0] == d) + (grid[1][1] == d) + (grid[2][2] == d);
|
||||
ccountc = (grid[2][0] == c) + (grid[1][1] == c) + (grid[0][2] == c);
|
||||
dcountc = (grid[2][0] == d) + (grid[1][1] == d) + (grid[0][2] == d);
|
||||
|
||||
if (!done && ccountr + dcountr == 3 && ccountr && dcountr) {
|
||||
++(c == d ? single : two);
|
||||
} else if (!done && ccountc + dcountc == 3 && ccountc && dcountc) {
|
||||
++(c == d ? single : two);
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << single << '\n' << two;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
#define PROBLEM_NAME "tttt"
|
||||
|
||||
#ifdef LOCAL
|
||||
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
|
||||
#else
|
||||
freopen(PROBLEM_NAME ".in", "r", stdin);
|
||||
freopen(PROBLEM_NAME ".out", "w", stdout);
|
||||
#endif
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue