結果

問題 No.1716 Bonus Nim
ユーザー 👑 ygussanyygussany
提出日時 2021-10-10 13:34:21
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 30,952 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 11:33:11
合計ジャッジ時間 3,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 54 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 119 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void merge_sort(int n, int x[])
{
	static int y[200001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}


int solve(int N, int A[])
{
	if (N % 2 != 0) return 0;

	int i, max = 0, tmp, X;
	merge_sort(N, &(A[1]));
	for (i = 2, tmp = 1, X = A[1]; i <= N; i++) {
		if (A[i] == A[i-1]) tmp++;
		else {
			if (max < tmp) max = tmp;
			tmp = 1;
		}
		X ^= A[i];
	}
	if (max < tmp) max = tmp;
	if (max <= N / 2 || X != 0) return 0;
	else return 1;
}

int main()
{
	int i, t, T, N, A[200001];
	scanf("%d", &T);
	for (t = 1; t <= T; t++) {
		scanf("%d", &N);
		for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
		if (solve(N, A) == 0) printf("Alice\n");
		else printf("Bob\n");
	}
	fflush(stdout);
	return 0;
}
0