# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1004373 | 2024-06-21T08:22:16 Z | aykhn | Trobojnica (COCI19_trobojnica) | C++17 | 2000 ms | 13152 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; template<class T> using os = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define inf 0x3F3F3F3F3F3F3F3F const int MXN = 20 + 5; const int mod = 1e9 + 7; const int LOG = 20; int n; vector<array<int, 3>> res; os<array<int, 3>> s; int ok() { if (s.size() == 3) { array<int, 3> x = *s.begin(), y = *next(s.begin()), z = *next(next(s.begin())); return x[2] != y[2] && x[2] != z[2] && y[2] != z[2]; } int cnt = 0; for (int i = 0; i < s.size(); i++) { auto x = s.find_by_order(i); auto y = (next(x) == s.end() ? s.begin() : next(x)); array<int, 3> A = *x, B = *y; if (A[2] != B[2]) { s.erase(A), s.erase(B); s.insert({A[0], B[1], 6 - A[2] - B[2]}); if (ok()) { res.push_back({A[0], B[1], 6 - A[2] - B[2]}); return 1; } s.erase({A[0], B[1], 6 - A[2] - B[2]}); s.insert(A), s.insert(B); } } return 0; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; vector<array<int, 3>> v; int cnt[3] = {0, 0, 0}; for (int i = 0; i < n; i++) { char ch; cin >> ch; s.insert({i + 1, (i + 1) % n + 1, ch - '0'}); cnt[ch - '0' - 1]++; } if (cnt[0] % 2 != cnt[1] % 2 || cnt[0] % 2 != cnt[1] % 2 || cnt[1] % 2 != cnt[2] % 2) { cout << "NE\n"; return 0; } if (!ok()) cout << "NE\n"; else { cout << "DA\n"; for (array<int, 3> &x : res) cout << x[0] << ' ' << x[1] << ' ' << x[2] << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 6 ms | 600 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 452 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 4 ms | 528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 6 ms | 600 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 452 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 604 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 4 ms | 528 KB | Output is correct |
21 | Execution timed out | 2080 ms | 13152 KB | Time limit exceeded |
22 | Halted | 0 ms | 0 KB | - |