結果

問題 No.1681 +-*
ユーザー aaaaaaaaaa2230
提出日時 2021-09-17 23:01:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 439 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 106,476 KB
最終ジャッジ日時 2024-06-29 21:49:52
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
three = 1
dp = [A[0],0]
ans = 0
for i,a in enumerate(A[1:],1):
    ndp = [0,0]
    ans += dp[0]*pow(3,n-1-i,mod)*2%mod
    ans -= dp[1]*pow(3,n-1-i,mod)*2%mod
    ans %= mod
    ndp[0] += dp[0]*a
    ndp[0] += three*a
    ndp[0] %= mod
    ndp[1] += dp[1]*a
    ndp[1] += three*a
    ndp[1] %= mod
    dp = ndp
    three *= 3
    three %= mod

print((ans+dp[0]-dp[1])%mod)
0