Submission #251634

# Submission time Handle Problem Language Result Execution time Memory
251634 2020-07-22T05:42:25 Z MrRobot_28 Trobojnica (COCI19_trobojnica) C++17
110 / 110
59 ms 7936 KB
#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

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 time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 59 ms 7936 KB Output is correct
22 Correct 57 ms 6916 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 59 ms 7812 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 30 ms 3960 KB Output is correct
28 Correct 9 ms 4748 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 4 ms 4876 KB Output is correct