結果

問題 No.2165 Let's Play Nim!
ユーザー ntudantuda
提出日時 2023-04-16 20:14:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 96,236 KB
平均クエリ数 697.67
最終ジャッジ日時 2024-04-20 07:32:42
合計ジャッジ時間 17,634 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
70,368 KB
testcase_01 AC 249 ms
94,664 KB
testcase_02 AC 268 ms
96,236 KB
testcase_03 AC 210 ms
94,536 KB
testcase_04 AC 62 ms
71,368 KB
testcase_05 AC 70 ms
73,544 KB
testcase_06 AC 72 ms
73,544 KB
testcase_07 AC 70 ms
72,392 KB
testcase_08 AC 218 ms
94,564 KB
testcase_09 AC 66 ms
72,208 KB
testcase_10 AC 79 ms
80,080 KB
testcase_11 AC 268 ms
94,772 KB
testcase_12 AC 240 ms
94,664 KB
testcase_13 AC 58 ms
70,984 KB
testcase_14 AC 68 ms
73,288 KB
testcase_15 AC 62 ms
71,624 KB
testcase_16 AC 221 ms
94,792 KB
testcase_17 AC 139 ms
93,128 KB
testcase_18 AC 353 ms
95,800 KB
testcase_19 AC 61 ms
71,140 KB
testcase_20 AC 67 ms
72,784 KB
testcase_21 AC 115 ms
88,536 KB
testcase_22 AC 92 ms
82,904 KB
testcase_23 AC 91 ms
81,496 KB
testcase_24 AC 83 ms
80,984 KB
testcase_25 AC 202 ms
94,808 KB
testcase_26 AC 275 ms
95,476 KB
testcase_27 AC 97 ms
84,680 KB
testcase_28 AC 153 ms
92,900 KB
testcase_29 AC 59 ms
70,752 KB
testcase_30 AC 58 ms
70,368 KB
testcase_31 AC 59 ms
70,784 KB
testcase_32 AC 238 ms
94,560 KB
evil_2_big_1.txt AC 1,388 ms
100,432 KB
evil_2_big_2.txt TLE -
evil_2_big_3.txt AC 1,359 ms
100,552 KB
evil_big_1.txt AC 1,810 ms
109,356 KB
evil_big_2.txt AC 1,871 ms
116,064 KB
evil_big_3.txt AC 1,876 ms
115,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def rec():
    ret = int(input())
    if ret == -1:
        exit()

def inp():
    global g
    i, k = map(int, input().split())
    i -= 1
    g ^= A[i]
    dic[A[i]].remove(i)
    A[i] -= k
    if A[i] == 0:
        remain.remove(i)
    else:
        dic[A[i]].add(i)
    g ^= A[i]

def find(x):
    j = 0
    if len(dic[x]) > 0:
        return next(iter(dic[x]))
    else:
        return -1

from collections import defaultdict
dic = defaultdict(set)
n = int(input())
A = list(map(int, input().split()))
remain = set(range(n))
g = 0
for i, a in enumerate(A):
    g ^= a
    dic[a].add(i)

if g == 0:
    print(0)
else:
    print(1)

while 1:
    #print(A,g)
    if g != 0:
        i = find(g)
        if i == -1:
            for j in remain:
                gt = A[j] ^ g
                if gt <= A[j]:
                    i = j
                    break
        dic[A[i]].remove(i)
        to = A[i] ^ g
        subt = A[i] - to
        A[i] = to
        if A[i] == 0:
            remain.remove(i)
        else:
            dic[A[i]].add(i)
        g = 0
        print(i + 1, subt)
        rec()

    #if sum(A) == 0:
    #    print("finish")
    #    exit()
    #print(A,g)
    inp()
    rec()
0