結果
問題 | No.2977 Kth Xor Pair |
ユーザー | PNJ |
提出日時 | 2024-12-08 16:39:52 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,449 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,096 KB |
実行使用メモリ | 166,148 KB |
最終ジャッジ日時 | 2024-12-08 16:40:18 |
合計ジャッジ時間 | 24,690 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 467 ms
139,904 KB |
testcase_01 | AC | 487 ms
140,056 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 607 ms
155,020 KB |
testcase_23 | AC | 628 ms
155,080 KB |
testcase_24 | AC | 610 ms
155,232 KB |
testcase_25 | RE | - |
testcase_26 | AC | 591 ms
154,844 KB |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 538 ms
165,224 KB |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
ソースコード
def walsh_hadamard_transform(f): k = (len(f) - 1).bit_length() h = 1 for _ in range(k): for i in range(0, len(f), h * 2): for j in range(i, i + h): f[j], f[j + h] = f[j] + f[j + h], f[j] - f[j + h] h *= 2 def Xor_convolution(a, b): f = a[:] g = b[:] k = (len(f) - 1).bit_length() walsh_hadamard_transform(f) walsh_hadamard_transform(g) for i in range(1 << k): f[i] = f[i] * g[i] walsh_hadamard_transform(f) for i in range(len(f)): f[i] >>= k return f N, K = map(int, input().split()) A = list(map(int, input().split())) F = [0 for i in range(1 << 20)] for a in A: F[a >> 10] += 1 F = Xor_convolution(F, F) F[0] -= N for i in range(1 << 20): F[i] //= 2 if i > 0: F[i] += F[i - 1] i = 0 while F[i] < K: i += 1 mask = i ans = i << 10 G = [[] for i in range(1 << 20)] for a in A: b = a >> 10 G[b].append(a - (b << 10)) F = [0 for i in range(1 << 10)] for i in range(1 << 20): c = min(len(G[i]), len(G[mask ^ i])) if c <= 100: for j in G[i]: for k in G[i ^ mask]: F[j ^ k] += 1 else: f, g = [0 for _ in range(1 << 10)], [0 for _ in range(1 << 10)] for j in G[i]: f[j] += 1 for k in G[i ^ mask]: g[k] += 1 f = Xor_convolution(f, g) for j in range(1 << 10): F[j] += f[j] if mask == 0: F[0] -= N for i in range(1 << 10): F[i] //= 2 if i > 0: F[i] += F[i - 1] i = 0 while F[i] < K: i += 1 ans += i print(ans)