#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, nxt[N], col[N], cnt[3], x[N], y[N], z[N];
string s;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for(int i = 0; i < n; i++)
{
int C = s[i] - '1';
col[i] = C;
cnt[C]++;
nxt[i] = (i + 1) % n;
}
for(int i = 0; i < n - 3; i++)
{
if(max({cnt[0], cnt[1], cnt[2]}) == n - i + 1)
{
cout << "NE";
return 0;
}
int X = 0;
while(col[X] == col[nxt[X]] || (cnt[col[X]] == 1 && cnt[col[nxt[X]]] == 1)) X = nxt[X];
int Y = nxt[X];
int new_col = 3 - col[X] - col[Y];
cnt[col[X]]--;
cnt[col[Y]]--;
cnt[new_col]++;
col[X] = new_col;
nxt[X] = nxt[Y];
x[i] = X + 1;
y[i] = nxt[Y] + 1;
z[i] = new_col + 1;
}
if(cnt[0] == 1 && cnt[1] == 1)
{
cout << "DA\n";
for(int i = 0; i < n - 3; i++)
cout << x[i] << ' ' << y[i] << ' ' << z[i] << '\n';
}
else cout << "NE";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Execution timed out |
2079 ms |
204 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Execution timed out |
2079 ms |
204 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Execution timed out |
2079 ms |
204 KB |
Time limit exceeded |