結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 Kazun
提出日時 2022-12-16 00:51:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 94,188 KB
平均クエリ数 884.90
最終ジャッジ日時 2024-11-14 17:11:54
合計ジャッジ時間 17,765 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#==================================================
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