結果

問題 No.130 XOR Minimax
ユーザー Mao-betaMao-beta
提出日時 2024-03-15 01:02:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,779 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 648,820 KB
最終ジャッジ日時 2024-03-15 01:02:44
合計ジャッジ時間 34,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,779 ms
275,064 KB
testcase_01 AC 31 ms
10,368 KB
testcase_02 AC 30 ms
10,368 KB
testcase_03 AC 31 ms
10,368 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


class Node:
    def __init__(self):
        self.child = [-1] * 2


class BinaryTrie:
    def __init__(self, bit=32):
        self.D = [Node()]
        self.bit = bit

    def add(self, x):
        now = 0
        for i in range(self.bit-1, -1, -1):
            b = (x>>i) & 1
            if self.D[now].child[b] == -1:
                self.D[now].child[b] = len(self.D)
            now = self.D[now].child[b]
            self.D.append(Node())

    def dfs(self):
        ans = 1 << self.bit
        stack = deque()
        stack.append([0, 0])
        while stack:
            now, res = stack.pop()
            l, r = self.D[now].child
            if l == r == -1:
                ans = min(ans, res)
            elif l == -1 or r == -1:
                res <<= 1
                if l == -1:
                    stack.append([r, res])
                else:
                    stack.append([l, res])
            else:
                res = (res << 1) | 1
                stack.append([l, res])
                stack.append([r, res])
        return ans


def main():
    N = NI()
    A = NLI()
    trie = BinaryTrie()
    for a in A:
        trie.add(a)
    print(trie.dfs())


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