結果

問題 No.1084 積の積
ユーザー ShibuyapShibuyap
提出日時 2020-06-19 22:02:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,088 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 202,464 KB
実行使用メモリ 5,696 KB
最終ジャッジ日時 2023-09-16 14:16:38
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 34 ms
5,532 KB
testcase_05 RE -
testcase_06 AC 35 ms
5,696 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 37 ms
5,100 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 42 ms
5,276 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 28 ms
4,644 KB
testcase_19 AC 38 ms
5,096 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 AC 12 ms
4,380 KB
testcase_23 AC 23 ms
4,380 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 37 ms
5,288 KB
testcase_26 AC 26 ms
5,472 KB
testcase_27 AC 26 ms
5,336 KB
testcase_28 AC 26 ms
5,296 KB
testcase_29 AC 26 ms
5,420 KB
testcase_30 AC 26 ms
5,340 KB
testcase_31 AC 26 ms
5,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

// ax + by = gcd(a, b) となるような (x, y) を求める
// a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰
    y -= a / b * x;
    return d;
}

// 負の数に対応した mod
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // x % m だが、x が負かもしれないので
}

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    int n;
    cin >> n;
    ll a[n];
    int zero = 0;
    rep(i,n){
        cin >> a[i];
        if(a[i] == 0)zero = 1;
    }
    if(zero){
        cout << 0 << endl;
    }

    int r[n] = {};
    int now = 1;
    ll mul = a[0];
    ll ten = 1000000000;
    ll MOD = 1e9+7;
    rep(i,n){
        while(now < n && mul * a[now] < ten){
            mul *= a[now];
            now++;
        }
        r[i] = now;
        mul /= a[i];
    }

    ll cnt[n] = {};
    ll sum = 0;
    priority_queue<int,vector<int>,greater<int>> que;
    rep(i,n){
        while(!que.empty() && que.top() <= i){
            que.pop();
        }
        sum += r[i] - i;
        que.push(r[i]);
        cnt[i] = sum;
        sum -= que.size();
    }

    ll ans = 1;
    rep(i,n){
        ans = ans * mod_pow(a[i], cnt[i], MOD) % MOD;
    }

    cout << ans << endl;
    return 0;
}
 
 
0