Submission #433078

# Submission time Handle Problem Language Result Execution time Memory
433078 2021-06-18T20:17:03 Z rainboy Archery (IOI09_archery) C
60 / 100
2000 ms 8388 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);
	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:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d", &aa[i]), aa[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 30 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 400 ms 356 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 138 ms 332 KB Output is correct
4 Execution timed out 2092 ms 764 KB Time limit exceeded
5 Execution timed out 2084 ms 7216 KB Time limit exceeded
6 Correct 3 ms 204 KB Output is correct
7 Correct 55 ms 204 KB Output is correct
8 Execution timed out 2096 ms 732 KB Time limit exceeded
9 Execution timed out 2096 ms 972 KB Time limit exceeded
10 Correct 77 ms 332 KB Output is correct
11 Execution timed out 2074 ms 1024 KB Time limit exceeded
12 Correct 448 ms 332 KB Output is correct
13 Execution timed out 2063 ms 5188 KB Time limit exceeded
14 Correct 1571 ms 424 KB Output is correct
15 Execution timed out 2079 ms 1484 KB Time limit exceeded
16 Correct 3 ms 204 KB Output is correct
17 Correct 100 ms 332 KB Output is correct
18 Correct 249 ms 332 KB Output is correct
19 Correct 768 ms 332 KB Output is correct
20 Correct 1493 ms 424 KB Output is correct
21 Execution timed out 2075 ms 972 KB Time limit exceeded
22 Execution timed out 2086 ms 1356 KB Time limit exceeded
23 Execution timed out 2081 ms 7620 KB Time limit exceeded
24 Correct 2 ms 204 KB Output is correct
25 Correct 31 ms 332 KB Output is correct
26 Correct 788 ms 428 KB Output is correct
27 Execution timed out 2097 ms 972 KB Time limit exceeded
28 Execution timed out 2040 ms 5468 KB Time limit exceeded
29 Correct 59 ms 452 KB Output is correct
30 Correct 590 ms 424 KB Output is correct
31 Execution timed out 2071 ms 972 KB Time limit exceeded
32 Execution timed out 2075 ms 7492 KB Time limit exceeded
33 Correct 2 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 111 ms 332 KB Output is correct
36 Correct 163 ms 352 KB Output is correct
37 Execution timed out 2089 ms 844 KB Time limit exceeded
38 Execution timed out 2098 ms 1228 KB Time limit exceeded
39 Correct 2 ms 204 KB Output is correct
40 Correct 24 ms 332 KB Output is correct
41 Correct 115 ms 344 KB Output is correct
42 Correct 146 ms 332 KB Output is correct
43 Correct 705 ms 428 KB Output is correct
44 Execution timed out 2076 ms 588 KB Time limit exceeded
45 Execution timed out 2067 ms 972 KB Time limit exceeded
46 Execution timed out 2072 ms 1100 KB Time limit exceeded
47 Execution timed out 2069 ms 8388 KB Time limit exceeded