結果

問題 No.130 XOR Minimax
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-10 11:36:33
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 359 ms / 5,000 ms
コード長 698 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 21,208 KB
最終ジャッジ日時 2023-10-10 00:09:09
合計ジャッジ時間 4,862 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
15,244 KB
testcase_01 AC 15 ms
8,132 KB
testcase_02 AC 15 ms
7,996 KB
testcase_03 AC 15 ms
8,020 KB
testcase_04 AC 32 ms
10,124 KB
testcase_05 AC 47 ms
18,948 KB
testcase_06 AC 111 ms
21,020 KB
testcase_07 AC 115 ms
21,104 KB
testcase_08 AC 359 ms
21,208 KB
testcase_09 AC 36 ms
10,312 KB
testcase_10 AC 44 ms
12,992 KB
testcase_11 AC 90 ms
17,652 KB
testcase_12 AC 26 ms
9,552 KB
testcase_13 AC 74 ms
15,828 KB
testcase_14 AC 312 ms
20,492 KB
testcase_15 AC 18 ms
8,272 KB
testcase_16 AC 206 ms
15,928 KB
testcase_17 AC 224 ms
16,276 KB
testcase_18 AC 226 ms
15,800 KB
testcase_19 AC 273 ms
16,744 KB
testcase_20 AC 142 ms
14,880 KB
testcase_21 AC 301 ms
20,280 KB
testcase_22 AC 76 ms
10,464 KB
testcase_23 AC 34 ms
8,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def read_data():
    N = int(input())
    As = list(map(int, input().split()))
    return N, As

def solve(N, As):
    As = list(set(As))
    As.sort()
    maxA = As[-1]
    if maxA == 0:
        return 0
    idx = 1 << (len(bin(maxA)) - 2)
    return divq(As, idx, 0, len(As))

def divq(As, idx, begin, end):
    if idx == 1 or end <= begin:
        return 0
    new_idx = idx >> 1
    if not(As[end-1] & new_idx) or As[begin] & new_idx:
        return divq(As, new_idx, begin, end)
    mid = bisect.bisect_left(As, (As[begin]&(-idx))+new_idx, begin, end)
    return new_idx + min(divq(As, new_idx, begin, mid), divq(As, new_idx, mid, end))

N, As = read_data()
print(solve(N, As))
0