結果

問題 No.2282 Boxed Nim
ユーザー FromBooskaFromBooska
提出日時 2023-04-29 13:10:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 83,328 KB
最終ジャッジ日時 2024-04-29 08:25:17
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,456 KB
testcase_01 AC 40 ms
51,328 KB
testcase_02 AC 41 ms
51,584 KB
testcase_03 AC 41 ms
51,712 KB
testcase_04 AC 40 ms
51,840 KB
testcase_05 AC 41 ms
51,712 KB
testcase_06 AC 42 ms
51,712 KB
testcase_07 AC 41 ms
51,840 KB
testcase_08 AC 40 ms
51,840 KB
testcase_09 AC 72 ms
82,688 KB
testcase_10 AC 72 ms
82,432 KB
testcase_11 AC 72 ms
82,816 KB
testcase_12 AC 73 ms
82,688 KB
testcase_13 AC 72 ms
82,816 KB
testcase_14 AC 66 ms
77,952 KB
testcase_15 AC 67 ms
78,208 KB
testcase_16 AC 67 ms
78,464 KB
testcase_17 AC 68 ms
77,952 KB
testcase_18 AC 68 ms
78,208 KB
testcase_19 AC 73 ms
83,328 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数を求める
# 0ならその山は先手勝ち、それ以外は先手負け
# 全山のGrundy数のxor sumが0であれば手番の人は負ける

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

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

if xor_sum == 0:
    print('Second')
else:
    print('First')
0