結果
| 問題 | No.754 畳み込みの和 | 
| コンテスト | |
| ユーザー |  convexineq | 
| 提出日時 | 2020-11-21 03:16:34 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 158 ms / 5,000 ms | 
| コード長 | 754 bytes | 
| コンパイル時間 | 214 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 18,560 KB | 
| 最終ジャッジ日時 | 2024-07-23 14:22:00 | 
| 合計ジャッジ時間 | 1,717 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 | 
ソースコード
"""
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))
            
            
            
        