답안 #291566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291566 2020-09-05T13:34:47 Z kingfran1907 Trobojnica (COCI19_trobojnica) C++14
110 / 110
61 ms 7900 KB
#include <bits/stdc++.h>
#define X first
#define Y second
 
using namespace std;
typedef long long llint;
 
const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
char niz[maxn];
int cl[maxn], cnt[10];
int nx[maxn];
vector< int > x, y, s;

int main() {
	scanf("%d%s", &n, niz);
	for (int i = 0; i < n; i++) {
		cl[i] = niz[i] - '1';
		cnt[cl[i]]++, nx[i] = (i + 1) % n; 
	}

	int tren = 0;
	for (int i = 0; i < n - 3; i++) {
		if (max({cnt[0], cnt[1], cnt[2]}) == n - i) {
			printf("NE\n");
			return 0;
		}

		while (cl[tren] == cl[nx[tren]] || (cnt[cl[tren]] == 1 && cnt[cl[nx[tren]]] == 1)) {
			tren = nx[tren];
		}

		int ac = nx[tren];
		int ms = 1 + 2 - cl[tren] - cl[ac];
		//printf("debug: %d %d\n", ac, ms);
		cnt[cl[tren]]--, cnt[cl[ac]]--;
		cnt[ms]++;

		cl[tren] = ms, nx[tren] = nx[ac];
		x.push_back(tren);
		y.push_back(nx[tren]);
		s.push_back(ms);
	}

	if (cnt[0] != 1 || cnt[1] != 1 || cnt[2] != 1) {
		printf("NE\n");
		return 0;
	} else {
		printf("DA\n");
		for (int i = 0; i < x.size(); i++) {
			printf("%d %d %d\n", x[i] + 1, y[i] + 1, s[i] + 1);
		}
	}
	return 0;
}

Compilation message

trobojnica.cpp: In function 'int main()':
trobojnica.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (int i = 0; i < x.size(); i++) {
      |                   ~~^~~~~~~~~~
trobojnica.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d%s", &n, niz);
      |  ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 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 0 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 7900 KB Output is correct
22 Correct 57 ms 6876 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 61 ms 7764 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 31 ms 3952 KB Output is correct
28 Correct 11 ms 4708 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 3 ms 2304 KB Output is correct