結果

問題 No.1618 Convolution?
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-14 15:27:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 151,924 KB
最終ジャッジ日時 2023-10-18 11:44:28
合計ジャッジ時間 27,476 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Any, List
import numpy as np


def convolution(a: Any, b: Any) -> "np.ndarray":
    """fft求卷积(可能精度不够)"""
    n = len(a) + len(b) - 1
    n = 1 << ((n - 1).bit_length())
    c = np.fft.irfft((np.fft.rfft(a, n)) * (np.fft.rfft(b, n)), n)
    c = np.rint(c).astype(np.int64)
    return c


def convolution_fft_large(a: Any, b: Any) -> List[int]:
    """精度不够用这个"""
    a, b = np.array(a, dtype=np.int64), np.array(b, dtype=np.int64)
    d = 1 << 10
    a1, a2 = np.divmod(a, d * d)
    a2, a3 = np.divmod(a2, d)
    b1, b2 = np.divmod(b, d * d)
    b2, b3 = np.divmod(b2, d)
    aa = convolution(a1, b1)
    bb = convolution(a2, b2)
    cc = convolution(a3, b3)
    dd = convolution(a1 + a2, b1 + b2) - (aa + bb)  # type: ignore
    ee = convolution(a2 + a3, b2 + b3) - (bb + cc)  # type: ignore
    ff = convolution(a1 + a3, b1 + b3) - (aa + cc)  # type: ignore
    h = ((aa * d * d)) * d * d + ((dd * d * d)) * d + (bb + ff) * d * d + ee * d + cc
    return h.tolist()


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_fft_large(A, f)
B = convolution_fft_large(B, f)
C = [a + b for a, b in zip(A, B)]
C = C[1:]
print(*C)
0