結果

問題 No.1857 Gacha Addiction
ユーザー chineristACchineristAC
提出日時 2022-02-25 22:07:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,328 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 270,896 KB
最終ジャッジ日時 2023-09-16 17:05:24
合計ジャッジ時間 24,398 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
82,724 KB
testcase_01 AC 120 ms
82,284 KB
testcase_02 AC 121 ms
82,700 KB
testcase_03 AC 121 ms
82,420 KB
testcase_04 AC 373 ms
90,032 KB
testcase_05 AC 364 ms
90,060 KB
testcase_06 AC 359 ms
90,156 KB
testcase_07 AC 368 ms
90,160 KB
testcase_08 AC 360 ms
90,280 KB
testcase_09 AC 2,671 ms
231,016 KB
testcase_10 AC 2,675 ms
230,208 KB
testcase_11 AC 2,669 ms
230,016 KB
testcase_12 AC 2,696 ms
230,304 KB
testcase_13 AC 2,695 ms
228,888 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
omega = pow(3,119,mod)
rev_omega = pow(omega,mod-2,mod)

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

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

def _ntt(f,L,reverse=False):
    F=[f[i] for i in range(L)]
    n = L.bit_length() - 1
    base = omega
    if reverse:
        base = rev_omega

    if not n:
        return F

    size = 2**n
    wj = pow(base,2**22,mod)
    res = [0]*2**n

    for i in range(n,0,-1):
        use_omega = pow(base,2**(22+i-n),mod)
        res = [0]*2**n
        size //= 2
        w = 1
        for j in range(0,L//2,size):
            for a in range(size):
                res[a+j] = (F[a+2*j] + w * F[a+size+2*j]) % mod
                t = (w * wj) % mod
                res[L//2+a+j] = (F[a+2*j] + t * F[a+size+2*j]) % mod
            w = (w * use_omega) % mod
        F = res

    return res

def ntt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L)
    return F

def intt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L,reverse=True)
    inv = pow(L,mod-2,mod)
    for i in range(L):
        F[i] *= inv
        F[i] %= mod
    return F

def convolve(_f,_g,limit=None):
    f = [v for v in _f]
    g = [v for v in _g]
    l = len(f)+len(g)-1
    L = 1<<((l-1).bit_length())

    F = ntt(f,L)
    G = ntt(g,L)

    H = [(F[i] * G[i]) % mod for i in range(L)]

    h = intt(H,L)
    if not limit:
        return h[:l]

    return h[:limit]






class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [[[1,0],[1,0]] for i in range(2*self.num)]
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
        

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

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

N,S = mi()
P = li()
for i in range(N):
    P[i] = P[i] * pow(S,mod-2,mod) % mod

init = [[[0,P[i]*P[i] % mod],[1,P[i]]] for i in range(N)]

def add(f,g):
    res = [0 for i in range(max(len(f),len(g)))]
    for i in range(len(f)):
        res[i] += f[i]
        res[i] %= mod
    for j in range(len(g)):
        res[j] += g[j]
        res[j] %= mod
    return res

def merge(x,y):
    return [add(convolve(x[0],y[1],len(x[0])+len(y[1])-1),convolve(x[1],y[0],len(x[1])+len(y[0])-1)),convolve(x[1],y[1],len(x[1])+len(y[1])-1)]

deq = deque(init)
while len(deq) > 1:
    a = deq.popleft()
    b = deq.popleft()
    c = merge(a,b)
    deq.append(c)


res = deq[0][0]
ans = 0
for k in range(1,N+1):
    ans += g1[k+1] * res[k]  % mod
    ans %= mod

print(ans)
0