Submission #492349

# Submission time Handle Problem Language Result Execution time Memory
492349 2021-12-07T00:48:20 Z vuavisao Trobojnica (COCI19_trobojnica) C++17
110 / 110
49 ms 7604 KB
#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
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 49 ms 7604 KB Output is correct
22 Correct 44 ms 6624 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 47 ms 7440 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 23 ms 3784 KB Output is correct
28 Correct 5 ms 4440 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 2 ms 2136 KB Output is correct