Submission #442815

# Submission time Handle Problem Language Result Execution time Memory
442815 2021-07-09T07:50:11 Z sstefanovic Trobojnica (COCI19_trobojnica) C++14
110 / 110
381 ms 8316 KB
#include<bits/stdc++.h>
using namespace std; 

const int MAXN = 2e5+10; 
int n; 
string s;
int slj[MAXN], boje[MAXN], cnt[3], solx[MAXN], soly[MAXN], solb[MAXN], pret[MAXN]; 

int main( ){
	cin >> n >> s; 
	for (int i=0; i<n; i++){
		boje[i]=s[i]-'1'; 
		cnt[boje[i]]++;
		slj[i] = (i+1)%n; 
		pret[i] = (i+n-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 (boje[x] == boje [slj[x]] or cnt[boje[x]] == 1 && cnt[boje[slj[x]]]){
			x = slj[x]; 
		}
		int y = slj [x]; 
		int nX = 3-boje[x]-boje[y]; 
		cnt[boje[x]]--; 
		cnt[boje[y]]--; 
		cnt[nX]++; 
		solx[i]=x; 
		soly[i]=slj[y]; 
		solb[i]=nX; 
		boje[x] = nX; 
		slj[x]=slj[y]; 
		pret[slj[x]]=x; 
		x=pret[x]; 
	}
	if (cnt[0] == 1 && cnt[1]==1 && cnt[2] == 1){
		cout << "DA\n"; 
		for (int i=0; i<n-3; i++){
			cout << solx[i]+1 << " " << soly[i]+1 <<" " << solb[i]+1 << endl; 
		}
	}else{
		cout << "NE\n";
		return 0; 
	}
	return 0;
}

Compilation message

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:23:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   23 |   while (boje[x] == boje [slj[x]] or cnt[boje[x]] == 1 && cnt[boje[slj[x]]]){
      |                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 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 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 378 ms 7860 KB Output is correct
22 Correct 377 ms 7508 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 381 ms 8316 KB Output is correct
26 Correct 1 ms 280 KB Output is correct
27 Correct 187 ms 4300 KB Output is correct
28 Correct 13 ms 5468 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 8 ms 3164 KB Output is correct