結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー とりゐとりゐ
提出日時 2021-10-18 02:23:35
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,374 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,684 KB
実行使用メモリ 199,488 KB
最終ジャッジ日時 2023-10-18 00:38:29
合計ジャッジ時間 13,997 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,652 KB
testcase_01 AC 41 ms
55,620 KB
testcase_02 AC 41 ms
55,620 KB
testcase_03 AC 178 ms
78,348 KB
testcase_04 AC 151 ms
78,172 KB
testcase_05 AC 155 ms
78,280 KB
testcase_06 AC 144 ms
78,100 KB
testcase_07 AC 142 ms
78,096 KB
testcase_08 AC 150 ms
78,180 KB
testcase_09 AC 156 ms
78,160 KB
testcase_10 AC 137 ms
77,804 KB
testcase_11 AC 143 ms
77,900 KB
testcase_12 AC 133 ms
77,756 KB
testcase_13 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

p, g = 998244353, 3
invg = pow(g, p-2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
 
def fft(k, f):
    for l in range(k)[::-1]:
        d = 1 << l
        u = 1
        for i in range(d):
            for j in range(i, 1 << k, 2*d):
                f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
            u = u * W[l+1] % p
 
def ifft(k, f):
    for l in range(k):
        d = 1 << l
        u = 1
        for i in range(d):
            for j in range(i, 1 << k, 2*d):
                f[j+d] *= u
                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
            u = u * iW[l+1] % p
 
def convolve(a, b):
    n0, n1 = len(a), len(b)
    k = (max(n0, n1) - 1).bit_length() + 1
    n = 1 << k
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    return [a[i] * invn % p for i in range(n0 + n1 - 1)]

from collections import deque
def conv_all(l):
    # 分割統治
    q = deque(l)
    while len(q)>=2:
        a = q.popleft()
        b = q.popleft()
        q.append(convolve(a,b))
    return q[0]

n,q=map(int,input().split())
a=list(map(int,input().split()))
FFT=conv_all([[(i-1)%p,1] for i in a])
for i in list(map(int,input().split())):
  print(FFT[i])
0