답안 #482420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482420 2021-10-24T13:36:31 Z rainboy Tenis (COCI20_tenis) C
80 / 110
51 ms 4292 KB
#include <stdio.h>

#define N	200000
#define T	3
#define S	6

int min(int a, int b) { return a < b ? a : b; }

int pref[S][T] = {
	{ 0, 1, 2 },
	{ 0, 2, 1 },
	{ 1, 0, 2 },
	{ 1, 2, 0 },
	{ 2, 0, 1 },
	{ 2, 1, 0 }
};

int main() {
	static int ii[N][T], ii_[N], ep[N][T], eo[N], kk[N], ll[N], mm[S];
	int n, g, h, i, j, j_, p, q, s, t, t_;

	scanf("%d", &n);
	for (t = 0; t < T; t++)
		for (i = 0; i < n; i++) {
			scanf("%d", &p), p--;
			ii[p][t] = i;
		}
	for (p = 0; p < n; p++) {
		ii_[p] = n;
		for (t = 0; t < T; t++)
			ii_[p] = min(ii_[p], ii[p][t]);
	}
	for (p = 0; p < n; p++) {
		i = ii_[p];
		ep[i][eo[i]++] = p;
	}
	for (i = 0; i < n; i++)
		for (g = 0; g < eo[i]; g++)
			for (h = g + 1; h < eo[i]; h++) {
				p = ep[i][g], q = ep[i][h], j_ = n, t_ = -1;
				for (t = 0; t < T; t++)
					if (ii[p][t] == i || ii[q][t] == i) {
						j = i ^ ii[p][t] ^ ii[q][t];
						if (j_ > j)
							j_ = j, t_ = t;
					}
				kk[t_]++;
				if (ii[p][t_] < ii[q][t_])
					ll[p]++;
				else
					ll[q]++;
			}
	for (i = n - 1; i >= 0; i--) {
		for (g = 0; g < eo[i]; g++) {
			p = ep[i][g];
			for (s = 0; s < S; s++) {
				for (t = 0; t < T; t++)
					if (ii[p][pref[s][t]] == i)
						break;
				kk[pref[s][t]] += mm[s], ll[p] += mm[s];
			}
		}
		for (g = 0; g < eo[i]; g++) {
			p = ep[i][g];
			for (s = 0; s < S; s++) {
				int congruent = 1;

				for (t = 1; t < T; t++)
					if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
						congruent = 0;
						break;
					}
				if (congruent)
					mm[s]++;
			}
		}
	}
	for (t = 0; t < T; t++)
		printf("%d ", kk[t]);
	printf("\n");
	for (p = 0; p < n; p++)
		printf("%d ", ll[p]);
	printf("\n");
	return 0;
}

Compilation message

tenis.c: In function 'main':
tenis.c:69:98: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   69 |      if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
      |                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.c:22:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
tenis.c:25:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |    scanf("%d", &p), p--;
      |    ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 20 ms 1812 KB Output is correct
6 Correct 30 ms 2656 KB Output is correct
7 Correct 51 ms 3472 KB Output is correct
8 Correct 50 ms 4292 KB Output is correct
9 Partially correct 49 ms 3560 KB Partially correct
10 Partially correct 50 ms 4292 KB Partially correct