結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 39 ms
4,856 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 39 ms
4,384 KB
testcase_13 AC 81 ms
4,852 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 93 ms
4,840 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 60 ms
4,380 KB
testcase_19 AC 84 ms
4,864 KB
testcase_20 AC 20 ms
4,380 KB
testcase_21 AC 30 ms
4,376 KB
testcase_22 AC 24 ms
4,380 KB
testcase_23 AC 50 ms
4,380 KB
testcase_24 AC 45 ms
4,376 KB
testcase_25 AC 81 ms
4,704 KB
testcase_26 AC 87 ms
4,796 KB
testcase_27 AC 86 ms
4,856 KB
testcase_28 AC 86 ms
5,032 KB
testcase_29 AC 86 ms
4,808 KB
testcase_30 AC 87 ms
4,816 KB
testcase_31 AC 86 ms
4,800 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){
            calc();
            v.clear();
        }
    }
    calc();
    cout << ans << endl;
}
0