結果

問題 No.130 XOR Minimax
ユーザー roiti46roiti46
提出日時 2015-02-26 00:04:24
言語 Python2
(2.7.18)
結果
AC  
実行時間 870 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 6,704 KB
実行使用メモリ 61,100 KB
最終ジャッジ日時 2023-10-10 00:07:54
合計ジャッジ時間 8,836 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 258 ms
11,616 KB
testcase_01 AC 11 ms
5,920 KB
testcase_02 AC 11 ms
6,064 KB
testcase_03 AC 11 ms
6,064 KB
testcase_04 AC 49 ms
7,352 KB
testcase_05 AC 63 ms
14,564 KB
testcase_06 AC 865 ms
61,100 KB
testcase_07 AC 870 ms
59,520 KB
testcase_08 AC 581 ms
19,268 KB
testcase_09 AC 121 ms
13,648 KB
testcase_10 AC 182 ms
17,552 KB
testcase_11 AC 506 ms
37,432 KB
testcase_12 AC 64 ms
9,680 KB
testcase_13 AC 432 ms
32,884 KB
testcase_14 AC 525 ms
17,272 KB
testcase_15 AC 14 ms
6,092 KB
testcase_16 AC 364 ms
13,872 KB
testcase_17 AC 375 ms
13,980 KB
testcase_18 AC 406 ms
14,900 KB
testcase_19 AC 488 ms
16,472 KB
testcase_20 AC 230 ms
11,012 KB
testcase_21 AC 517 ms
17,076 KB
testcase_22 AC 104 ms
8,100 KB
testcase_23 AC 36 ms
6,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    one  = [ai ^ (ai & (1 << shift)) for ai in a if     ai & (1 << shift) and ai >> (shift+1) == 0]
    zero = [ai ^ (ai & (1 << shift)) for ai in a if not ai & (1 << shift) and ai >> (shift+1) == 0]
    
    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