Submission #492347

# Submission time Handle Problem Language Result Execution time Memory
492347 2021-12-07T00:47:14 Z vuavisao Trobojnica (COCI19_trobojnica) C++17
110 / 110
78 ms 7772 KB
#include <bits/stdc++.h>
using namespace std;

const int MaxN = 2e5 + 10;
int nxt[MaxN], color[MaxN], cnt[3];
int sol_x[MaxN], sol_y[MaxN], sol_c[MaxN];

int main() {
    int n;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n; i++) {
        color[i] = s[i] - '1';
        cnt[s[i] - '1']++;
        nxt[i] = (i + 1) % n;
    }

    int x = 0;
    for (int i = 0; i < n - 3; i++) {
        if (max(cnt[0], max(cnt[1], cnt[2])) == n - i) {
            cout << "NE\n";
            return 0;
        }

        while (color[x] == color[nxt[x]] ||
               (cnt[color[x]] == 1 && cnt[color[nxt[x]]] == 1))
            x = nxt[x];

        int y = nxt[x];
        int new_color = 3 - color[x] - color[y];
        cnt[color[x]]--;
        cnt[color[y]]--;
        cnt[new_color]++;
        color[x] = new_color;
        nxt[x] = nxt[y];
        sol_x[i] = x;
        sol_y[i] = nxt[y];
        sol_c[i] = new_color;
    }

    if (cnt[0] == 1 && cnt[1] == 1) {
        cout << "DA\n";
        for (int i = 0; i < n - 3; i++)
            cout << sol_x[i] + 1 << " "
                 << sol_y[i] + 1 << " "
                 << sol_c[i] + 1 << "\n";
    } else {
        cout << "NE\n";
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 57 ms 7772 KB Output is correct
22 Correct 55 ms 6720 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 78 ms 7632 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 30 ms 3888 KB Output is correct
28 Correct 10 ms 4700 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 7 ms 2364 KB Output is correct