結果
問題 | No.1084 積の積 |
ユーザー |
|
提出日時 | 2020-06-19 23:09:15 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,327 bytes |
コンパイル時間 | 665 ms |
コンパイル使用メモリ | 124,480 KB |
実行使用メモリ | 9,276 KB |
最終ジャッジ日時 | 2024-06-22 07:28:26 |
合計ジャッジ時間 | 2,117 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 1 |
other | AC * 26 WA * 1 |
ソースコード
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;if (A.map!(a => a == 0).all) {writeln(0);return;}long ans = 1;foreach (a; A.split(0)) {ans = ans * solve(a.array) % mod;}ans.writeln;}long solve(long[] A) {if (A.empty) return 1;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;}