結果

問題 No.1618 Convolution?
ユーザー 草苺奶昔
提出日時 2023-03-14 15:15:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 480 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 95,564 KB
最終ジャッジ日時 2024-09-18 08:05:22
合計ジャッジ時間 22,897 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def convolution(A, B):
    n, m = len(A), len(B)
    ph = 1 << (n + m - 2).bit_length()
    T = np.fft.rfft(A, ph) * np.fft.rfft(B, ph)
    res = np.fft.irfft(T, ph)[: n + m - 1]
    return np.rint(res).astype(np.int64)


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


A = [0] + A
B = [0] + B
f = list(range(n + 1))
A = convolution(A, f)
B = convolution(B, f)
C = [a + b for a, b in zip(A, B)]
C = C[1:]
print(*C)
0