Submission #442815

#TimeUsernameProblemLanguageResultExecution timeMemory
442815sstefanovicTrobojnica (COCI19_trobojnica)C++14
110 / 110
381 ms8316 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...