結果

問題 No.130 XOR Minimax
ユーザー roiti46roiti46
提出日時 2015-02-26 00:02:35
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,124 ms / 5,000 ms
コード長 447 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 61,236 KB
最終ジャッジ日時 2023-10-10 00:08:15
合計ジャッジ時間 11,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 492 ms
11,736 KB
testcase_01 AC 12 ms
5,864 KB
testcase_02 AC 12 ms
6,000 KB
testcase_03 AC 12 ms
6,044 KB
testcase_04 AC 50 ms
7,216 KB
testcase_05 AC 63 ms
14,532 KB
testcase_06 AC 711 ms
61,236 KB
testcase_07 AC 716 ms
59,728 KB
testcase_08 AC 1,124 ms
19,080 KB
testcase_09 AC 116 ms
13,716 KB
testcase_10 AC 168 ms
17,372 KB
testcase_11 AC 447 ms
37,380 KB
testcase_12 AC 64 ms
9,684 KB
testcase_13 AC 378 ms
32,924 KB
testcase_14 AC 938 ms
17,044 KB
testcase_15 AC 20 ms
5,952 KB
testcase_16 AC 665 ms
13,988 KB
testcase_17 AC 685 ms
14,080 KB
testcase_18 AC 738 ms
14,752 KB
testcase_19 AC 880 ms
16,528 KB
testcase_20 AC 434 ms
11,008 KB
testcase_21 AC 928 ms
17,168 KB
testcase_22 AC 208 ms
8,148 KB
testcase_23 AC 70 ms
6,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def rec(shift, a):
    if shift < 0: return 0

    one  = [ai ^ (ai & (1 << shift)) for ai in a if     ai & (1 << shift)]
    zero = [ai ^ (ai & (1 << shift)) for ai in a if not ai & (1 << shift)]
    
    if not zero: return rec(shift - 1,  one)
    if not  one: return rec(shift - 1, zero)

    return (1 << shift) + min(rec(shift - 1, zero), rec(shift - 1, one))

N = int(raw_input())
A = list(set(map(int,raw_input().split())))
print rec(30,A)
0