結果

問題 No.1189 Sum is XOR
ユーザー 👑 rin204rin204
提出日時 2022-03-23 17:10:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,927 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 105,216 KB
最終ジャッジ日時 2024-04-20 01:22:36
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
105,088 KB
testcase_01 AC 137 ms
105,088 KB
testcase_02 AC 131 ms
105,216 KB
testcase_03 AC 36 ms
52,224 KB
testcase_04 AC 34 ms
52,736 KB
testcase_05 AC 33 ms
52,224 KB
testcase_06 AC 33 ms
52,224 KB
testcase_07 AC 33 ms
52,352 KB
testcase_08 AC 32 ms
52,480 KB
testcase_09 AC 34 ms
52,224 KB
testcase_10 AC 35 ms
52,736 KB
testcase_11 AC 115 ms
80,800 KB
testcase_12 AC 132 ms
105,068 KB
testcase_13 AC 134 ms
101,760 KB
testcase_14 AC 125 ms
91,392 KB
testcase_15 AC 118 ms
80,780 KB
testcase_16 AC 121 ms
78,208 KB
testcase_17 AC 119 ms
80,128 KB
testcase_18 AC 115 ms
84,908 KB
testcase_19 AC 134 ms
96,000 KB
testcase_20 AC 140 ms
96,128 KB
testcase_21 AC 96 ms
77,080 KB
testcase_22 AC 96 ms
77,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x0000003f

MOD = 998244353

def convolve_subset(A, B):
    n = max(len(A), len(B))
    l = ((n - 1).bit_length())
    m = 1 << l
    l += 1
    A_ = [0] * (l * m)
    B_ = [0] * (l * m)
    for i, a in enumerate(A):
        A_[i * l + popcount(i)] += a
        A_[i * l + popcount(i)] %= MOD
        
    for i, b in enumerate(B):
        B_[i * l + popcount(i)] += b
        B_[i * l + popcount(i)] %= MOD
    
    def f(A):
        for i in range(l):
            for bit in range(m):
                if bit >> i & 1:
                    for j in range(l):
                        A[bit * l + j] += A[(bit ^ (1 << i)) * l + j]
                        A[bit * l + j] %= MOD
    
    def invf(A):
        for i in range(l):
            for bit in range(m):
                if bit >> i & 1:
                    for j in range(l):
                        A[bit * l + j] -= A[(bit ^ (1 << i)) * l + j]
                        A[bit * l + j] %= MOD
    
    f(A_)
    f(B_)
    C_ = [0] * (l * m)
    for bit in range(m):
        for i in range(l):
            for j in range(l):
                if i + j >= l:
                    break
                C_[bit * l + i + j] += A_[bit * l + i] * B_[bit * l + j]
                C_[bit * l + i + j] %= MOD
    invf(C_)
    C = [0] * m
    for i in range(m):
        C[i] = C_[i * l + popcount(i)]
    return C
    
MOD = 998244353
n, k = map(int, input().split())
if k > 10:
    print(0)
    exit()
    
A = list(map(int, input().split()))
X = [0] * (1 << 10)
for a in A:
    X[a] += 1
ans = [0] * (1 << 10)
ans[0] = 1
for _ in range(k):
    ans = convolve_subset(ans, X[:])

inv = 1
for i in range(2, k + 1):
    inv *= i
    inv %= MOD
inv = pow(inv, MOD - 2, MOD)
print(sum(ans) * inv % MOD)

0