結果

問題 No.1753 Don't cheat.
ユーザー chineristACchineristAC
提出日時 2021-11-19 22:03:56
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,367 ms / 3,000 ms
コード長 2,406 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 88,724 KB
最終ジャッジ日時 2023-08-30 08:34:41
合計ジャッジ時間 77,894 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,316 ms
87,596 KB
testcase_01 AC 2,297 ms
87,384 KB
testcase_02 AC 2,300 ms
87,532 KB
testcase_03 AC 2,295 ms
87,424 KB
testcase_04 AC 2,308 ms
87,452 KB
testcase_05 AC 2,297 ms
87,516 KB
testcase_06 AC 2,298 ms
87,512 KB
testcase_07 AC 2,299 ms
87,648 KB
testcase_08 AC 2,300 ms
87,348 KB
testcase_09 AC 2,302 ms
87,616 KB
testcase_10 AC 2,293 ms
87,540 KB
testcase_11 AC 2,292 ms
87,508 KB
testcase_12 AC 2,310 ms
87,536 KB
testcase_13 AC 2,284 ms
87,764 KB
testcase_14 AC 2,301 ms
87,428 KB
testcase_15 AC 2,311 ms
87,564 KB
testcase_16 AC 2,302 ms
87,532 KB
testcase_17 AC 2,342 ms
87,584 KB
testcase_18 AC 2,345 ms
87,788 KB
testcase_19 AC 2,351 ms
88,424 KB
testcase_20 AC 2,324 ms
88,724 KB
testcase_21 AC 2,321 ms
87,732 KB
testcase_22 AC 2,329 ms
87,944 KB
testcase_23 AC 2,299 ms
87,500 KB
testcase_24 AC 2,367 ms
87,996 KB
testcase_25 AC 2,300 ms
87,492 KB
testcase_26 AC 2,343 ms
87,696 KB
testcase_27 AC 2,316 ms
87,516 KB
testcase_28 AC 2,313 ms
87,396 KB
testcase_29 AC 2,315 ms
87,652 KB
testcase_30 AC 2,303 ms
87,632 KB
testcase_31 AC 2,302 ms
87,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 2*10**5
mod = 998244353
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def fwt(n,A):
    assert len(A) == 2**n
    for i in range(n):
        t = 2**i
        for j in range(2**n):
            if j&t==0:
                A[j] += A[j|t]
    return A

def ifwt(n,A):
    assert len(A) == 2**n
    for i in range(n):
        t = 2**i
        for j in range(2**n):
            if j&t==0:
                A[j] -= A[j|t]
    return A

inv = pow(1024,mod-2,mod)
 
def _fourier(f, inverse = False):
    f = f[:]
    n = (len(f) - 1).bit_length()
    for d in range(n):
        for U in range(1 << n):
            if not U >> d & 1:
                s, t = f[U], f[U | 1 << d]
                f[U], f[U | 1 << d] = (s + t)%mod, (s - t)%mod
    if inverse:
        f = [v *inv % mod for v in f]
    return f
 
def convolution(f, g):
    return _fourier([a * b  % mod for a, b in zip(_fourier(f), _fourier(g))], inverse = 1)

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
A = li()
S = sum(A)

P = [A[i]*pow(S,mod-2,mod)%mod for i in range(N+1)] + [0] * (1023-N)
res = P[0]
for i in range(1,1024):
    f = [0] + [P[j] for j in range(1,1024)]
    g = [f[j] for j in range(1024)]
    g[i] = 0

    af = _fourier(f)
    ag = _fourier(g)
    for j in range(1024):
        af[j] = af[j] * pow(1-af[j],mod-2,mod) % mod
        ag[j] = ag[j] * pow(1-ag[j],mod-2,mod) % mod
    tmp = _fourier([af[i]-ag[i] for i in range(1024)],True)
    #print(f,g)
    #print([f[i]*30 % mod for i in range(4)])
    res += P[0] * tmp[i] % mod
    res %= mod

f = [0] + [P[j] for j in range(1,1024)]
af = _fourier(f)
for j in range(1024):
    af[j] = af[j] * pow(1-af[j],mod-2,mod) % mod
    ag[j] = ag[j] * pow(1-ag[j],mod-2,mod) % mod
f = _fourier(af,True)
res += P[0] * f[0] % mod
res %= mod
print((1-res)%mod)

0