結果

問題 No.1681 +-*
ユーザー dongdongdong111
提出日時 2025-05-01 10:22:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 2,531 ms
コンパイル使用メモリ 193,408 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-01 10:22:29
合計ジャッジ時間 4,990 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0), cout.tie(0);
#define debug(a) cout << "=======" << a << "========" << endl;
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<ll, ll> PII;
typedef pair<ll, array<ll, 2>> PIA;
const int N = 1e6 + 10, mod = 1e9+7;
int n, m, k;
ll f[N];
ll a[N];
ll pow(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        a = a % mod;
        if (b & 1)
            res = res * a % mod;
        b = b >> 1;
        a = a * a % mod;
    }
    return res;
}
ll pow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        b = b >> 1;
        a = a * a;
    }
    return res;
}
void solve()
{
    cin >> n;
    ll ans=0;
    ll now=1;
    for(int i=1;i<=n;i++){
        cin >> f[i];
        now*=f[i];
        now%=mod;
        if(i!=n)ans=(ans+(2*now%mod*pow(3,n-i-1,mod)%mod)%mod);
        else ans+=now;
        ans%=mod;
    }
    cout<<ans<<'\n';
    
}
int main()
{
    IOS;
    int _ = 1;
    // cin >> _;
    while (_--){
        solve();

    }

    return 0;
}
0