結果

問題 No.1681 +-*
ユーザー ygd.ygd.
提出日時 2021-09-23 14:26:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 105,120 KB
最終ジャッジ日時 2023-09-18 19:52:32
合計ジャッジ時間 4,212 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,104 KB
testcase_01 AC 73 ms
71,156 KB
testcase_02 AC 74 ms
71,292 KB
testcase_03 AC 74 ms
71,124 KB
testcase_04 AC 75 ms
71,248 KB
testcase_05 AC 122 ms
103,856 KB
testcase_06 AC 119 ms
103,900 KB
testcase_07 AC 120 ms
103,900 KB
testcase_08 AC 124 ms
105,052 KB
testcase_09 AC 123 ms
105,120 KB
testcase_10 AC 124 ms
105,012 KB
testcase_11 AC 125 ms
105,072 KB
testcase_12 AC 124 ms
105,096 KB
testcase_13 AC 101 ms
89,148 KB
testcase_14 AC 124 ms
105,072 KB
testcase_15 AC 74 ms
71,464 KB
testcase_16 AC 74 ms
71,204 KB
testcase_17 AC 124 ms
105,052 KB
testcase_18 AC 124 ms
105,012 KB
testcase_19 AC 122 ms
104,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input()); MOD = pow(10,9) + 7
    A = list(map(int,input().split()))
    fac = 2*pow(3,N-2,MOD)
    inv3 = pow(3,MOD-2,MOD)
    ans = 0
    a = 1
    for i in range(N-1):
        a = a*A[i]%MOD
        #print(a,fac)
        ans += a*fac
        ans %= MOD
        #facの更新
        fac = fac*inv3%MOD
    #最後はfac無し
    ans += a*A[N-1]%MOD
    print(ans%MOD)

if __name__ == '__main__':
    main()
0