답안 #433074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433074 2021-06-18T20:09:38 Z rainboy Archery (IOI09_archery) C
39 / 100
1482 ms 432 KB
#include <stdio.h>
#include <string.h>

#define N	200000

char used[N];

int solve_losers(int *kk, int n) {
	int i, k, sum;

	memset(used, 0, n * sizeof *used);
	k = 0, sum = 0;
	for (i = n - 1; i >= 0; i--) {
		k += kk[i];
		if (!used[i] && k > 0)
			used[i] = 1, k--, sum ^= i;
	}
	for (i = n - 1; i >= 0; i--)
		if (!used[i] && k > 0)
			used[i] = 1, k--, sum ^= i;
	return sum;
}

int solve_winners(int *kk, int n) {
	int i, j, k, sum;

	k = 0, sum = 0;
	for (i = 0; i < n; i++)
		if (kk[i] > 0) {
			k = kk[i] - 1;
			if (i == 0 && k > 0)
				used[i] = 1, k--, sum ^= i;
			break;
		}
	for (j = i + 1; j <= i + n; j++) {
		if (j != i + n)
			k += kk[j % n];
		if (!used[j % n] && k > 0)
			used[j % n] = 1, k--, sum ^= j % n;
	}
	for (j = i + 1; j <= i + n; j++)
		if (!used[j % n] && k > 0)
			used[j % n] = 1, k--, sum ^= j % n;
	return sum;
}

int main() {
	static int aa[N * 2], bb[N * 2], pp[N * 2], kk[N];
	int n, r, p, p_, i, i_, a;

	scanf("%d%d", &n, &r);
	if (n > 5000) {
		printf(":(\n");
		return 0;
	}
	for (i = 0; i < n * 2; i++)
		scanf("%d", &aa[i]), aa[i]--;
	i_ = -1, p_ = n * 2;
	for (i = 0; i < n * 2; i++) {
		int tmp;

		if (i > 0)
			tmp = aa[i], aa[i] = aa[i - 1], aa[i - 1] = tmp;
		memcpy(bb, aa, n * 2 * sizeof *aa);
		for (p = 0; p < n * 2; p++)
			pp[aa[p]] = p / 2;
		if (aa[i] == 0)
			p = 0;
		else if (aa[i] >= n + 1) {
			memset(kk, 0, n * sizeof *kk), kk[0]++;
			for (a = n * 2 - 1; a > aa[i]; a--)
				kk[pp[a]]++;
			p = solve_losers(kk, n), kk[pp[aa[i]]]++, p ^= solve_losers(kk, n);
		} else {
			memset(kk, 0, n * sizeof *kk);
			for (a = 0; a < aa[i]; a++)
				kk[pp[a]]++;
			p = solve_winners(kk, n), kk[pp[aa[i]]]++, p ^= solve_winners(kk, n);
			p = (p - r % n + n) % n;
		}
		if (p_ >= p)
			p_ = p, i_ = i / 2;
	}
	printf("%d\n", i_ + 1);
	return 0;
}

Compilation message

archery.c: In function 'main':
archery.c:51:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d", &n, &r);
      |  ^~~~~~~~~~~~~~~~~~~~~
archery.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d", &aa[i]), aa[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 29 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 345 ms 364 KB Output isn't correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 3 ms 204 KB Output isn't correct
3 Incorrect 122 ms 332 KB Output isn't correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Correct 3 ms 204 KB Output is correct
7 Incorrect 51 ms 204 KB Output isn't correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Incorrect 0 ms 204 KB Output isn't correct
10 Incorrect 71 ms 332 KB Output isn't correct
11 Incorrect 0 ms 204 KB Output isn't correct
12 Incorrect 468 ms 332 KB Output isn't correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Incorrect 1482 ms 432 KB Output isn't correct
15 Incorrect 1 ms 204 KB Output isn't correct
16 Incorrect 3 ms 204 KB Output isn't correct
17 Incorrect 104 ms 332 KB Output isn't correct
18 Incorrect 243 ms 336 KB Output isn't correct
19 Correct 764 ms 392 KB Output is correct
20 Correct 1466 ms 428 KB Output is correct
21 Incorrect 1 ms 204 KB Output isn't correct
22 Incorrect 0 ms 204 KB Output isn't correct
23 Incorrect 0 ms 204 KB Output isn't correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 32 ms 204 KB Output is correct
26 Correct 766 ms 432 KB Output is correct
27 Incorrect 0 ms 204 KB Output isn't correct
28 Incorrect 1 ms 204 KB Output isn't correct
29 Correct 59 ms 332 KB Output is correct
30 Correct 604 ms 428 KB Output is correct
31 Incorrect 1 ms 204 KB Output isn't correct
32 Incorrect 1 ms 204 KB Output isn't correct
33 Correct 2 ms 204 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 113 ms 340 KB Output is correct
36 Correct 167 ms 332 KB Output is correct
37 Incorrect 1 ms 204 KB Output isn't correct
38 Incorrect 0 ms 204 KB Output isn't correct
39 Correct 2 ms 204 KB Output is correct
40 Correct 34 ms 332 KB Output is correct
41 Correct 113 ms 344 KB Output is correct
42 Correct 149 ms 348 KB Output is correct
43 Correct 703 ms 432 KB Output is correct
44 Incorrect 0 ms 204 KB Output isn't correct
45 Incorrect 0 ms 204 KB Output isn't correct
46 Incorrect 1 ms 204 KB Output isn't correct
47 Incorrect 0 ms 204 KB Output isn't correct