結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー maspymaspy
提出日時 2020-05-31 02:06:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,364 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 61,460 KB
最終ジャッジ日時 2023-08-09 02:40:31
合計ジャッジ時間 13,114 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,928 KB
testcase_01 AC 128 ms
29,780 KB
testcase_02 AC 129 ms
29,892 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 131 ms
29,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998244353

def fft_convolve(f, g, MOD=MOD):
    """
    数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで,
    30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える.
    """
    fft = np.fft.rfft
    ifft = np.fft.irfft
    Lf = f.shape[-1]
    Lg = g.shape[-1]
    L = Lf + Lg - 1
    fft_len = 1 << L.bit_length()
    fl = f & (1 << 15) - 1
    fh = f >> 15
    gl = g & (1 << 15) - 1
    gh = g >> 15

    def conv(f, g):
        return ifft(fft(f, fft_len) * fft(g, fft_len))[:L]

    x = conv(fl, gl) % MOD
    y = conv(fl + fh, gl + gh) % MOD
    z = conv(fh, gh) % MOD
    a, b, c = map(lambda x: (x + .5).astype(np.int64), [x, y, z])
    return (a + ((b - a - c) << 15) + (c << 30)) % MOD

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)

A %= MOD
polys = np.empty((N, 2), np.int64)
polys[:, 1] = 1
polys[:, 0] = A - 1

while len(polys) > 1:
    if len(polys) & 1:
        polys = np.pad(polys, ((0, 1), (0, 0)))
        polys[-1, 0] = 1
    P = polys[:len(polys)//2]
    Q = polys[len(polys)//2:]
    polys = fft_convolve(P, Q)

P = polys[0]

for q in map(int, read().split()):
    print(P[q])
0