結果

問題 No.1681 +-*
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-09-17 23:01:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 439 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 107,616 KB
最終ジャッジ日時 2023-09-12 09:05:25
合計ジャッジ時間 5,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,276 KB
testcase_01 AC 71 ms
71,272 KB
testcase_02 AC 73 ms
71,508 KB
testcase_03 AC 73 ms
71,408 KB
testcase_04 AC 74 ms
71,432 KB
testcase_05 AC 285 ms
107,616 KB
testcase_06 AC 283 ms
107,448 KB
testcase_07 AC 284 ms
107,596 KB
testcase_08 AC 296 ms
101,732 KB
testcase_09 AC 296 ms
102,004 KB
testcase_10 AC 297 ms
101,864 KB
testcase_11 AC 296 ms
101,928 KB
testcase_12 AC 298 ms
102,008 KB
testcase_13 AC 181 ms
92,696 KB
testcase_14 AC 300 ms
101,896 KB
testcase_15 AC 71 ms
71,576 KB
testcase_16 AC 71 ms
71,528 KB
testcase_17 AC 298 ms
101,868 KB
testcase_18 AC 298 ms
101,876 KB
testcase_19 AC 300 ms
101,840 KB
権限があれば一括ダウンロードができます

ソースコード

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