結果

問題 No.1681 +-*
ユーザー Nanashima
提出日時 2021-09-17 22:43:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 170,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-29 21:28:36
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

const ll mod=1000000007;

ll modpow(ll n,ll r) {
    ll num=1;
    while(r) {
        if(r&1) num=num*n%mod;
        n=n*n%mod;
        r/=2;
    }
    return num;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> a;
    ll tot=1;
    rep(i,n) {
        ll x;
        cin >> x;
        if(x==0) break;
        a.push_back(x);
        tot*=a[i];
        tot%=mod;
    }
    if((int)a.size()==0) {
        cout << 0 << endl;
        return 0;
    }
    reverse(all(a));
    ll ans=tot,num=2;
    tot*=modpow(a[0],mod-2);
    tot%=mod;
    for(int i=1;i<(int)a.size();i++) {
        ans=(ans+(tot*num)%mod)%mod;
        tot*=modpow(a[i],mod-2);
        tot%=mod;
        num*=3;
        num%=mod;
    }
    cout << ans << endl;
    return 0;
}
0