| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 442815 | sstefanovic | Trobojnica (COCI19_trobojnica) | C++14 | 381 ms | 8316 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; 
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)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
