結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 43 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 87 ms
4,380 KB
testcase_14 AC 33 ms
4,380 KB
testcase_15 AC 30 ms
4,376 KB
testcase_16 AC 99 ms
4,376 KB
testcase_17 AC 39 ms
4,380 KB
testcase_18 AC 65 ms
4,380 KB
testcase_19 AC 87 ms
4,376 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 33 ms
4,376 KB
testcase_22 AC 25 ms
4,376 KB
testcase_23 AC 53 ms
4,376 KB
testcase_24 AC 48 ms
4,376 KB
testcase_25 AC 87 ms
4,380 KB
testcase_26 AC 91 ms
4,380 KB
testcase_27 AC 92 ms
4,376 KB
testcase_28 AC 92 ms
4,376 KB
testcase_29 AC 92 ms
4,380 KB
testcase_30 AC 91 ms
4,376 KB
testcase_31 AC 92 ms
4,380 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;
int A[100000];
vector<int> 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){
            calc();
            v.clear();
        }
    }
    calc();
    cout << ans << endl;
}
0