結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー maspymaspy
提出日時 2020-05-29 21:42:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,063 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,448 KB
最終ジャッジ日時 2024-04-23 20:54:04
合計ジャッジ時間 21,419 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 521 ms
44,192 KB
testcase_01 AC 517 ms
44,448 KB
testcase_02 AC 479 ms
44,192 KB
testcase_03 AC 483 ms
44,320 KB
testcase_04 AC 513 ms
44,060 KB
testcase_05 AC 522 ms
44,056 KB
testcase_06 AC 521 ms
44,036 KB
testcase_07 AC 524 ms
43,932 KB
testcase_08 AC 794 ms
43,944 KB
testcase_09 AC 510 ms
44,316 KB
testcase_10 AC 1,049 ms
43,944 KB
testcase_11 AC 780 ms
43,796 KB
testcase_12 AC 745 ms
44,060 KB
testcase_13 AC 766 ms
43,944 KB
testcase_14 AC 766 ms
44,432 KB
testcase_15 AC 956 ms
43,936 KB
testcase_16 AC 691 ms
43,944 KB
testcase_17 AC 664 ms
44,444 KB
testcase_18 AC 902 ms
44,328 KB
testcase_19 AC 737 ms
44,316 KB
testcase_20 AC 511 ms
44,184 KB
testcase_21 AC 840 ms
44,188 KB
testcase_22 AC 515 ms
44,060 KB
testcase_23 AC 501 ms
43,672 KB
testcase_24 AC 536 ms
44,192 KB
testcase_25 AC 1,063 ms
43,808 KB
testcase_26 AC 1,005 ms
44,316 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 = len(f)
    Lg = len(g)
    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

def convolve_all(polys):
    while len(polys) >= 2:
        N = len(polys)
        for i in range(1, N, 2):
            polys[i-1] = fft_convolve(polys[i-1], polys[i])
        polys = polys[::2]
    return polys[0]

N, Q = map(int, readline().split())
A = map(int, readline().split())
polys = [None] * N
for i, x in enumerate(A):
    x %= MOD
    polys[i] = np.array([x-1, 1], np.int64)

P = convolve_all(polys)

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