結果
| 問題 |
No.1084 積の積
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 23:06:24 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,221 bytes |
| コンパイル時間 | 652 ms |
| コンパイル使用メモリ | 122,616 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2024-06-22 07:28:08 |
| 合計ジャッジ時間 | 2,095 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 24 WA * 3 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;
immutable long mod = 10 ^^ 9 + 7;
void main() {
auto N = readln.chomp.to!int;
auto A = readln.split.map!(to!long).array;
long ans = 1;
foreach (a; A.split(0)) {
ans = ans * solve(a.array) % mod;
}
ans.writeln;
}
long solve(long[] A) {
int N = A.length.to!int;
long tmp = 1;
long ans = 1;
auto imos = new long[](N+1);
auto len = new long[](N+1);
for (int i = 0, j = 0; i < N; ++i) {
if (i > 0) tmp /= A[i-1];
while (j < N && tmp * A[j] < 10^^9) {
tmp *= A[j++];
}
if (i > 0) imos[i-1] -= 1;
imos[j-1] += 1;
len[i] = j - i;
}
foreach_reverse (i; 1..N) imos[i-1] += imos[i];
foreach_reverse(i; 1..N) imos[i-1] += imos[i] - len[i];
foreach (i; 0..N) ans = ans * powmod(A[i], imos[i], mod) % mod;
return ans;
}
long powmod(long a, long x, long m) {
long ret = 1;
while (x) {
if (x % 2) ret = ret * a % m;
a = a * a % m;
x /= 2;
}
return ret;
}