답안 #433076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433076 2021-06-18T20:10:42 Z rainboy Archery (IOI09_archery) C
60 / 100
1578 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;

	memset(used, 0, n * sizeof *used);
	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:52:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d%d", &n, &r);
      |  ^~~~~~~~~~~~~~~~~~~~~
archery.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d", &aa[i]), aa[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 29 ms 336 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 406 ms 352 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 139 ms 332 KB Output is 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 Correct 55 ms 320 KB Output is correct
8 Incorrect 0 ms 204 KB Output isn't correct
9 Incorrect 0 ms 204 KB Output isn't correct
10 Correct 75 ms 332 KB Output is correct
11 Incorrect 0 ms 204 KB Output isn't correct
12 Correct 451 ms 360 KB Output is correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Correct 1578 ms 428 KB Output is correct
15 Incorrect 0 ms 204 KB Output isn't correct
16 Correct 3 ms 204 KB Output is correct
17 Correct 100 ms 332 KB Output is correct
18 Correct 252 ms 340 KB Output is correct
19 Correct 757 ms 400 KB Output is correct
20 Correct 1500 ms 428 KB Output is correct
21 Incorrect 0 ms 204 KB Output isn't correct
22 Incorrect 1 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 828 ms 432 KB Output is correct
27 Incorrect 0 ms 204 KB Output isn't correct
28 Incorrect 0 ms 204 KB Output isn't correct
29 Correct 63 ms 340 KB Output is correct
30 Correct 589 ms 432 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 1 ms 204 KB Output is correct
35 Correct 110 ms 348 KB Output is correct
36 Correct 163 ms 352 KB Output is correct
37 Incorrect 0 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 28 ms 332 KB Output is correct
41 Correct 116 ms 340 KB Output is correct
42 Correct 152 ms 352 KB Output is correct
43 Correct 669 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 0 ms 204 KB Output isn't correct
47 Incorrect 0 ms 204 KB Output isn't correct