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>
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;
}
int X = 0;
for(int i = 0; i < n - 3; i++)
{
if(max({cnt[0], cnt[1], cnt[2]}) == n - i)
{
cout << "NE";
return 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |