답안 #480132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480132 2021-10-14T19:16:12 Z rainboy Checker (COCI19_checker) C
23 / 110
118 ms 2860 KB
#include <stdio.h>

#define N	200000

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int ii[N], jj[N];

void sort(int *hh, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = ii[hh[j]] != ii[h] ? ii[hh[j]] - ii[h] : jj[h] - jj[hh[j]];

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		}
		sort(hh, l, i);
		l = k;
	}
}

int main() {
	static char cc[N + 1];
	static int hh[N];
	int n, h, i, cnt;

	scanf("%*d%d%s", &n, cc);
	for (i = 0; i < n; i++)
		cc[i] -= '0';
	for (i = 1; i < n; i++)
		cc[i] ^= cc[i - 1];
	if (cc[n - 1] != 0) {
		printf("neispravno bojenje\n");
		return 0;
	}
	for (h = 0; h < n - 3; h++) {
		int c, tmp;

		scanf("%d%d%d", &ii[h], &jj[h], &c), ii[h]--, jj[h]--;
		if (ii[h] > jj[h])
			tmp = ii[h], ii[h] = jj[h], jj[h] = tmp;
		if ((cc[jj[h] - 1] ^ (ii[h] == 0 ? 0 : cc[ii[h] - 1])) != c) {
			printf("neispravno bojenje\n");
			return 0;
		}
		hh[h] = h;
	}
	sort(hh, 0, n - 3);
	if (n <= 2000) {
		int h_;

		for (h = 0; h < n - 3; h++)
			for (h_ = h + 1; h_ < n - 3; h_++)
				if (!(ii[hh[h]] <= ii[hh[h_]] && jj[hh[h_]] <= jj[hh[h]] || ii[hh[h_]] <= ii[hh[h]] && jj[hh[h]] <= jj[hh[h_]]) && !(jj[hh[h]] <= ii[hh[h_]] || jj[hh[h_]] <= ii[hh[h]]) || ii[hh[h]] == ii[hh[h_]] && jj[hh[h]] == jj[hh[h_]]) {
					printf("neispravna triangulacija\n");
					return 0;
				}
	} else {
		cnt = 0;
		for (h = 0; h < n - 3; h++) {
			int h_ = hh[h];

			while (cnt && jj[hh[cnt - 1]] <= ii[h_])
				cnt--;
			if (cnt && (jj[h_] > jj[hh[cnt - 1]] || ii[h_] == ii[hh[cnt - 1]] && jj[h_] == jj[hh[cnt - 1]])) {
				printf("neispravna triangulacija\n");
				return 0;
			}
			hh[cnt++] = h_;
		}
	}
	printf("tocno\n");
	return 0;
}

Compilation message

checker.c: In function 'main':
checker.c:67:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |     if (!(ii[hh[h]] <= ii[hh[h_]] && jj[hh[h_]] <= jj[hh[h]] || ii[hh[h_]] <= ii[hh[h]] && jj[hh[h]] <= jj[hh[h_]]) && !(jj[hh[h]] <= ii[hh[h_]] || jj[hh[h_]] <= ii[hh[h]]) || ii[hh[h]] == ii[hh[h_]] && jj[hh[h]] == jj[hh[h_]]) {
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
checker.c:67:117: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |     if (!(ii[hh[h]] <= ii[hh[h_]] && jj[hh[h_]] <= jj[hh[h]] || ii[hh[h_]] <= ii[hh[h]] && jj[hh[h]] <= jj[hh[h_]]) && !(jj[hh[h]] <= ii[hh[h_]] || jj[hh[h_]] <= ii[hh[h]]) || ii[hh[h]] == ii[hh[h_]] && jj[hh[h]] == jj[hh[h_]]) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
checker.c:78:70: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   78 |    if (cnt && (jj[h_] > jj[hh[cnt - 1]] || ii[h_] == ii[hh[cnt - 1]] && jj[h_] == jj[hh[cnt - 1]])) {
      |                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
checker.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%*d%d%s", &n, cc);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
checker.c:52:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d%d%d", &ii[h], &jj[h], &c), ii[h]--, jj[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 2792 KB Output is correct
2 Correct 118 ms 2696 KB Output is correct
3 Correct 108 ms 2860 KB Output is correct
4 Incorrect 5 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 2784 KB Output is correct
2 Correct 104 ms 2784 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 8 ms 696 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 99 ms 2764 KB Output is correct
7 Correct 108 ms 2700 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 11 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -