結果

問題 No.1240 Or Sum of Xor Pair
ユーザー 👑 tatyamtatyam
提出日時 2020-08-24 23:13:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,137 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 157,420 KB
最終ジャッジ日時 2023-09-04 07:54:42
合計ジャッジ時間 38,109 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 860 ms
115,132 KB
testcase_01 AC 861 ms
115,084 KB
testcase_02 AC 872 ms
115,568 KB
testcase_03 AC 1,041 ms
154,320 KB
testcase_04 AC 1,043 ms
148,572 KB
testcase_05 AC 1,024 ms
139,536 KB
testcase_06 AC 1,022 ms
140,056 KB
testcase_07 AC 1,032 ms
146,516 KB
testcase_08 AC 1,035 ms
148,560 KB
testcase_09 AC 1,020 ms
138,996 KB
testcase_10 AC 1,029 ms
144,528 KB
testcase_11 AC 1,049 ms
155,360 KB
testcase_12 AC 1,045 ms
145,088 KB
testcase_13 AC 1,056 ms
156,200 KB
testcase_14 AC 1,059 ms
156,960 KB
testcase_15 AC 1,125 ms
149,212 KB
testcase_16 AC 1,119 ms
145,384 KB
testcase_17 AC 1,132 ms
152,892 KB
testcase_18 AC 1,107 ms
140,836 KB
testcase_19 AC 1,118 ms
153,188 KB
testcase_20 AC 1,135 ms
156,468 KB
testcase_21 AC 1,110 ms
139,376 KB
testcase_22 AC 1,123 ms
149,176 KB
testcase_23 AC 1,137 ms
155,004 KB
testcase_24 AC 1,127 ms
155,020 KB
testcase_25 AC 1,131 ms
155,632 KB
testcase_26 AC 1,115 ms
145,824 KB
testcase_27 AC 858 ms
115,324 KB
testcase_28 AC 863 ms
114,956 KB
testcase_29 AC 948 ms
157,420 KB
testcase_30 AC 1,053 ms
128,032 KB
testcase_31 AC 1,022 ms
115,876 KB
testcase_32 AC 1,076 ms
131,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0