結果

問題 No.1084 積の積
ユーザー albatross_35albatross_35
提出日時 2020-06-25 15:50:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 2,508 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 205,472 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-09-16 22:44:47
合計ジャッジ時間 4,143 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 109 ms
5,516 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 107 ms
5,648 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 18 ms
4,608 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 16 ms
4,380 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 17 ms
4,444 KB
testcase_26 AC 20 ms
4,568 KB
testcase_27 AC 19 ms
4,520 KB
testcase_28 AC 19 ms
4,616 KB
testcase_29 AC 20 ms
4,580 KB
testcase_30 AC 20 ms
4,524 KB
testcase_31 AC 19 ms
4,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,mod)%mod;
    ll p=pow(x,y/2,mod);
    return p*p%mod;
}

void solve(){
    int n;
    cin >> n;
    Vi a(n);
    bool z=false;
    rp(i,n) {
        cin >> a.at(i);
        if(a[i]==0) z=true;
    }
    if(z) {
        print(0);
        return;
    }
    ll pre=a[0];
    ll l=0,r=0;
    Vi num(n);
    while(l<n-1){
        if(pre>=1000000000||r==n){
            pre/=a[l];
            num[l]=r-l;
            l++;
        }else{
            r++;
            if(r!=n)
            pre*=a[r];
        }
    }
    num[n-1]=1;
    ll ans=1;
    ll ctr=0;
    ll sub=0;
    p_queue(ll) pos;
    rp(i,n){
        ctr-=sub;
        ctr+=num[i];
        while(pos.size()&&pos.top()==i){
            pos.pop();
            sub--;
        }
        sub++;
        pos.push(i+num[i]);
        ans*=pow(a[i],ctr,Mod);
        ans%=Mod;
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}
0