結果

問題 No.2165 Let's Play Nim!
コンテスト
ユーザー 👑 Kazun
提出日時 2022-12-16 00:51:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,117 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 163 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 101,792 KB
平均クエリ数 884.90
最終ジャッジ日時 2026-05-10 02:49:56
合計ジャッジ時間 9,113 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#==================================================
def send(i,k):
    print(i,k, flush=True)

def recieve():
    i,k=map(int,input().split())
    return i,k

def phase():
    return int(input())

def choice(turn):
    print(turn, flush=True)

def bit(x,k):
    return (x>>k)&1

#==================================================
def solve():
    N=int(input())
    A=[0]+list(map(int,input().split()))

    grundy=0; B=17
    S=[set([i for i in range(1,N+1) if bit(A[i],t)]) for t in range(B)]

    for a in A[1:]:
        grundy^=a

    turn=1 if grundy else 0
    choice(turn)

    while True:
        if turn:
            msb=grundy.bit_length()-1
            i=S[msb].pop()
            a=A[i]
            b=grundy^A[i]
            k=A[i]-b

            send(i,k)
        else:
            i,k=recieve()

        for t in range(B):
            S[t].discard(i)

        grundy^=A[i]^(A[i]-k)
        A[i]-=k

        for t in range(B):
            if bit(A[i],t):
                S[t].add(i)

        if phase()==-1:
            return
        turn^=1

#==================================================
solve()
0