結果

問題 No.1681 +-*
ユーザー wtf yup
提出日時 2024-12-10 16:59:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,377 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 169,388 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-12-10 16:59:32
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif
#define pb push_back
#define ar array
#define ll long long
#define ld long double
#define printvec(vec) {for(ll i=0;i<vec.size();i++) cout<<vec[i]<<" "; cout<<endl;}
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define endl '\n'
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 1e-9;
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve() {
    int n;
    cin >> n;
    vector<int> v(n+1);
    vector<ll> prod(n+1);
    prod[0] = 1;
    for(int i=1;i<=n;i++){
        cin >> v[i];
        prod[i] = (v[i]*prod[i-1])%MOD;
    }
    ll ans = prod[n];
    for(int i=1;i<n;i++){
        (ans += ((2*binpow(3,n-1-i,MOD))%MOD)*prod[i])%=MOD;
    }
    cout << ans << endl;
}
void init_code(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
}
int main() {
    init_code();
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    cerr<<"Time: "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<" ms\n";
}
0