Submission #442909

# Submission time Handle Problem Language Result Execution time Memory
442909 2021-07-09T10:45:03 Z Markomafko972 Trobojnica (COCI19_trobojnica) C++14
0 / 110
1 ms 204 KB
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

int n, da;
char c;
set< pair< pair<int, int>, int > > s;
set< pair< pair<int, int>, int > > :: iterator it;
set< pair< pair<int, int>, int > > :: iterator it2;
vector< pair< pair<int, int>, int > > sol; 

int main () {
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		s.insert({{i, (i+1)%n}, c-'1'});
	}
	
	while (s.size() > 2) {
		da = 0;
		for (it = s.begin(); it != s.end(); it=it) {
			//cout << (*it).X.X << " " << (*it).X.Y << " " << (*it).Y << endl;
			it2 = it;
			it2++;
			
			if (it2 != s.end()) {
				if ((*it).Y != (*it2).Y) {
					da = 1;
					int poc = (*it).X.X;
					int kr = (*it2).X.Y;
					int br = 3-(*it).Y-(*it2).Y;
					
					s.erase(it2);
					it2 = it;
					it++;
					s.erase(it2);
					s.insert({{poc, kr}, br});
					sol.push_back({{poc+1, kr+1}, br+1});
				}
				else {
					it++;
				}
			}
			else {
				it++;
			}
		}
		
		it = s.begin();
		it2 = s.end();
		it2--;
		if ((*it).Y != (*it2).Y) {
			da = 1;
			int poc = (*it2).X.X;
			int kr = (*it).X.Y;
			int br = 3-(*it).Y-(*it2).Y;
			
			s.erase(it);
			s.erase(it2);
			s.insert({{poc, kr}, br});
			sol.push_back({{poc+1, kr+1}, br+1});
		}
		
		if (da == 0) break;
	}
	
	if (!da) {
		cout << "NE";
		return 0;
	}
	
	it = s.begin();
	it2 = s.begin();
	it2++;
	
	if ((*it).Y != (*it2).Y) {
		cout << "NE";
		return 0;
	}
	
	cout << "DA\n";
	for (int i = 0; i < (int)sol.size()-1; i++) cout << sol[i].X.X << " " << sol[i].X.Y << " " << sol[i].Y << "\n";
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -