結果

問題 No.1084 積の積
ユーザー kyoprounokyoprouno
提出日時 2020-06-20 13:48:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,430 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 176,636 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-09-16 17:24:04
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 47 ms
4,620 KB
testcase_05 AC 3 ms
4,564 KB
testcase_06 AC 51 ms
4,736 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 22 ms
4,488 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 54 ms
4,380 KB
testcase_14 AC 20 ms
4,380 KB
testcase_15 AC 18 ms
4,380 KB
testcase_16 AC 62 ms
4,692 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 40 ms
4,376 KB
testcase_19 AC 56 ms
4,376 KB
testcase_20 AC 14 ms
4,376 KB
testcase_21 AC 21 ms
4,380 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 34 ms
4,376 KB
testcase_24 AC 30 ms
4,380 KB
testcase_25 AC 53 ms
4,380 KB
testcase_26 AC 45 ms
4,624 KB
testcase_27 AC 43 ms
4,564 KB
testcase_28 AC 45 ms
4,744 KB
testcase_29 AC 45 ms
4,732 KB
testcase_30 AC 45 ms
4,608 KB
testcase_31 AC 45 ms
4,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

struct mint {

  ll x; 

  mint(ll x=0):x((x%mod+mod)%mod){} //コンストラクタを呼んで自動的にmodを取っている。

  mint operator-() const { return mint(-x);}

  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    //メンバ関数にはthisポインタがある。メンバ変数の値を返す。
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }

  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }

  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }

  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1); //a=x/2
    a *= a; //繰り返し二乗法
    if (t&1) a *= *this; //tが奇数のときはxを1回かける
    return a;
  }



  // for prime mod

  mint inv() const {
    return pow(mod-2);
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
    
};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),x(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll le=0,ri=0;
    ll v=1;
    mint ans=1;
    mint rui=1;
    for(ll i=0;i<n;i++){
        le=i;
        if(ri<i){
            ri=i;
        }
        while(ri<=n-1 && v*a[ri]<1000000000){
            v*=a[ri];
            rui*=v;
            ri++;
        }
        ans*=rui;
        v/=a[le];
        mint dv=a[le];
        rui/=dv.pow(ri-le);
    }
    cout << ans.x << endl;
} 
0