結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー tktk_snsn
提出日時 2022-04-30 11:04:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,562 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 50,200 KB
最終ジャッジ日時 2024-06-29 16:47:22
合計ジャッジ時間 18,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
mod = 998244353


def convolve(A, B):
    n = len(A) + len(B) - 1
    fftlen = 1 << (n-1).bit_length()
    fa = np.fft.rfft(A, fftlen)
    fb = np.fft.rfft(B, fftlen)
    inv = (np.fft.irfft(fa * fb, fftlen) + 0.5).astype(np.int64)
    return inv[:n]


def mod_convolve_15(A, B):
    a1, a2 = np.divmod(A, 1 << 15)
    b1, b2 = np.divmod(B, 1 << 15)
    x = convolve(a1, b1) % mod
    y = convolve(a2, b2) % mod
    xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod
    res = (x << 30) + (xy << 15) + y
    return res % mod


def mod_convolve_10(A, B):
    a1, a2 = np.divmod(A, 1 << 20)
    a2, a3 = np.divmod(a2, 1 << 10)
    b1, b2 = np.divmod(B, 1 << 20)
    b2, b3 = np.divmod(b2, 1 << 10)
    x = convolve(a1, b1) % mod
    y = convolve(a2, b2) % mod
    z = convolve(a3, b3) % mod
    xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod
    yz = (convolve(a2 + a3, b2 + b3) - (y + z)) % mod
    zx = (convolve(a3 + a1, b3 + b1) - (z + x)) % mod
    res = ((((x << 20) % mod) << 20) +
           (((xy << 20) % mod) << 10) +
           ((y + zx) << 20) +
           (yz << 10) % mod + z) % mod
    return res


def main():
    N,  Q = map(int, input().split())
    A = list(map(int, input().split()))
    B = np.array(input().split(), dtype=np.intc)

    que = []
    for a in A:
        que.append(np.array([a-1, 1], dtype=np.int64))

    i = 0
    while i < len(que):
        if i + 1 == len(que):
            break
        que.append(mod_convolve_10(que[i], que[i+1]))
        i += 2

    F = que[-1]
    print(*F[B], sep="\n")


main()
0