結果

問題 No.1084 積の積
ユーザー Plan8Plan8
提出日時 2020-08-17 11:50:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 2,863 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 202,376 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-19 18:45:25
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 94 ms
5,632 KB
testcase_05 AC 93 ms
5,504 KB
testcase_06 AC 93 ms
5,632 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 99 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 45 ms
5,376 KB
testcase_13 AC 96 ms
5,376 KB
testcase_14 AC 36 ms
5,376 KB
testcase_15 AC 35 ms
5,376 KB
testcase_16 AC 112 ms
5,632 KB
testcase_17 AC 43 ms
5,376 KB
testcase_18 AC 72 ms
5,376 KB
testcase_19 AC 101 ms
5,376 KB
testcase_20 AC 23 ms
5,376 KB
testcase_21 AC 37 ms
5,376 KB
testcase_22 AC 28 ms
5,376 KB
testcase_23 AC 58 ms
5,376 KB
testcase_24 AC 54 ms
5,376 KB
testcase_25 AC 95 ms
5,376 KB
testcase_26 AC 103 ms
5,760 KB
testcase_27 AC 107 ms
5,632 KB
testcase_28 AC 104 ms
5,632 KB
testcase_29 AC 106 ms
5,504 KB
testcase_30 AC 103 ms
5,504 KB
testcase_31 AC 104 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007;//998244353;

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

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        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;
        if(x < 0) 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(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        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;
    }
};

void Main(){
    ll N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    vector<mint> cum(N+1,1); REP(i,N) cum[i+1] = cum[i]*A[i];
    vector<mint> cum2(N+1,1); REP(i,N) cum2[i+1] = cum2[i]*cum[i+1];

    mint ans(1);
    int r = 1;
    REP(l,N){
        mint tmp = cum[r]/cum[l];
        while(r<N && (cum[r]/cum[l]).x*A[r]<1000000000) r++;
        ans *= cum2[r] / cum2[l] / cum[l].pow(r-l);
    }
    cout << ans.x << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}
0