# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291561 | kingfran1907 | Trobojnica (COCI19_trobojnica) | C++14 | 1 ms | 384 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 X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n;
char niz[maxn];
int cl[maxn], cnt[10];
int nx[maxn];
vector< int > x, y, s;
int main() {
scanf("%d%s", &n, niz);
for (int i = 0; i < n; i++) {
cl[i] = niz[i] - '1';
cnt[cl[i]]++, nx[i] = (i + 1) % n;
}
int tren = 0;
for (int i = 0; i < n - 3; i++) {
if (max({cnt[0], cnt[1], cnt[2]}) == n - i) {
printf("NE\n");
return 0;
}
while (cl[tren] == cl[nx[tren]] || (cnt[cl[tren]] == 1 && cnt[cl[nx[tren]]] == 1)) {
tren = nx[tren];
}
int ac = nx[tren];
int ms = 1 + 2 - cl[tren] - cl[ac];
//printf("debug: %d %d\n", ac, ms);
cnt[cl[tren]]--, cnt[cl[ac]]--;
cnt[ms]++;
cl[tren] = ms, nx[tren] = nx[ac];
x.push_back(tren);
y.push_back(ac);
s.push_back(ms);
}
if (cnt[0] != 1 || cnt[1] != 1 || cnt[2] != 1) {
printf("NE\n");
return 0;
} else {
printf("DA\n");
for (int i = 0; i < x.size(); i++) {
printf("%d %d %d\n", x[i] + 1, y[i] + 1, s[i] + 1);
}
}
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... |