結果
問題 | No.2977 Kth Xor Pair |
ユーザー |
![]() |
提出日時 | 2024-12-01 13:28:11 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,451 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 1,705,068 KB |
最終ジャッジ日時 | 2024-12-01 13:30:18 |
合計ジャッジ時間 | 125,809 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
67,328 KB |
testcase_01 | MLE | - |
testcase_02 | AC | 175 ms
101,064 KB |
testcase_03 | MLE | - |
testcase_04 | AC | 164 ms
99,468 KB |
testcase_05 | MLE | - |
testcase_06 | AC | 165 ms
99,840 KB |
testcase_07 | MLE | - |
testcase_08 | TLE | - |
testcase_09 | MLE | - |
testcase_10 | TLE | - |
testcase_11 | MLE | - |
testcase_12 | TLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
testcase_35 | MLE | - |
ソースコード
class Trie: def __init__(self, N): self.tree = [[-1]*2 for _ in range(N+1)] self.arrive = [0]*(N+1) self.nex = 1 def insert(self, S): now = 0 for i in range(30): b = 1&S>>(29-i) if self.tree[now][b] == -1: self.tree[now][b] = self.nex now = self.nex self.nex += 1 else: now = self.tree[now][b] self.arrive[now] += 1 def query(self, MAX, S): now = 0 ans = 0 xor = MAX^S for i in range(30): b = 1 & S>>(29-i) if 1<<(29-i) & MAX: if b == 0 and self.tree[now][0] != -1: ans += self.arrive[self.tree[now][0]] elif b == 1 and self.tree[now][1] != -1: ans += self.arrive[self.tree[now][1]] b2 = 1 & xor>>(29-i) if self.tree[now][b2] != -1: now = self.tree[now][b2] else: break return ans N, K = map(int, input().split()) A = list(map(int, input().split())) def func(n): T = Trie(N*30) ans = 0 for i in reversed(range(N)): T.insert(A[i]) ans += T.query(n, A[i])-1 del T return ans left = 0 right = (1<<30)-1 while left+1 < right: mid = (left+right)//2 if func(mid) < K: left = mid else: right = mid print(right-1)