結果

問題 No.1618 Convolution?
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-14 15:20:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,682 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 170,044 KB
最終ジャッジ日時 2023-10-18 11:43:15
合計ジャッジ時間 28,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 473 ms
42,412 KB
testcase_01 AC 472 ms
42,620 KB
testcase_02 AC 1,516 ms
116,300 KB
testcase_03 AC 1,551 ms
132,904 KB
testcase_04 AC 1,123 ms
101,640 KB
testcase_05 AC 525 ms
44,568 KB
testcase_06 AC 1,501 ms
128,072 KB
testcase_07 AC 1,498 ms
126,320 KB
testcase_08 AC 1,092 ms
102,796 KB
testcase_09 AC 1,606 ms
138,856 KB
testcase_10 AC 1,451 ms
116,304 KB
testcase_11 AC 1,582 ms
136,212 KB
testcase_12 AC 1,679 ms
140,456 KB
testcase_13 AC 1,682 ms
139,620 KB
testcase_14 AC 1,618 ms
139,492 KB
testcase_15 AC 1,632 ms
140,284 KB
testcase_16 AC 1,612 ms
170,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


from typing import Any, List
import numpy as np


import numpy as np


def convolution(nums1: Any, nums2: Any) -> "np.ndarray":
    """fft求卷积1(可能精度不够)"""
    n, m = len(nums1), len(nums2)
    ph = 1 << (n + m - 2).bit_length()
    T = np.fft.rfft(nums1, ph) * np.fft.rfft(nums2, ph)
    res = np.fft.irfft(T, ph)[: n + m - 1]
    return np.rint(res).astype(np.int64)


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)
    ee = convolution(a2 + a3, b2 + b3) - (bb + cc)
    ff = convolution(a1 + a3, b1 + b3) - (aa + cc)
    h = ((aa * d * d)) * d * d + ((dd * d * d)) * d + (bb + ff) * d * d + ee * d + cc
    return list(h)


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

MOD = int(1e18)
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