feat(codeforces/817): ak

This commit is contained in:
Barrett Ruth 2025-05-17 18:42:05 -05:00
parent c65a12a652
commit ee35513364
30 changed files with 1222 additions and 23 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

41
codeforces/817/.clangd Normal file
View file

@ -0,0 +1,41 @@
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++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23
-std=c++23

104
codeforces/817/a.cc Normal file
View file

@ -0,0 +1,104 @@
#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";
}
template <typename T>
using vec = std::vector<T>;
#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 s;
cin >> s;
sort(all(s));
string timur = "Timur";
sort(all(timur));
if (n != timur.size()) {
NO();
return;
}
for (u32 i = 0; i < n; ++i) {
if (s[i] == 'T') {
if (timur[i] != 'T') {
NO();
return;
}
} else {
if (s[i] != timur[i]) {
NO();
return;
}
}
}
YES();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

90
codeforces/817/b.cc Normal file
View 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;
#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";
}
template <typename T>
using vec = std::vector<T>;
#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 a, b;
cin >> a >> b;
for (u32 i = 0; i < n; ++i) {
if (a[i] == b[i] ||
(a[i] == 'G' || a[i] == 'B') && (b[i] == 'G' || b[i] == 'B')) {
continue;
}
NO();
return;
}
YES();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

103
codeforces/817/c.cc Normal file
View file

@ -0,0 +1,103 @@
#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";
}
template <typename T>
using vec = std::vector<T>;
#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;
vec<set<string>> words(3);
map<string, u32> count;
string word;
for (u32 i = 0; i < 3; ++i) {
for (u32 j = 0; j < n; ++j) {
cin >> word;
words[i].insert(word);
++count[word];
}
}
for (u32 i = 0; i < 3; ++i) {
u32 points = 0;
for (auto& w : words[i]) {
u32 x = (u32)words[0].contains(w) + words[1].contains(w) +
words[2].contains(w);
if (x == 2)
++points;
else if (x == 1)
points += 3;
}
cout << points << " \n"[i == 2];
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View 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++23

115
codeforces/817/d.cc Normal file
View file

@ -0,0 +1,115 @@
#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";
}
template <typename T>
using vec = std::vector<T>;
#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 s;
cin >> s;
vec<u64> deltas;
u64 initial_value = 0;
for (u32 i = 0; i < n; ++i) {
if (s[i] == 'L') {
u64 dont = i;
initial_value += dont;
u64 turn = n - i - 1;
if (turn > dont) {
deltas.emplace_back(turn - dont);
}
} else {
u64 dont = n - i - 1;
initial_value += dont;
u64 turn = i;
if (turn > dont) {
deltas.emplace_back(turn - dont);
}
}
}
sort(rall(deltas));
u32 i = 0;
u64 total = initial_value;
for (u32 k = 1; k <= n; ++k) {
if (i < deltas.size()) {
total += deltas[i];
++i;
}
cout << total << " \n"[k == n];
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-DLOCAL
-std=c++23

101
codeforces/817/e.cc Normal file
View 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;
#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";
}
template <typename T>
using vec = std::vector<T>;
#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, q;
cin >> n >> q;
vec<vec<u64>> prefix(1000 + 1, vec<u64>(1000 + 1, 0));
for (u32 i = 0; i < n; ++i) {
u64 h, w;
cin >> h >> w;
prefix[h][w] += h * w;
}
for (u32 i = 1; i <= 1000; ++i)
for (u32 j = 1; j <= 1000; ++j)
prefix[i][j] +=
prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1];
for (u32 i = 0; i < q; ++i) {
u32 hs, ws, hb, wb;
cin >> hs >> ws >> hb >> wb;
u64 ans = prefix[hb - 1][wb - 1] - prefix[hs][wb - 1] - prefix[hb - 1][ws] +
prefix[hs][ws];
cout << ans << '\n';
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

139
codeforces/817/f.cc Normal file
View file

@ -0,0 +1,139 @@
#include <bits/stdc++.h> // {{{
#include <algorithm>
// 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";
}
template <typename T>
using vec = std::vector<T>;
#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
// }}}
bitset<50 * 50 + 1> visited;
void solve() {
const i32 dr8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const i32 dc8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
u32 n, m;
cin >> n >> m;
vec<string> g(n);
for (auto& s : g)
cin >> s;
vec<vec<u32>> vis(n, vec<u32>(m, 0));
bool ok = true;
for (i32 r = 0; r < (i32)n && ok; ++r)
for (i32 c = 0; c < (i32)m && ok; ++c)
if (g[r][c] == '*' && !vis[r][c]) {
vec<pair<i32, i32>> comp;
vec<pair<i32, i32>> q = {{r, c}};
vis[r][c] = 1;
for (i32 qi = 0; qi < (i32)q.size(); ++qi) {
auto [x, y] = q[qi];
comp.push_back({x, y});
for (i32 d = 0; d < 8; ++d) {
i32 nx = x + dr8[d], ny = y + dc8[d];
if (0 <= nx && nx < (i32)n && 0 <= ny && ny < (i32)m &&
g[nx][ny] == '*' && !vis[nx][ny]) {
vis[nx][ny] = 1;
q.push_back({nx, ny});
}
}
}
if (comp.size() != 3) {
ok = false;
break;
}
vec<i32> rows, cols;
for (auto [x, y] : comp) {
rows.push_back(x);
cols.push_back(y);
}
sort(rows.begin(), rows.end());
rows.erase(unique(rows.begin(), rows.end()), rows.end());
sort(cols.begin(), cols.end());
cols.erase(unique(cols.begin(), cols.end()), cols.end());
if (rows.size() != 2 || cols.size() != 2) {
ok = false;
break;
}
i32 cnt = 0;
for (i32 i = 0; i < 2; ++i)
for (i32 j = 0; j < 2; ++j)
for (auto [x, y] : comp)
if (x == rows[i] && y == cols[j])
++cnt;
if (cnt != 3) {
ok = false;
break;
}
}
if (ok)
YES();
else
NO();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

110
codeforces/817/g.cc Normal file
View file

@ -0,0 +1,110 @@
#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";
}
template <typename T>
using vec = std::vector<T>;
#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;
vec<u32> a(n);
for (u32 i = 0; i < n; i += 2) a[i] = i >> 1;
u32 xe = 0;
for (u32 i = 0; i < n; i += 2) xe ^= a[i];
u32 odd = n >> 1;
if (!odd) {
for (u32 i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
return;
}
const u32 BIG = 1u << 20;
u32 xo = 0;
for (u32 k = 0; k + 2 < odd; ++k) {
a[1 + 2 * k] = BIG + k;
xo ^= a[1 + 2 * k];
}
if (odd == 1) {
a[1] = BIG;
a[0] ^= xe ^ BIG;
} else {
u32 diff = xe ^ xo;
u32 p = BIG + odd - 2;
a[2 * odd - 3] = p;
a[2 * odd - 1] = p ^ diff;
}
for (u32 i = 0; i < n; ++i)
cout << a[i] << " \n"[i == n - 1];
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

21
codeforces/817/io/a.in Normal file
View file

@ -0,0 +1,21 @@
10
5
Timur
5
miurT
5
Trumi
5
mriTu
5
timur
4
Timr
6
Timuur
10
codeforces
10
TimurTimur
5
TIMUR

13
codeforces/817/io/a.out Normal file
View file

@ -0,0 +1,13 @@
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
[code]: 0
[time]: 12.6028 ms

19
codeforces/817/io/b.in Normal file
View file

@ -0,0 +1,19 @@
6
2
RG
RB
4
GRBG
GBGB
5
GGGGG
BBBBB
7
BBBBBBB
RRRRRRR
8
RGBRRGBR
RGGRRBGR
1
G
G

9
codeforces/817/io/b.out Normal file
View file

@ -0,0 +1,9 @@
YES
NO
YES
NO
YES
YES
[code]: 0
[time]: 4.15921 ms

13
codeforces/817/io/c.in Normal file
View file

@ -0,0 +1,13 @@
3
1
abc
def
abc
3
orz for qaq
qaq orz for
cod for ces
5
iat roc hem ica lly
bac ter iol ogi sts
bac roc lly iol iat

6
codeforces/817/io/c.out Normal file
View file

@ -0,0 +1,6 @@
1 3 1
2 2 6
9 11 5
[code]: 0
[time]: 4.16636 ms

14
codeforces/817/io/d.in Normal file
View file

@ -0,0 +1,14 @@
6
3
LLR
5
LRRLL
1
L
12
LRRRLLLRLLRL
10
LLLLLRRRRR
9
LRLRLRLRL

9
codeforces/817/io/d.out Normal file
View file

@ -0,0 +1,9 @@
3 5 5
16 16 16 16 16
0
86 95 98 101 102 102 102 102 102 102 102 102
29 38 45 52 57 62 65 68 69 70
44 50 54 56 56 56 56 56 56
[code]: 0
[time]: 3.96514 ms

21
codeforces/817/io/e.in Normal file
View file

@ -0,0 +1,21 @@
3
2 1
2 3
3 2
1 1 3 4
5 5
1 1
2 2
3 3
4 4
5 5
3 3 6 6
2 1 4 5
1 1 2 10
1 1 100 100
1 1 3 3
3 1
999 999
999 999
999 998
1 1 1000 1000

10
codeforces/817/io/e.out Normal file
View file

@ -0,0 +1,10 @@
6
41
9
0
54
4
2993004
[code]: 0
[time]: 13.3142 ms

49
codeforces/817/io/f.in Normal file
View file

@ -0,0 +1,49 @@
10
6 10
........**
.**......*
..*..*....
.....**...
...*.....*
..**....**
6 10
....*...**
.**......*
..*..*....
.....**...
...*.....*
..**....**
3 3
...
***
...
4 4
.*..
**..
..**
..*.
5 4
.*..
**..
....
..**
..*.
3 2
.*
**
*.
2 3
*..
.**
3 2
..
**
*.
3 3
.**
*.*
**.
3 3
..*
.**
..*

13
codeforces/817/io/f.out Normal file
View file

@ -0,0 +1,13 @@
YES
NO
NO
NO
YES
NO
NO
YES
NO
NO
[code]: 0
[time]: 4.43125 ms

9
codeforces/817/io/g.in Normal file
View file

@ -0,0 +1,9 @@
7
8
3
4
5
6
7
9

10
codeforces/817/io/g.out Normal file
View file

@ -0,0 +1,10 @@
0 1048576 1 1048577 2 1048578 3 1048579
1048577 1048576 1
0 1048576 1 1048577
0 1048576 1 1048579 2
0 1048576 1 1048580 2 7
0 1048576 1 1048580 2 4 3
0 1048576 1 1048577 2 1048578 3 1048583 4
[code]: 0
[time]: 4.62723 ms

30
codeforces/817/makefile Normal file
View file

@ -0,0 +1,30 @@
.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 .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
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
%:
@:

View 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 $?

View 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 $?

View 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
}

View file

@ -58,30 +58,16 @@ using vec = std::vector<T>;
// }}}
void solve() {
vector<string> grid(8);
for (auto& e : grid)
cin >> e;
string s;
for (u32 i = 0; i < 8; ++i) {
cin >> s;
if (s == "RRRRRRRR") {
cout << "R\n";
return;
}
}
for (u32 r = 0; r < 8; ++r) {
bool good = true;
for (u32 c = 0; c < 8; ++c) {
good &= grid[r][c] == grid[r][0];
}
if (good && grid[r][0] == 'R') {
cout << grid[r][0] << '\n';
return;
}
}
for (u32 c = 0; c < 8; ++c) {
bool good = true;
for (u32 r = 0; r < 8; ++r) {
good &= grid[r][c] == grid[0][c];
}
if (good && grid[0][c] == 'B') {
cout << grid[0][c] << '\n';
return;
}
}
cout << "B\n";
}
int main() { // {{{