This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// iee
#include <bits/stdc++.h>
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);
template <class T> void read(T &x) {
x = 0; int f = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
x *= f;
}
int main() {
int TT = 1; // cin >> TT;
rep(CAS, 1, TT)
work(CAS);
return 0;
}
const int N = 2e5 + 5;
int n;
char s[N];
int nxt[N], col[N], cnt[5];
void work(int CASE) {
read(n);
scanf("%s", s);
rep(i, 0, n - 1) ++cnt[col[i] = s[i] - '0'], nxt[i] = (i + 1) % n;
rep(i, 1, 3) if (cnt[i] == n || cnt[i] % 2 != (n - 2) % 2) { puts("NE"); return; }
puts("DA");
int idx = 0;
rep(t, 1, n - 3) {
while (col[idx] == col[nxt[idx]] || cnt[col[idx]] == 1 && cnt[col[nxt[idx]]] == 1) idx = nxt[idx];
int c = 6 - col[idx] - col[nxt[idx]];
printf("%d %d %d\n", idx + 1, nxt[nxt[idx]] + 1, c);
cnt[col[idx]]--, cnt[col[nxt[idx]]]--, cnt[c]++;
nxt[idx] = nxt[nxt[idx]], col[idx] = c;
}
}
Compilation message (stderr)
trobojnica.cpp: In function 'void work(int)':
trobojnica.cpp:38:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
38 | while (col[idx] == col[nxt[idx]] || cnt[col[idx]] == 1 && cnt[col[nxt[idx]]] == 1) idx = nxt[idx];
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
trobojnica.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%s", s);
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |