結果

問題 No.2165 Let's Play Nim!
ユーザー ntudantuda
提出日時 2023-04-16 10:27:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,453 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 284,420 KB
平均クエリ数 612.82
最終ジャッジ日時 2024-04-20 02:16:43
合計ジャッジ時間 12,092 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
69,560 KB
testcase_01 AC 752 ms
113,356 KB
testcase_02 AC 892 ms
142,780 KB
testcase_03 AC 352 ms
94,920 KB
testcase_04 AC 55 ms
69,496 KB
testcase_05 AC 80 ms
82,244 KB
testcase_06 AC 76 ms
81,508 KB
testcase_07 AC 75 ms
79,704 KB
testcase_08 AC 386 ms
98,728 KB
testcase_09 AC 70 ms
75,924 KB
testcase_10 AC 97 ms
86,660 KB
testcase_11 AC 956 ms
157,400 KB
testcase_12 AC 659 ms
110,184 KB
testcase_13 AC 54 ms
69,984 KB
testcase_14 AC 70 ms
80,256 KB
testcase_15 AC 57 ms
70,644 KB
testcase_16 AC 562 ms
104,516 KB
testcase_17 AC 229 ms
93,592 KB
testcase_18 TLE -
testcase_19 AC 55 ms
71,164 KB
testcase_20 AC 68 ms
79,352 KB
testcase_21 AC 163 ms
92,912 KB
testcase_22 AC 118 ms
92,516 KB
testcase_23 AC 115 ms
92,376 KB
testcase_24 AC 114 ms
92,328 KB
testcase_25 AC 343 ms
95,752 KB
testcase_26 AC 906 ms
145,736 KB
testcase_27 AC 126 ms
93,276 KB
testcase_28 AC 221 ms
93,884 KB
testcase_29 AC 55 ms
70,772 KB
testcase_30 AC 53 ms
70,700 KB
testcase_31 AC 55 ms
69,544 KB
testcase_32 AC 214 ms
94,140 KB
evil_2_big_1.txt TLE -
evil_2_big_2.txt TLE -
evil_2_big_3.txt TLE -
evil_big_1.txt TLE -
evil_big_2.txt TLE -
evil_big_3.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

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]
    remX(A[i], i)
    A[i] -= k
    if A[i] == 0:
        remain.remove(i)

    setX(A[i], i)
    g ^= A[i]

def remX(x, i):
    j = 0
    while x > 0:
        if x & 1:
            X[j].remove(i)
        x >>= 1
        j += 1

def setX(x, i):
    j = 0
    while x > 0:
        if x & 1:
            X[j].add(i)
        x >>= 1
        j += 1

def find(x):
    j = 0
    tmp = set(range(n))
    while x > 0:
        if x & 1:
            tmp &= X[j]
        j += 1
        x >>= 1
    if tmp:
        return next(iter(tmp))
    else:
        return -1

X = [set() for _ in range(14)]
n = int(input())
A = list(map(int, input().split()))
remain = set(range(n))
g = 0

for i, a in enumerate(A):
    g ^= a
    setX(a, 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
        remX(A[i], i)
        to = A[i] ^ g
        subt = A[i] - to
        A[i] = to
        if A[i] == 0:
            remain.remove(i)
        setX(to, i)
        g = 0
        print(i + 1, subt)
        rec()

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