結果

問題 No.1084 積の積
ユーザー kriiikriii
提出日時 2020-06-19 21:46:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 59,688 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-09-16 13:48:28
合計ジャッジ時間 2,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 20 ms
4,696 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 20 ms
4,648 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 31 ms
4,380 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 27 ms
4,376 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 16 ms
4,380 KB
testcase_25 AC 28 ms
4,380 KB
testcase_26 AC 27 ms
4,380 KB
testcase_27 AC 27 ms
4,376 KB
testcase_28 AC 27 ms
4,380 KB
testcase_29 AC 28 ms
4,380 KB
testcase_30 AC 28 ms
4,376 KB
testcase_31 AC 28 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <deque>
using namespace std;

const long long mod = 1000000007;
const long long lim = 1000000000;

long long fpow(long long a, long long p)
{
	long long r = 1;
	while (p){
		if (p & 1) r = r * a % mod;
		a = a * a % mod;
		p /= 2;
	}
	return r;
}

long long inv(long long a)
{
	return fpow(a, mod - 2);
}

int N;
deque<pair<long long, long long> > Q;

int main()
{
	scanf ("%d", &N);

	long long ans = 1, mmul = 1, mul = 1;
	Q = { { 1, 1 } };

	for (int i = 0; i < N; i++){
		long long x; scanf ("%lld", &x);

		if (x == 0){
			ans = 0;
			break;
		}

		long long last = Q.back().second;
		mul *= x;
		while (mul >= lim){
			mul /= Q[1].first;
			mmul = mmul * Q.front().second % mod * inv(last) % mod;
			Q.pop_front();
		}
		mmul = mmul * fpow(x, Q.size()) % mod;
		Q.push_back({ x, last * x % mod });
		ans = (ans * mmul) % mod;
	}

	printf ("%lld\n", ans);
	return 0;
}
0