結果

問題 No.1084 積の積
ユーザー auaua
提出日時 2020-06-19 22:36:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 169,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 15:09:25
合計ジャッジ時間 3,036 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%inf;
        x=x*x%inf;
        b/=2;
    }
    return res;
}
signed main(){
    ll n;cin>>n;
    vector<ll>a(n+1);
    a[n]=1;
    bool f=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]==0)f=1;
    }
    if(f){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    vector<ll>imos(n+2);
    vector<ll>imo(n+2);
    ll j=0;
    ll now=1;
    rep(i,n){
        if(j==n){
            imos[i]+=j-i;
            imo[i+1]--;
            imo[j+1]++;
        }else{
            while(j<n&&a[j]*now<1000000000LL){
                now*=a[j];
                j++;
            }

                imos[i]+=j-i;
                imo[i+1]--;
                imo[j+1]++;
        }
        now/=a[i];
    }
    REP(i,1,n+2){
        imo[i]+=imo[i-1];
        //cout<<imo[i]<<endl;
    }
    REP(i,1,n+1){
        imos[i]+=imos[i-1]+imo[i];
    }
    rep(i,n){
        //cout<<imos[i]<<endl;
    }
    rep(i,n){
        ans=(ans*rui(a[i],imos[i])%inf)%inf;
    }
    cout<<ans<<endl;
}
0