結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-12-05 20:53:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,327 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 37,012 KB
最終ジャッジ日時 2023-09-21 15:01:38
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
37,012 KB
testcase_01 AC 135 ms
29,824 KB
testcase_02 AC 135 ms
29,828 KB
testcase_03 AC 137 ms
29,856 KB
testcase_04 AC 133 ms
29,956 KB
testcase_05 AC 137 ms
29,888 KB
testcase_06 AC 133 ms
29,848 KB
testcase_07 AC 129 ms
29,848 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

def convolve(f, g):
    tf = np.array(f, np.int64)
    tg = np.array(g, np.int64) 
    fft_len = 1
    while 2 * fft_len < len(tf) + len(tg) - 1:
        fft_len *= 2
    
    fft_len *= 2

    # フーリエ変換
    Ff = np.fft.rfft(tf, fft_len)
    Fg = np.fft.rfft(tg, fft_len)

    # 各点積
    Fh = Ff * Fg

    # フーリエ逆変換
    h = np.fft.irfft(Fh, fft_len)

    # 小数になっているので、整数にまるめる
    h = np.rint(h).astype(np.int64)

    return h[:len(f) + len(g) - 1]

def convolve2(f,g,p):
    
    
    f1,f2 = np.divmod(f,1<<15)
    g1,g2 = np.divmod(g,1<<15)
    
    a = convolve(f1,g1)%p
    c = convolve(f2,g2)%p
    b = (convolve(f1+f2,g1+g2) - a - c)%p
    h = (a<<30) + (b<<15) + c
    return h%p
    
def convolve_pow(f,n,p):
    nbit = list(str(bin(n))[2:])
    nbit = [int(i) for i in nbit]
    N = len(f)
    C = [1] + [0]*(N-1)
    
    B = f

        
    for i in range(len(nbit)):
        if nbit[-1-i] == 1:
            C = convolve2(C,B,p)
        
        B = convolve2(B,B,p)
    
    return C
    
N,Q = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
p = 998244353
res = [1] + [0]*N
for i in range(N):
    res = convolve2(res,[A[i]-1,1],p)
for i in range(Q):
    b = B[i]
    print(res[b])
0