Submission #442555

# Submission time Handle Problem Language Result Execution time Memory
442555 2021-07-08T07:57:54 Z jesus_coconut Trobojnica (COCI19_trobojnica) C++17
0 / 110
2 ms 204 KB
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define dbg(x) cerr << #x << " = " << x << '\n';
#define F first
#define S second
using namespace std;

using ll = long long;



void solve() {
	int n;
	cin >> n;
	list<pair<int, int>> l;
	for (int i = 0; i < n; ++i) {
		char c;
		cin >> c;
		l.push_back({i + 1, c - '0'});
	}
	vector<array<int, 3>> ans;
	int cnt = 0;
	for (auto it = l.begin(); cnt < 500000; ++cnt) {
		auto sit = l.begin();
		if (next(it) != l.end()) {
			sit = next(it);
		}
		if (it->second != sit->second) {
			auto nit = next(sit);
			if (nit == l.end()) nit = l.begin();
			if (next(nit) == it || (next(nit) == l.end() && l.begin() == it)) {
				if (it->S + sit->S + nit->S != 6) {
					cout << "NE\n";
					return;
				} else {
					break;
				}
			}
			ans.push_back({it->F, nit->F, 6 - it->S - sit->S});
			it->second = 6 - it->S - sit->S;
			l.erase(sit);
			if (it != l.begin()) {
				it = prev(it);
			} else {
				it = prev(l.end());
			}
		} else {
			if (next(it) != l.end()) {
				it = next(it);
			} else it = l.begin();
		}
		if (ans.size() > n - 3) {
			cout << "NE\n";
			return;
		}
	}
	if (ans.size() != n - 3) {
		cout << "NE\n";
		return;
	}
	cout << "DA\n";
	for (auto &arr : ans) {
		for (auto a : arr) {
			cout << a << ' ';
		}
		cout << '\n';
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);


	solve();

    return 0;
}

Compilation message

trobojnica.cpp: In function 'void solve()':
trobojnica.cpp:52:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |   if (ans.size() > n - 3) {
      |       ~~~~~~~~~~~^~~~~~~
trobojnica.cpp:57:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |  if (ans.size() != n - 3) {
      |      ~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 2 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 2 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 2 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -