結果

問題 No.582 キャンディー・ボックス3
ユーザー FromBooskaFromBooska
提出日時 2024-03-18 13:21:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,082 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2024-03-18 13:21:56
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 WA -
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 49 ms
53,460 KB
testcase_10 AC 35 ms
53,460 KB
testcase_11 AC 35 ms
53,460 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 36 ms
53,460 KB
testcase_17 WA -
testcase_18 AC 36 ms
53,460 KB
testcase_19 AC 35 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# これはニム、典型的ゲーム
# 山のコインの数要素すべてのxor sumを計算し、それが0なら手番の人は負ける
# 自分の手番で全要素のxor sumが0でなければ、ある行動で0にして相手を負けさせることができるので勝つ
# すべて0のとき、xor sumは0となるので負けている
# つまり一度xor sumが0となってしまえば、何をやっても相手にまたxor sum 0にされて手番が回ってくる
# するといずれは最後の全部0の状態=負け確定、まで持っていかれる
# https://algo-logic.info/combinatorial-games/
# https://www.mojirca.com/2019/09/why-nim-xor-eq-zero.html

# Grundy数
# 各山のGrundy数を求める
# 1ならその山は先手勝ち、それ以外は先手負け
# 全山のGrundy数のxor sumが0であれば手番の人は負ける

N = int(input())
A = list(map(int, input().split()))

xor_sum = 0
for a in A:
    if a == 1:
        grundy = 1
    else:
        grundy = 0
    xor_sum ^= grundy

if xor_sum == 0:
    print('B')
else:
    print('A')
0