結果
| 問題 |
No.1084 積の積
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2020-06-19 22:03:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 913 ms |
| コンパイル使用メモリ | 93,616 KB |
| 最終ジャッジ日時 | 2025-01-11 06:20:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
ll powmod(ll n, ll k) {
ll r = 1, t = n % P;
for (; k != 0; k /= 2) {
if (k & 1) r = r * t % P;
t = t * t % P;
}
return r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), p(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 0) {
cout << 0 << endl;
exit(0);
}
}
int k = 0;
for (int i = n - 1; i >= 0; i--) {
p[i] = k;
if (a[i] == 1) k++; else k = 0;
}
ll r = 1;
for (int i = 0; i < n; i++) {
ll t = 1;
for (int j = i; j < n; j++) {
t *= a[j];
if (t >= (int)1e+9) break;
int k = p[j];
if (k == 0) {
(r *= t) %= P;
} else {
(r *= powmod(t, k + 1)) %= P;
j += k;
}
}
}
cout << r << endl;
return 0;
}
merom686