# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442555 | jesus_coconut | Trobojnica (COCI19_trobojnica) | C++17 | 2 ms | 204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define dbg(x) cerr << #x << " = " << x << '\n';
#define F first
#define S second
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
list<pair<int, int>> l;
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
l.push_back({i + 1, c - '0'});
}
vector<array<int, 3>> ans;
int cnt = 0;
for (auto it = l.begin(); cnt < 500000; ++cnt) {
auto sit = l.begin();
if (next(it) != l.end()) {
sit = next(it);
}
if (it->second != sit->second) {
auto nit = next(sit);
if (nit == l.end()) nit = l.begin();
if (next(nit) == it || (next(nit) == l.end() && l.begin() == it)) {
if (it->S + sit->S + nit->S != 6) {
cout << "NE\n";
return;
} else {
break;
}
}
ans.push_back({it->F, nit->F, 6 - it->S - sit->S});
it->second = 6 - it->S - sit->S;
l.erase(sit);
if (it != l.begin()) {
it = prev(it);
} else {
it = prev(l.end());
}
} else {
if (next(it) != l.end()) {
it = next(it);
} else it = l.begin();
}
if (ans.size() > n - 3) {
cout << "NE\n";
return;
}
}
if (ans.size() != n - 3) {
cout << "NE\n";
return;
}
cout << "DA\n";
for (auto &arr : ans) {
for (auto a : arr) {
cout << a << ' ';
}
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |