結果

問題 No.1084 積の積
ユーザー otoshigootoshigo
提出日時 2023-02-20 20:21:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 76,360 KB
実行使用メモリ 5,132 KB
最終ジャッジ日時 2023-09-28 16:19:35
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 40 ms
4,844 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 40 ms
4,936 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 36 ms
5,132 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 41 ms
4,900 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 27 ms
4,376 KB
testcase_19 AC 36 ms
4,948 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 22 ms
4,376 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 36 ms
4,572 KB
testcase_26 AC 38 ms
4,840 KB
testcase_27 AC 38 ms
4,948 KB
testcase_28 AC 37 ms
4,848 KB
testcase_29 AC 37 ms
4,888 KB
testcase_30 AC 37 ms
4,888 KB
testcase_31 AC 37 ms
4,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll MOD=1e9+7,MAX=1e9-1;

ll power(ll x,ll r){
    ll re=1,k=x;
    for(int i=0;i<60;i++){
        if(r>>i&1){
            re=(re*k)%MOD;
        }
        k=k*k%MOD;
    }
    return re;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin>>N;
    vector<ll>A(N);
    rep(i,N)cin>>A[i];
    rep(i,N){
        if(A[i]==0){
            cout<<0<<"\n";
            return 0;
        }
    }
    vector<int>L(N);
    L[0]=0;
    ll pr=1;
    rep(i,N){
        if(i>0)L[i]=min(N,L[i-1]);
        while(L[i]<N&&pr*A[L[i]]<=MAX){
            pr*=A[L[i]];
            L[i]++;
        }
        pr/=A[i];
    }
    vector<ll>S(N+1);
    rep(i,N){
        S[i]--;
        S[L[i]]++;
    }
    rrep(i,N)S[i]+=S[i+1];
    rep(i,N)S[i]-=L[i]-i;
    rrep(i,N)S[i]+=S[i+1];
    ll ans=1;
    rep(i,N)ans=ans*power(A[i],S[i+1])%MOD;
    cout<<ans<<"\n";
}
0