이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
vector<int> id(N), label(N), next(N);
for (int i = 0; i < N; ++i) {
char c;
std::cin >> c;
id[i] = i;
label[i] = c - '1';
next[i] = i + 1 == N ? 0 : i + 1;
}
array<int, 3> count = {};
for (const int x : label) {
count[x] += 1;
}
for (const int x : count) {
if (x == N or x % 2 != N % 2) {
std::cout << "NE\n";
return 0;
}
}
std::cout << "DA\n";
int root = 0;
for (int step = 0; step < N - 3; ++step) {
while (label[root] == label[next[root]] or (count[label[root]] == 1 and count[label[next[root]]] == 1)) {
root = next[root];
}
const int x = root;
const int y = next[x];
const int z = next[y];
const int c = 3 - label[x] - label[y];
std::cout << x + 1 << ' ' << z + 1 << ' ' << c + 1 << '\n';
next[x] = z;
label[x] = c;
}
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... |