結果
| 問題 | No.1084 積の積 | 
| コンテスト | |
| ユーザー |  kriii | 
| 提出日時 | 2020-06-19 21:46:07 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 36 ms / 2,000 ms | 
| コード長 | 901 bytes | 
| コンパイル時間 | 902 ms | 
| コンパイル使用メモリ | 57,784 KB | 
| 最終ジャッジ日時 | 2025-01-11 06:01:58 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf ("%d", &N);
      |         ~~~~~~^~~~~~~~~~
main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |                 long long x; scanf ("%lld", &x);
      |                              ~~~~~~^~~~~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        