結果

問題 No.2165 Let's Play Nim!
ユーザー H3PO4H3PO4
提出日時 2022-12-22 22:22:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 96,692 KB
平均クエリ数 884.90
最終ジャッジ日時 2023-08-11 11:26:54
合計ジャッジ時間 22,007 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
86,856 KB
testcase_01 AC 334 ms
95,680 KB
testcase_02 AC 355 ms
95,292 KB
testcase_03 AC 297 ms
95,224 KB
testcase_04 AC 100 ms
91,632 KB
testcase_05 AC 127 ms
91,584 KB
testcase_06 AC 126 ms
92,180 KB
testcase_07 AC 117 ms
92,116 KB
testcase_08 AC 297 ms
95,052 KB
testcase_09 AC 107 ms
91,524 KB
testcase_10 AC 147 ms
92,916 KB
testcase_11 AC 354 ms
96,296 KB
testcase_12 AC 336 ms
95,032 KB
testcase_13 AC 96 ms
91,436 KB
testcase_14 AC 123 ms
91,940 KB
testcase_15 AC 104 ms
91,344 KB
testcase_16 AC 322 ms
95,312 KB
testcase_17 AC 252 ms
94,480 KB
testcase_18 AC 396 ms
95,528 KB
testcase_19 AC 99 ms
91,324 KB
testcase_20 AC 116 ms
91,436 KB
testcase_21 AC 228 ms
94,208 KB
testcase_22 AC 192 ms
94,228 KB
testcase_23 AC 177 ms
93,496 KB
testcase_24 AC 177 ms
93,720 KB
testcase_25 AC 264 ms
95,128 KB
testcase_26 AC 361 ms
96,692 KB
testcase_27 AC 209 ms
94,084 KB
testcase_28 AC 266 ms
94,352 KB
testcase_29 AC 94 ms
87,304 KB
testcase_30 AC 89 ms
87,276 KB
testcase_31 AC 92 ms
87,440 KB
testcase_32 AC 249 ms
94,532 KB
evil_2_big_1.txt AC 1,659 ms
99,120 KB
evil_2_big_2.txt AC 1,833 ms
104,280 KB
evil_2_big_3.txt AC 1,758 ms
99,112 KB
evil_big_1.txt AC 1,775 ms
103,592 KB
evil_big_2.txt AC 1,805 ms
105,112 KB
evil_big_3.txt AC 1,802 ms
105,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Player:
    MAX_BIT = 17

    def __init__(self, N: int, A: list):
        self.N = N
        self.A = A
        self.x = self.calc_initial_xor(A)
        self.bits_set = self.calc_initial_bits(A)

    @staticmethod
    def calc_initial_xor(A: list):
        x = 0
        for a in A:
            x ^= a
        return x

    @classmethod
    def calc_initial_bits(cls, A: list):
        st = [set() for _ in range(cls.MAX_BIT)]
        for i, a in enumerate(A):
            for n in range(cls.MAX_BIT):
                if (a >> n) & 1:
                    st[n].add(i)
        return st

    def output(self):
        for n in range(self.MAX_BIT - 1, -1, -1):
            if (self.x >> n) & 1:
                i = self.bits_set[n].pop()
                k = self.A[i] - (self.A[i] ^ self.x)
                self.update(i + 1, k)
                assert self.x == 0
                return i + 1, k

    def update(self, i: int, k: int):
        i -= 1
        self.x ^= self.A[i]
        self.A[i] -= k
        self.x ^= self.A[i]
        for n in range(self.MAX_BIT):
            if i in self.bits_set[n]:
                self.bits_set[n].remove(i)
            if (self.A[i] >> n) & 1:
                self.bits_set[n].add(i)


N = int(input())
A = list(map(int, input().split()))

player = Player(N, A)
t = 0 if player.x == 0 else 1
"""先攻:t=1, 後攻:t=0"""

print(t, flush=True)

while True:
    if t:
        print(*player.output(), flush=True)
    else:
        player.update(*map(int, input().split()))
    ret = int(input())
    if ret != 0:
        exit()
    t = 1 - t
0