結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー vwxyzvwxyz
提出日時 2021-10-06 19:21:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,170 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 163,064 KB
最終ジャッジ日時 2023-09-30 08:49:41
合計ジャッジ時間 10,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,640 KB
testcase_01 AC 78 ms
71,512 KB
testcase_02 AC 79 ms
71,308 KB
testcase_03 AC 440 ms
86,380 KB
testcase_04 AC 390 ms
82,684 KB
testcase_05 AC 454 ms
86,868 KB
testcase_06 AC 367 ms
83,676 KB
testcase_07 AC 349 ms
82,976 KB
testcase_08 AC 405 ms
82,596 KB
testcase_09 AC 428 ms
84,736 KB
testcase_10 AC 295 ms
82,012 KB
testcase_11 AC 335 ms
82,384 KB
testcase_12 AC 253 ms
79,976 KB
testcase_13 TLE -
testcase_14 -- -
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 #

import heapq
import sys
readline=sys.stdin.readline

mod=998244353
def NTT(polynomial0,polynomial1):
    if mod==998244353:
        prim_root=3
        prim_root_inve=332748118
    else:
        prim_root=Primitive_Root(mod)
        prim_root_inve=MOD(mod).Pow(prim_root,-1)
    def DFT(polynomial,n,inverse=False):
        if inverse:
            for bit in range(1,n+1):
                a=1<<bit-1
                x=pow(prim_root,mod-1>>bit,mod)
                U=[1]
                for _ in range(a):
                    U.append(U[-1]*x%mod)
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t]*U[j])%mod,(polynomial[s]-polynomial[t]*U[j])%mod
            x=pow((mod+1)//2,n,mod)
            for i in range(1<<n):
                polynomial[i]*=x
                polynomial[i]%=mod
        else:
            for bit in range(n,0,-1):
                a=1<<bit-1
                x=pow(prim_root_inve,mod-1>>bit,mod)
                U=[1]
                for _ in range(a):
                    U.append(U[-1]*x%mod)
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t])%mod,U[j]*(polynomial[s]-polynomial[t])%mod

    l=len(polynomial0)+len(polynomial1)-1
    n=(len(polynomial0)+len(polynomial1)-2).bit_length()
    polynomial0=polynomial0+[0]*((1<<n)-len(polynomial0))
    polynomial1=polynomial1+[0]*((1<<n)-len(polynomial1))
    DFT(polynomial0,n)
    DFT(polynomial1,n)
    ntt=[x*y%mod for x,y in zip(polynomial0,polynomial1)]
    DFT(ntt,n,inverse=True)
    ntt=ntt[:l]
    return ntt

N,Q=map(int,readline().split())
hq=[]
A=list(map(int,readline().split()))
for a in A:
    hq.append((2,[a-1,1]))
heapq.heapify(hq)
while len(hq)>=2:
    _,P0=heapq.heappop(hq)
    _,P1=heapq.heappop(hq)
    P=NTT(P0,P1)
    heapq.heappush(hq,(len(P),P))
_,P=hq[0]
for b in map(int,readline().split()):
    ans=P[b]
    print(ans)
0