結果

問題 No.946 箱箱箱
ユーザー lam6er
提出日時 2025-03-20 20:57:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 77,588 KB
最終ジャッジ日時 2025-03-20 20:58:02
合計ジャッジ時間 9,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [int(input()) for _ in range(n)]

pre_xor = [0] * (n + 1)
for i in range(n):
    pre_xor[i + 1] = pre_xor[i] ^ A[i]

g = [0] * (n + 2)
g[n + 1] = 0  # Base case: no unopened boxes left

for i in range(n, 0, -1):
    s = set()
    max_k = n - i + 1
    for k in range(1, max_k + 1):
        next_i = i + k
        current_xor = pre_xor[i - 1 + k] ^ pre_xor[i - 1]
        total = current_xor ^ g[next_i]
        s.add(total)
    mex = 0
    while mex in s:
        mex += 1
    g[i] = mex

print("Takahashi" if g[1] != 0 else "Takanashi")
0