結果

問題 No.1084 積の積
ユーザー milanis48663220milanis48663220
提出日時 2020-06-19 22:49:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,366 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 86,012 KB
実行使用メモリ 4,840 KB
最終ジャッジ日時 2023-09-16 15:03:47
合計ジャッジ時間 3,418 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 39 ms
4,836 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 14 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 40 ms
4,376 KB
testcase_13 AC 83 ms
4,644 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 94 ms
4,760 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 63 ms
4,380 KB
testcase_19 AC 82 ms
4,676 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 31 ms
4,376 KB
testcase_22 AC 23 ms
4,380 KB
testcase_23 AC 49 ms
4,376 KB
testcase_24 AC 44 ms
4,380 KB
testcase_25 AC 80 ms
4,804 KB
testcase_26 AC 84 ms
4,820 KB
testcase_27 AC 87 ms
4,840 KB
testcase_28 AC 83 ms
4,836 KB
testcase_29 AC 86 ms
4,732 KB
testcase_30 AC 88 ms
4,812 KB
testcase_31 AC 87 ms
4,812 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;
    ll t = 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