結果

問題 No.1681 +-*
ユーザー mtrhmtrh
提出日時 2021-09-18 18:01:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 166,504 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-09-13 05:30:24
合計ジャッジ時間 4,046 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 62 ms
4,544 KB
testcase_06 AC 64 ms
4,708 KB
testcase_07 AC 63 ms
4,688 KB
testcase_08 AC 98 ms
4,640 KB
testcase_09 AC 98 ms
4,716 KB
testcase_10 AC 98 ms
4,704 KB
testcase_11 AC 99 ms
4,740 KB
testcase_12 AC 99 ms
4,620 KB
testcase_13 AC 50 ms
4,376 KB
testcase_14 AC 98 ms
4,568 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 98 ms
4,612 KB
testcase_18 AC 99 ms
4,612 KB
testcase_19 AC 98 ms
4,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

ll modpow(ll x,ll n,ll mod){
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        n>>=1;
    }
    return res%mod;
}

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    ll mod=1e9+7;
    ll ans=0;
    ll temp=1;
    for(int i=0;i<N;i++){
        ll x=temp*A[i];
        x%=mod;
        x*=modpow(3,N-i-2,mod);
        x%=mod;
        if(i<N-1) x*=2;
        x%=mod;
        ans+=x;
        ans%=mod;
        temp*=A[i];
        temp%=mod;
    }
    ans=(10*mod+ans)%mod;
    cout<<ans<<endl;
    return 0;
}
0