結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-03-22 22:52:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,038 ms / 3,500 ms
コード長 1,513 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 230,340 KB
最終ジャッジ日時 2024-04-18 23:43:42
合計ジャッジ時間 58,186 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,352 KB
testcase_01 AC 38 ms
52,992 KB
testcase_02 AC 40 ms
52,736 KB
testcase_03 AC 206 ms
78,896 KB
testcase_04 AC 192 ms
78,948 KB
testcase_05 AC 192 ms
79,296 KB
testcase_06 AC 182 ms
78,744 KB
testcase_07 AC 179 ms
78,940 KB
testcase_08 AC 186 ms
79,452 KB
testcase_09 AC 193 ms
79,112 KB
testcase_10 AC 154 ms
77,832 KB
testcase_11 AC 182 ms
78,896 KB
testcase_12 AC 148 ms
78,308 KB
testcase_13 AC 2,990 ms
229,928 KB
testcase_14 AC 2,972 ms
229,952 KB
testcase_15 AC 2,962 ms
229,976 KB
testcase_16 AC 2,956 ms
230,248 KB
testcase_17 AC 3,038 ms
229,840 KB
testcase_18 AC 2,890 ms
229,968 KB
testcase_19 AC 2,943 ms
229,836 KB
testcase_20 AC 2,889 ms
230,340 KB
testcase_21 AC 2,887 ms
229,952 KB
testcase_22 AC 2,899 ms
229,968 KB
testcase_23 AC 2,973 ms
230,228 KB
testcase_24 AC 2,941 ms
229,976 KB
testcase_25 AC 2,909 ms
229,972 KB
testcase_26 AC 2,943 ms
229,948 KB
testcase_27 AC 2,931 ms
229,844 KB
testcase_28 AC 2,934 ms
229,584 KB
testcase_29 AC 2,909 ms
222,744 KB
testcase_30 AC 2,883 ms
222,760 KB
testcase_31 AC 38 ms
53,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
g = 3
ginv = 332748118
W = [pow(g, (mod-1)>>i, mod) for i in range(24)]
Winv = [pow(ginv, (mod-1)>>i, mod) for i in range(24)]

def fft(k,f):
    for l in range(k,0,-1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1]*W[l]%mod)
        for i in range(1<<k - l):
            for j in range(d):
                s = i*2*d + j
                f[s],f[s+d] = (f[s]+f[s+d])%mod, U[j]*(f[s]-f[s+d])%mod

def fftinv(k,f):
    for l in range(1,k+1):
        d = 1 << l - 1
        for i in range(1<<k - l):
            u = 1
            for j in range(i*2*d, (i*2+1)*d):
                f[j+d] *= u
                f[j],f[j+d] = (f[j]+f[j+d])%mod, (f[j]-f[j+d])%mod
                u *= Winv[l] 
                u %= mod

def convolution(a,b):
    le = len(a)+len(b)-1
    k = le.bit_length()
    n = 1 << k
    a = a + [0]*(n-len(a))
    b = b + [0]*(n-len(b))
    fft(k,a)
    fft(k,b)
    for i in range(n):
        a[i] *= b[i]
        a[i] %= mod
    fftinv(k,a)
    
    ninv = pow(n,mod-2,mod)
    for i in range(le):
        a[i] *= ninv
        a[i] %= mod
    
    return a[:le]


n,q = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
calA = [[a-1,1] for a in A]
while len(calA) > 1:
    ncalA = []
    if len(calA) & 1:
        ncalA.append(calA.pop())
    for i in range(0,len(calA)//2):
        ncalA.append(convolution(calA[2*i],calA[2*i+1]))
    calA = ncalA
dp = calA[0]
for b in B:
    print(dp[b])
0