結果

問題 No.1681 +-*
ユーザー NanashimaNanashima
提出日時 2021-09-17 22:43:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 168,872 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-09-12 08:44:09
合計ジャッジ時間 3,740 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 106 ms
5,104 KB
testcase_09 AC 106 ms
5,040 KB
testcase_10 AC 106 ms
5,104 KB
testcase_11 AC 106 ms
5,052 KB
testcase_12 AC 106 ms
5,200 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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