#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
#define endl '\n'
int suc[maxn];
int pre[maxn];
int succol[maxn], precol[maxn];
int main() {
ios_base :: sync_with_stdio (false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int freq[] = {0, 0, 0, 0};
for(int i = 0; i < n; i++) {
pre[i] = (n + i - 1) % n;
suc[i] = (i + 1) % n;
freq[s[i] - '0'] += 1;
precol[i] = s[pre[i]] - '0';
succol[i] = s[i] - '0';
}
if(freq[1] == n || freq[2] == n || freq[3] == n) {
cout << "NE" << endl;
exit(0);
}
if(abs(freq[1] - freq[2]) % 2 == 1 || abs(freq[2] - freq[3]) % 2 == 1) {
cout << "NE" << endl;
exit(0);
}
cout << "DA" << endl;
int cur = 0;
for(int i = 0; i < n - 3; i++) {
int occur = max({freq[1], freq[2], freq[3]});
int col;
for(col = 1; col <= 3; col++) {
if(freq[col] == occur) break;
}
while(true) {
if(precol[cur] != succol[cur] &&
(col == precol[cur] || col == succol[cur])) {
int inv = 6 - precol[cur] - succol[cur];
freq[precol[cur]] -= 1;
freq[succol[cur]] -= 1;
freq[inv] += 1;
cout << pre[cur] + 1 << " " << suc[cur] + 1 << " " << inv << endl;
pre[suc[cur]] = pre[cur]; precol[suc[cur]] = inv;
suc[pre[cur]] = suc[cur]; succol[pre[cur]] = inv;
cur = suc[cur];
break;
} else {
cur = suc[cur];
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Execution timed out |
2085 ms |
4228 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |