結果

問題 No.1289 RNG and OR
ユーザー shotoyooshotoyoo
提出日時 2020-11-13 23:18:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 114,228 KB
最終ジャッジ日時 2023-09-30 04:17:31
合計ジャッジ時間 4,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 77 ms
71,472 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
M = 998244353

### 素数の逆元とCombination

N = 104 # 必要なテーブルサイズ
g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M
def perm(n, r, M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M

ps = [0]*n
for b in range(1<<n):
    for i in range(n):
        if b>>i&1:
            ps[i] += a[b]
total = sum(a)
tinv = pow(total, M-2, M)
for i in range(n):
    ps[i] = ps[i] * tinv
    ps[i] %= M
ans = 0
for b in range(1,(1<<n)-1):
    s = bin(b).count("1")
    si = -1
    val = 1
    for i in range(n):
        if b>>i&1:
            si *= -1
            val *= (1 - ps[i])
            val %= M
    ans += val * si * pow(1-val, M-2, M)
print(ans%M)
0