結果
| 問題 |
No.1084 積の積
|
| コンテスト | |
| ユーザー |
kriii
|
| 提出日時 | 2020-06-19 21:42:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 912 bytes |
| コンパイル時間 | 956 ms |
| コンパイル使用メモリ | 57,716 KB |
| 最終ジャッジ日時 | 2025-01-11 05:59:31 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 2 |
| other | AC * 5 WA * 22 |
コンパイルメッセージ
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 * 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;
}
kriii