結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2024-03-15 01:03:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,223 ms / 5,000 ms |
コード長 | 1,759 bytes |
コンパイル時間 | 417 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 456,840 KB |
最終ジャッジ日時 | 2024-09-29 23:55:30 |
合計ジャッジ時間 | 16,903 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import sysimport mathimport bisectfrom heapq import heapify, heappop, heappushfrom collections import deque, defaultdict, Counterfrom functools import lru_cachefrom itertools import accumulate, combinations, permutations, productsys.setrecursionlimit(1000000)MOD = 10 ** 9 + 7MOD99 = 998244353input = 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] * 2class BinaryTrie:def __init__(self, bit=32):self.D = [[-1, -1]]self.bit = bitdef add(self, x):now = 0for i in range(self.bit-1, -1, -1):b = (x>>i) & 1if self.D[now][b] == -1:self.D[now][b] = len(self.D)now = self.D[now][b]self.D.append([-1, -1])def dfs(self):ans = 1 << self.bitstack = deque()stack.append([0, 0])while stack:now, res = stack.pop()l, r = self.D[now]if l == r == -1:ans = min(ans, res)elif l == -1 or r == -1:res <<= 1if l == -1:stack.append([r, res])else:stack.append([l, res])else:res = (res << 1) | 1stack.append([l, res])stack.append([r, res])return ansdef main():N = NI()A = NLI()trie = BinaryTrie()for a in A:trie.add(a)print(trie.dfs())if __name__ == "__main__":main()