結果

問題 No.1681 +-*
ユーザー HaaHaa
提出日時 2021-09-17 21:52:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 167,620 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-12 07:21:33
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 62 ms
4,680 KB
testcase_06 AC 62 ms
4,580 KB
testcase_07 AC 61 ms
4,740 KB
testcase_08 AC 98 ms
4,760 KB
testcase_09 AC 97 ms
4,656 KB
testcase_10 AC 98 ms
4,628 KB
testcase_11 AC 97 ms
4,580 KB
testcase_12 AC 98 ms
4,636 KB
testcase_13 AC 49 ms
4,380 KB
testcase_14 AC 97 ms
4,888 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 98 ms
4,696 KB
testcase_18 AC 97 ms
4,620 KB
testcase_19 AC 98 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    ll ans=0, x=1;
    REP(i,n){
        x=x*a[i]%MOD;
        if(i==n-1)
            ans=(ans+x)%MOD;
        else
            ans=(ans+x*power(3,n-i-2)*2%MOD)%MOD;
    }
    cout << ans << endl;
}
0