結果

問題 No.1084 積の積
ユーザー kriiikriii
提出日時 2020-06-19 21:42:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 59,564 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-09-16 13:46:22
合計ジャッジ時間 2,653 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 * x % mod;
		mul *= x;
		while (mul >= lim){
			mul /= Q.front().first;
			mmul = mmul * inv(Q.front().second % mod) % mod * last % mod;
			Q.pop_front();
		}
		mmul = mmul * fpow(x, Q.size()) % mod;
		Q.push_back({ x, last });
		ans = (ans * mmul) % mod;
	}

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