結果

問題 No.1084 積の積
ユーザー hirokazu1020hirokazu1020
提出日時 2020-06-19 22:07:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,495 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 93,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 14:28:34
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 18 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 18 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

#define MOD 1000000007

long long extgcd(int a, int b, int& x, int& y) {
	int gcd_ = a;
	if (b) {
		gcd_ = extgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	else {
		x = 1; y = 0;
	}
	return gcd_;
}
//逆元を計算 O(log MOD)
int inv_mod(int a) {
	int x, y;
	extgcd(a, MOD, x, y);
	return (MOD + x % MOD) % MOD;
}

long long pow_mod(long long x, long long y) {
	int res = 1;
	while (y) {
		if (y & 1)res = (res * x) % MOD;
		y >>= 1;
		x = (x * x) % MOD;
	}
	return res;
}

int n;
int a[100000];


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	rep(i, n)cin >> a[i];
	long long ans = 1;

	long long s = 1, sm = 1;
	int e = 0;
	rep(i, n) {
		if (a[i] == 0) {
			s = sm = 1;
			continue;
		}
		while (e < n && a[e] != 0 && s * a[e] < 1000000000) {
			s *= a[e];
			sm *= s;
			sm %= MOD;
			e++;
		}
		ans *= sm;
		ans %= MOD;
		s /= a[i];
		sm = sm * pow_mod(inv_mod(a[i]), e - i) % MOD;
	}

	cout << ans << endl;


	
	return 0;
}
0