結果

問題 No.130 XOR Minimax
ユーザー Coki628Coki628
提出日時 2020-01-13 01:25:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 665 ms / 5,000 ms
コード長 1,381 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 38,428 KB
最終ジャッジ日時 2023-10-10 00:26:31
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
13,644 KB
testcase_01 AC 17 ms
8,264 KB
testcase_02 AC 17 ms
8,416 KB
testcase_03 AC 18 ms
8,344 KB
testcase_04 AC 269 ms
33,132 KB
testcase_05 AC 307 ms
38,428 KB
testcase_06 AC 346 ms
27,276 KB
testcase_07 AC 362 ms
26,588 KB
testcase_08 AC 665 ms
19,136 KB
testcase_09 AC 73 ms
11,732 KB
testcase_10 AC 104 ms
13,768 KB
testcase_11 AC 315 ms
23,664 KB
testcase_12 AC 44 ms
9,708 KB
testcase_13 AC 251 ms
21,676 KB
testcase_14 AC 571 ms
17,484 KB
testcase_15 AC 23 ms
8,084 KB
testcase_16 AC 403 ms
14,704 KB
testcase_17 AC 422 ms
14,992 KB
testcase_18 AC 455 ms
15,404 KB
testcase_19 AC 542 ms
16,668 KB
testcase_20 AC 267 ms
13,056 KB
testcase_21 AC 558 ms
17,440 KB
testcase_22 AC 134 ms
10,264 KB
testcase_23 AC 53 ms
8,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

def rec(li, k):
    if not li or k < 0:
        return 0
    li1, li2 = [], []
    # 今見ている桁が1の要素と0の要素で振り分ける
    for a in li:
        if a & 1<<k:
            li1.append(a)
        else:
            li2.append(a)
    # 全て片方にあれば、この桁は(最大値になりうる)全要素で0にできる
    if not li1 or not li2:
        return rec(li, k - 1)
    else:
        # 0も1もあれば、この桁が(最大値になりうる)いずれかの要素で立つのは確定で、どちらを立たせた方が得かを下の桁に調べに行く
        return min(rec(li1, k - 1), rec(li2, k - 1)) + (1 << k)

print(rec(A, 30))
0