結果

問題 No.754 畳み込みの和
ユーザー convexineqconvexineq
提出日時 2020-11-21 03:16:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 754 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 15,996 KB
最終ジャッジ日時 2023-09-30 20:33:09
合計ジャッジ時間 1,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
15,996 KB
testcase_01 AC 115 ms
15,856 KB
testcase_02 AC 116 ms
15,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
a,b の convolution の、n-1 次までの和を r^{i} の重み付きで求める
a,b は n 次以上
"""
def sum_of_convolution(a,b,n,r):
    assert len(a) >= n and len(b) >= n
    if r != 1:
        R = 1
        for i in range(n):
            a[i] = a[i]*R%MOD
            b[i] = b[i]*R%MOD
            R = R*r%MOD
    acc = res = 0
    for i in range(n):
        acc += a[i]
        acc %= MOD
        res += acc*b[n-1-i]
        res %= MOD
    return res
    
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,q = map(int,readline().split())
n = int(readline())+1
a = [int(readline()) for _ in range(n)]
b = [int(readline()) for _ in range(n)]
MOD = 10**9+7
print(sum_of_convolution(a,b,n,1))
0