# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335310 | 2020-12-11T22:49:22 Z | CaroLinda | Trobojnica (COCI19_trobojnica) | C++14 | 76 ms | 8408 KB |
#include <bits/stdc++.h> using namespace std ; int N ; int freq[3] ; int main() { scanf("%d", &N) ; vector<int> color(N) , nxt(N) , prev(N) ; for(int i = 0 ; i < N ; i++ ) { char c ; scanf(" %c", &c ) ; color[i] = c-'1' ; freq[ color[i] ]++ ; nxt[i] = (i == N-1) ? 0 : (i+1) ; prev[ nxt[i] ] = i ; } for(int i = 0 ; i < 3 ; i++ ) if(freq[i] > N-2 || (N-2-freq[i])&1 ) { printf("NE\n") ; return 0 ; } printf("DA\n") ; vector< tuple<int,int,int> > ans ; int cur = 1 ; while(N > 3 ) { int mostFrequent = (freq[0] > freq[1] ) ? 0 : 1 ; mostFrequent = (freq[mostFrequent] > freq[2] ) ? mostFrequent : 2 ; if( color[cur] != color[ nxt[cur] ] && (color[cur] == mostFrequent || color[nxt[cur] ] == mostFrequent) ) { // printf("%d %d %d %d %d\n", cur, nxt[cur], nxt[nxt[cur] ] , color[cur] , color[nxt[cur] ] ) ; freq[ color[cur] ]-- ; freq[ color[nxt[cur] ] ]-- ; color[cur] = 3 - color[cur] - color[ nxt[cur] ] ; nxt[cur] = nxt[ nxt[cur] ] ; prev[ nxt[cur] ] = cur ; ans.push_back( make_tuple(cur, nxt[cur] , color[cur] ) ) ; freq[color[cur] ]++ ; cur = prev[cur] ; N-- ; } else cur = nxt[cur] ; } for(auto e : ans ) printf("%d %d %d\n", get<0>(e)+1 , get<1>(e)+1, get<2>(e)+1 ) ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 0 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 0 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 0 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 0 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 75 ms | 8152 KB | Output is correct |
22 | Correct | 73 ms | 7512 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 76 ms | 8408 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 38 ms | 4316 KB | Output is correct |
28 | Correct | 15 ms | 2796 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 15 ms | 2924 KB | Output is correct |