結果

問題 No.1084 積の積
ユーザー milanis48663220milanis48663220
提出日時 2020-06-19 22:53:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 85,692 KB
実行使用メモリ 4,996 KB
最終ジャッジ日時 2023-09-16 15:05:53
合計ジャッジ時間 3,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 39 ms
4,764 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 39 ms
4,872 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 41 ms
4,376 KB
testcase_13 AC 84 ms
4,720 KB
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 96 ms
4,872 KB
testcase_17 AC 38 ms
4,376 KB
testcase_18 AC 63 ms
4,380 KB
testcase_19 AC 85 ms
4,640 KB
testcase_20 AC 20 ms
4,376 KB
testcase_21 AC 31 ms
4,376 KB
testcase_22 AC 24 ms
4,376 KB
testcase_23 AC 52 ms
4,376 KB
testcase_24 AC 46 ms
4,376 KB
testcase_25 AC 83 ms
4,808 KB
testcase_26 AC 88 ms
4,760 KB
testcase_27 AC 87 ms
4,996 KB
testcase_28 AC 88 ms
4,736 KB
testcase_29 AC 88 ms
4,880 KB
testcase_30 AC 87 ms
4,740 KB
testcase_31 AC 87 ms
4,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int N;
ll A[100000];
vector<ll> v;


ll inv(ll n){
    if(n == 1) return 1;
    else return MOD-inv(MOD%n)*(MOD/n)%MOD;
}

template <typename T>
T pow(T a, ll n) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}

ll ans = 1;
ll th = 1e9;
void calc(){
    ll tmp = 1;
    ll cur = 1;
    int sz = v.size();
    int r = 0;
    for(int l = 0; l < sz; l++){
        if(l > 0) {
            tmp /= v[l-1];
            cur *= inv(pow<ll>(v[l-1], r-l+1));
            cur %= MOD;
        }
        while(tmp*v[r] < th && r < sz){
            tmp*= v[r];
            cur *= tmp;
            cur %= MOD;
            r++;
        }
        ans *= cur;
        ans %= MOD;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++){
        if(A[i] != 0) v.push_back(A[i]);
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    calc();
    cout << ans << endl;
}
0