답안 #291561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291561 2020-09-05T13:32:02 Z kingfran1907 Trobojnica (COCI19_trobojnica) C++14
0 / 110
1 ms 384 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(ac);
		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 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -