結果

問題 No.1289 RNG and OR
ユーザー chineristACchineristAC
提出日時 2020-11-13 22:02:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 727 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 137,304 KB
最終ジャッジ日時 2023-09-30 02:53:48
合計ジャッジ時間 4,564 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,412 KB
testcase_01 AC 76 ms
71,328 KB
testcase_02 AC 75 ms
71,256 KB
testcase_03 AC 75 ms
71,172 KB
testcase_04 AC 76 ms
71,268 KB
testcase_05 AC 75 ms
71,236 KB
testcase_06 AC 77 ms
70,884 KB
testcase_07 AC 73 ms
71,328 KB
testcase_08 AC 76 ms
71,012 KB
testcase_09 AC 76 ms
71,420 KB
testcase_10 AC 86 ms
76,376 KB
testcase_11 AC 83 ms
76,096 KB
testcase_12 AC 86 ms
75,908 KB
testcase_13 AC 133 ms
77,228 KB
testcase_14 AC 104 ms
77,312 KB
testcase_15 AC 112 ms
78,812 KB
testcase_16 AC 126 ms
79,928 KB
testcase_17 AC 165 ms
85,184 KB
testcase_18 AC 228 ms
92,236 KB
testcase_19 AC 392 ms
104,748 KB
testcase_20 AC 727 ms
137,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

N = int(input())
A = list(map(int,input().split()))
mod = 998244353
S = sum(A)
inv = pow(S,mod-2,mod)

dp = [[0 for j in range(N+1)] for i in range(2**N)]
for i in range(2**N):
    dp[i][0] = inv * A[i] % mod

for j in range(N):
    for i in range(2**N):
        if i&(1<<j):
            dp[i][j+1] = dp[i & ~(1<<j)][j] + dp[i][j]
        else:
            dp[i][j+1] = dp[i][j]

#for i in range(2**N):
    #print(dp[i][N]*S %mod)

res = 0
for i in range(2**N-1):
    res += pow(-1,N-1-popcount(i),mod) * pow(1-dp[i][N],mod-2,mod)
    res %= mod

print(res)
0