Submission #433078

#TimeUsernameProblemLanguageResultExecution timeMemory
433078rainboyArchery (IOI09_archery)C11
60 / 100
2098 ms8388 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...