제출 #516722

#제출 시각아이디문제언어결과실행 시간메모리
516722KoDTrobojnica (COCI19_trobojnica)C++17
0 / 110
2063 ms208 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...