Submission #251634

#TimeUsernameProblemLanguageResultExecution timeMemory
251634MrRobot_28Trobojnica (COCI19_trobojnica)C++17
110 / 110
59 ms7936 KiB
#include<bits/stdc++.h>
using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	string s;
	cin >> n >> s;
	vector <int> nxt(n), color(n);
	vector <int> cnt(3);
	for(int i = 0; i < n; i++)
	{
		nxt[i] = (i + 1) % n;
		color[i] = s[i] - '1';
		cnt[s[i] - '1']++;
	}
	vector <int> ans1(n), ans2(n), ans3(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";
			return 0;
		}
		while(color[x] == color[nxt[x]] || cnt[color[x]] == 1 && cnt[color[nxt[x]]] == 1)
		{
			x = nxt[x];
		}
		int y = nxt[x];
		cnt[color[x]]--;
		cnt[color[y]]--;
		ans1[i] = x;
		ans2[i] = nxt[y];
		color[x] = 3 - color[x] - color[y];
		nxt[x] = nxt[y];
		ans3[i] = color[x];
		cnt[color[x]]++;
	}
	if(cnt[0] == 1 && cnt[1] == 1)
	{
		cout << "DA\n";
		for(int i = 0; i < n - 3; i++)
		{
			cout << ans1[i] + 1 << " " << ans2[i] + 1 << " " << ans3[i] + 1 << "\n";
		}
	}
	else
	{
		cout << "NE";
	}
  	return 0;
}

Compilation message (stderr)

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:28:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   while(color[x] == color[nxt[x]] || cnt[color[x]] == 1 && cnt[color[nxt[x]]] == 1)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...