結果

問題 No.130 XOR Minimax
ユーザー しらっ亭しらっ亭
提出日時 2015-07-14 12:07:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 243 ms / 5,000 ms
コード長 570 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 38,356 KB
最終ジャッジ日時 2023-10-10 00:09:55
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
12,876 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 17 ms
7,768 KB
testcase_03 AC 17 ms
7,948 KB
testcase_04 AC 180 ms
33,112 KB
testcase_05 AC 209 ms
38,356 KB
testcase_06 AC 228 ms
27,004 KB
testcase_07 AC 243 ms
26,396 KB
testcase_08 AC 201 ms
19,128 KB
testcase_09 AC 52 ms
11,544 KB
testcase_10 AC 73 ms
13,528 KB
testcase_11 AC 213 ms
24,552 KB
testcase_12 AC 33 ms
9,744 KB
testcase_13 AC 172 ms
21,660 KB
testcase_14 AC 206 ms
17,492 KB
testcase_15 AC 18 ms
8,160 KB
testcase_16 AC 144 ms
14,528 KB
testcase_17 AC 151 ms
14,908 KB
testcase_18 AC 160 ms
15,360 KB
testcase_19 AC 196 ms
16,468 KB
testcase_20 AC 97 ms
12,828 KB
testcase_21 AC 208 ms
17,108 KB
testcase_22 AC 52 ms
10,124 KB
testcase_23 AC 26 ms
8,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(d, a):
    if len(a) == 1:
        return 0

    a0 = []
    a1 = []
    b = 1 << d
    for n in a:
        if n & b:
            a1.append(n)
        else:
            a0.append(n)

    if not a0 or not a1:
        if d == 0:
            return 0
        return dfs(d - 1, a)
    else:
        if d == 0:
            return 1
        return b + min(dfs(d - 1, a0), dfs(d - 1, a1))


def solve(N, A):
    return dfs(30, A)


def main():
    N = int(input())
    A = list(map(int, input().split()))

    print(solve(N, A))


if __name__ == '__main__':
    main()
0