結果

問題 No.1681 +-*
ユーザー NanashimaNanashima
提出日時 2021-09-17 22:53:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 167,432 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-09-12 08:56:11
合計ジャッジ時間 4,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 70 ms
4,684 KB
testcase_06 AC 71 ms
4,600 KB
testcase_07 AC 70 ms
4,548 KB
testcase_08 AC 106 ms
4,588 KB
testcase_09 AC 105 ms
4,744 KB
testcase_10 AC 105 ms
4,732 KB
testcase_11 AC 106 ms
4,552 KB
testcase_12 AC 106 ms
4,664 KB
testcase_13 AC 54 ms
4,376 KB
testcase_14 AC 105 ms
4,600 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 106 ms
4,544 KB
testcase_18 AC 105 ms
4,588 KB
testcase_19 AC 106 ms
4,596 KB
権限があれば一括ダウンロードができます

ソースコード

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(n);
    ll tot=1;
    rep(i,n) {
        cin >> a[i];
        if(a[i]==0) continue;
        tot*=a[i];
        tot%=mod;
    }
    reverse(all(a));
    ll ans=tot,num=2;
    if(a[0]!=0) {
        tot*=modpow(a[0],mod-2);
        tot%=mod;
    } else ans=0;
    for(int i=1;i<n;i++) {
        ans=(ans+(tot*num)%mod)%mod;
        if(a[i]!=0) {
            tot*=modpow(a[i],mod-2);
            tot%=mod;
        } else ans=0;
        num*=3;
        num%=mod;
    }
    cout << ans << endl;
    return 0;
}
0