# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335308 | CaroLinda | Trobojnica (COCI19_trobojnica) | C++14 | 2084 ms | 2412 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
int N ;
int freq[3] ;
int main()
{
scanf("%d", &N) ;
vector<int> color(N) , nxt(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) ;
}
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] ] ;
ans.push_back( make_tuple(cur, nxt[cur] , color[cur] ) ) ;
freq[color[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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |