답안 #433072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433072 2021-06-18T20:07:42 Z rainboy Archery (IOI09_archery) C
37 / 100
1420 ms 476 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[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 1 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 328 ms 292 KB Output isn't correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 284 KB Output isn't correct
2 Incorrect 3 ms 204 KB Output isn't correct
3 Incorrect 115 ms 344 KB Output isn't correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Correct 3 ms 204 KB Output is correct
7 Incorrect 49 ms 332 KB Output isn't correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Incorrect 1 ms 352 KB Output isn't correct
10 Incorrect 70 ms 332 KB Output isn't correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Incorrect 417 ms 388 KB Output isn't correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Incorrect 1413 ms 472 KB Output isn't correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Incorrect 3 ms 204 KB Output isn't correct
17 Incorrect 98 ms 332 KB Output isn't correct
18 Incorrect 230 ms 360 KB Output isn't correct
19 Correct 717 ms 420 KB Output is correct
20 Incorrect 1420 ms 472 KB Output isn't correct
21 Incorrect 1 ms 204 KB Output isn't correct
22 Incorrect 1 ms 272 KB Output isn't correct
23 Incorrect 1 ms 288 KB Output isn't correct
24 Correct 2 ms 272 KB Output is correct
25 Correct 32 ms 324 KB Output is correct
26 Correct 797 ms 472 KB Output is correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Incorrect 0 ms 332 KB Output isn't correct
29 Correct 61 ms 356 KB Output is correct
30 Correct 589 ms 476 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Incorrect 0 ms 332 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 112 ms 404 KB Output is correct
36 Correct 163 ms 332 KB Output is correct
37 Incorrect 1 ms 204 KB Output isn't correct
38 Incorrect 0 ms 332 KB Output isn't correct
39 Correct 2 ms 204 KB Output is correct
40 Correct 29 ms 332 KB Output is correct
41 Correct 115 ms 360 KB Output is correct
42 Correct 148 ms 392 KB Output is correct
43 Correct 684 ms 468 KB Output is correct
44 Incorrect 1 ms 204 KB Output isn't correct
45 Incorrect 1 ms 204 KB Output isn't correct
46 Incorrect 0 ms 332 KB Output isn't correct
47 Incorrect 1 ms 204 KB Output isn't correct