Submission #442811

# Submission time Handle Problem Language Result Execution time Memory
442811 2021-07-09T07:40:45 Z sstefanovic Trobojnica (COCI19_trobojnica) C++14
60 / 110
2000 ms 3952 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]; 

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; 
	}
	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]; 
	}
	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:22:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |   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 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 ms 304 KB Output is correct
13 Correct 3 ms 304 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 300 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 ms 304 KB Output is correct
13 Correct 3 ms 304 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 300 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
21 Execution timed out 2071 ms 3952 KB Time limit exceeded
22 Halted 0 ms 0 KB -