結果

問題 No.130 XOR Minimax
ユーザー ntudantuda
提出日時 2022-02-13 10:59:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 565 ms / 5,000 ms
コード長 718 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 93,108 KB
最終ジャッジ日時 2023-09-11 15:19:52
合計ジャッジ時間 7,953 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 319 ms
83,776 KB
testcase_01 AC 92 ms
71,776 KB
testcase_02 AC 95 ms
71,552 KB
testcase_03 AC 96 ms
71,752 KB
testcase_04 AC 117 ms
89,920 KB
testcase_05 AC 122 ms
92,368 KB
testcase_06 AC 171 ms
91,888 KB
testcase_07 AC 178 ms
92,924 KB
testcase_08 AC 565 ms
93,108 KB
testcase_09 AC 156 ms
79,124 KB
testcase_10 AC 170 ms
80,220 KB
testcase_11 AC 201 ms
90,516 KB
testcase_12 AC 149 ms
78,784 KB
testcase_13 AC 191 ms
87,296 KB
testcase_14 AC 490 ms
90,952 KB
testcase_15 AC 122 ms
77,644 KB
testcase_16 AC 383 ms
86,732 KB
testcase_17 AC 395 ms
86,204 KB
testcase_18 AC 426 ms
87,908 KB
testcase_19 AC 469 ms
89,400 KB
testcase_20 AC 302 ms
83,168 KB
testcase_21 AC 488 ms
91,656 KB
testcase_22 AC 213 ms
79,120 KB
testcase_23 AC 156 ms
78,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
Yuki130
No.130 XOR Minimax
'''
from collections import deque
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
A.sort()
amax = max(A)
n = amax.bit_length() - 1
q = deque()  # target,left,right,value
q.append((2 ** n, n, 0, N, 0))
ans = 10 ** 10
while len(q) > 0:
    (x, i, l, r, v) = q.pop()
    if i < 0:
        if ans > v:
            ans = v
        continue
    y = bisect_left(A, x)
    if y == l:
        q.append((x + 2 ** (i - 1), i - 1, y, r, v * 2))
    elif y == r:
        q.append((x - 2 ** (i - 1), i - 1, l, y, v * 2))
    else:
        q.append((x + 2 ** (i - 1), i - 1, y, r, v * 2 + 1))
        q.append((x - 2 ** (i - 1), i - 1, l, y, v * 2 + 1))
print(ans)
0