結果
問題 |
No.1240 Or Sum of Xor Pair
|
ユーザー |
👑 ![]() |
提出日時 | 2020-08-24 23:13:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 931 ms / 2,000 ms |
コード長 | 1,181 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 157,140 KB |
最終ジャッジ日時 | 2024-06-22 07:10:26 |
合計ジャッジ時間 | 30,058 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import sys input = sys.stdin.readline def fwht(a): n = len(a) j = 1 while j < n: for i in range(0, n): if i & j == 0: a[i], a[i | j] = a[i] + a[i | j], a[i] - a[i | j] j <<= 1 return a def ifwht(a): n = len(a) j = 1 while j < n: for i in range(0, n): if i & j == 0: a[i], a[i | j] = (a[i] + a[i | j]) >> 1, (a[i] - a[i | j]) >> 1 j <<= 1 return a n, x = map(int, input().split()) a = [*map(int, input().split())] cnt = [0] * 2**18 for i in a: cnt[i] += 1 # XOR 畳み込み fwht(cnt) for i in range(2**18): cnt[i] **= 2 ifwht(cnt) cnt[0] -= n A = sum(cnt[:x]) // 2 # A_i ^ A_j < X となる (i, j) の個数 ans = 0 for k in range(18): bit = 1 << k cnt = [0] * 2**18 B = 0 for i in a: if not i & bit: cnt[i] += 1 B += 1 # XOR 畳み込み fwht(cnt) for i in range(2**18): cnt[i] **= 2 ifwht(cnt) cnt[0] -= B B = sum(cnt[:x]) // 2 # A_i, A_j の k bit 目が立っていない かつ A_i ^ A_j < X となる (i, j) の個数 ans += (A - B) * bit print(ans)