답안 #442627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442627 2021-07-08T11:18:13 Z jesus_coconut Trobojnica (COCI19_trobojnica) C++17
60 / 110
2000 ms 2520 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']++;
	}

	int cur = 0;
	vector<array<int, 3>> ans;
	for (int q = 0; q < n - 3; ++q) {
		int mx = 0;
		for (int i = 1; i < 4; ++i) {
			if (cnt[i] > cnt[mx]) {
				mx = i;
			}
		}
		for (int i = 0; i < n - ans.size() + 5; ++i) {
			int nxt = v[cur].F;
			if (v[cur].S != v[nxt].S) {
				if (v[cur].S == mx || v[nxt].S == mx) {
					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;
				}
			}
			cur = v[cur].F;
		}
		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

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:36: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]
   36 |   for (int i = 0; i < n - ans.size() + 5; ++i) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~
trobojnica.cpp:51: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]
   51 |   if (q + 1 != ans.size()) {
      |       ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 288 KB Output is correct
21 Execution timed out 2071 ms 2520 KB Time limit exceeded
22 Halted 0 ms 0 KB -