답안 #442631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442631 2021-07-08T11:28:31 Z jesus_coconut Sob (COCI19_sob) C++17
0 / 110
1 ms 460 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;



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

	int n;
	cin >> n;
	vector<pair<int, int>> v(n);
	array<int, 4> cnt{};
	for (int i = 0; i < n; ++i) {
		char c;
		cin >> c;
		v[i] = {(i + 1) % n, c - '0'};
		cnt[c - '0']++;
	}
	if (cnt[1] % 2 != cnt[2] % 2 || cnt[1] % 2 != cnt[2] % 2) {
		cout << "NE\n";
		return 0;
	}
	int prv = n - 1;
	int cur = 0;
	vector<array<int, 3>> ans;
	for (int q = 0; q < n - 3; ++q) {
		set<int> mx;
		int cmx = 0;
		for (int i = 1; i < 4; ++i) {
			if (cnt[i] > cmx) {
				mx.clear();
				cmx = cnt[i];
				mx.insert(i);
			} else if (cnt[i] == cmx) {
				mx.insert(i);
			}
		}
		for (int i = 0; i < n - ans.size() + 5; ++i) {
			int nxt = v[cur].F;
			if (v[cur].S != v[nxt].S) {
				if (mx.count(v[cur].S) || mx.count(v[nxt].S)) {
					ans.push_back({cur + 1, v[nxt].F + 1, 6 - v[cur].S - v[nxt].S});
					cnt[v[cur].S]--;
					cnt[v[nxt].S]--;
					v[cur].F = v[nxt].F;
					v[cur].S = 6 - v[cur].S - v[nxt].S;
					cnt[v[cur].S]++;
					break;
				}
			}
			prv = cur;
			cur = v[cur].F;
		}
		cur = prv;
		if (q + 1 != ans.size()) {
			cout << "NE\n";
			return 0;
		}
	}
	int nxt = v[cur].F;
	if (v[cur].S + v[nxt].S + v[v[nxt].F].S != 6) {
		cout << "NE\n";
		return 0;
	}
	cout << "DA\n";
	for (auto &arr : ans) {
		for (auto &a : arr) {
			cout << a << ' ';
		}
		cout << '\n';
	}


    return 0;
}

Compilation message

sob.cpp: In function 'int main()':
sob.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 0; i < n - ans.size() + 5; ++i) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~
sob.cpp:62:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   if (q + 1 != ans.size()) {
      |       ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "NE" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -