답안 #198066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198066 2020-01-24T15:12:26 Z model_code Trobojnica (COCI19_trobojnica) C++17
110 / 110
89 ms 7708 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 412 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 412 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 456 KB Output is correct
21 Correct 89 ms 7708 KB Output is correct
22 Correct 81 ms 6672 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 85 ms 7580 KB Output is correct
26 Correct 2 ms 424 KB Output is correct
27 Correct 43 ms 3936 KB Output is correct
28 Correct 21 ms 4528 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 12 ms 2156 KB Output is correct