結果
問題 | No.1289 RNG and OR |
ユーザー |
|
提出日時 | 2020-11-13 22:02:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 725 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,828 KB |
実行使用メモリ | 136,880 KB |
最終ジャッジ日時 | 2024-07-22 20:50:46 |
合計ジャッジ時間 | 3,687 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
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)