結果

問題 No.130 XOR Minimax
ユーザー HachimoriHachimori
提出日時 2015-01-17 16:48:56
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,021 ms / 5,000 ms
コード長 999 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 35,172 KB
最終ジャッジ日時 2023-10-10 00:07:26
合計ジャッジ時間 12,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 465 ms
9,428 KB
testcase_01 AC 12 ms
6,024 KB
testcase_02 AC 12 ms
6,024 KB
testcase_03 AC 12 ms
6,124 KB
testcase_04 AC 424 ms
32,496 KB
testcase_05 AC 436 ms
35,172 KB
testcase_06 AC 501 ms
23,744 KB
testcase_07 AC 503 ms
23,384 KB
testcase_08 AC 1,021 ms
14,748 KB
testcase_09 AC 99 ms
8,832 KB
testcase_10 AC 141 ms
10,212 KB
testcase_11 AC 446 ms
21,076 KB
testcase_12 AC 54 ms
7,316 KB
testcase_13 AC 362 ms
17,760 KB
testcase_14 AC 882 ms
13,124 KB
testcase_15 AC 21 ms
6,172 KB
testcase_16 AC 612 ms
10,980 KB
testcase_17 AC 641 ms
11,000 KB
testcase_18 AC 684 ms
11,564 KB
testcase_19 AC 812 ms
12,696 KB
testcase_20 AC 406 ms
9,208 KB
testcase_21 AC 855 ms
13,180 KB
testcase_22 AC 196 ms
7,424 KB
testcase_23 AC 67 ms
6,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8

def read():
    N = input()
    return map(int, raw_input().split())


def rec(bit, vList):
    if bit == -1:
        return (0, 0)
    
    zeroList = []
    oneList = []
    
    for v in vList:
        if v & (1 << bit):
            oneList.append(v)
        else:
            zeroList.append(v)    

    if zeroList and oneList:
        (x1, val1) = rec(bit - 1, oneList)
        (x2, val2) = rec(bit - 1, zeroList)
        if val1 < val2:
            return (x1             , val1 + (1 << bit))
        else:
            return (x2 + (1 << bit), val2 + (1 << bit))
        
    elif not zeroList and     oneList:
        (x, val) = rec(bit - 1, oneList)
        return (x + (1 << bit), val)
        
    elif     zeroList and not oneList:
        (x, val) = rec(bit - 1, zeroList)
        return (x, val)
    
    else:
        assert False
        

def work(vList):
    (x, val) = rec(32, vList)
    print val


if __name__ == "__main__":
    work(read())
0