結果
| 問題 | No.1084 積の積 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-19 23:11:20 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 81 ms / 2,000 ms | 
| コード長 | 1,327 bytes | 
| コンパイル時間 | 819 ms | 
| コンパイル使用メモリ | 123,556 KB | 
| 実行使用メモリ | 9,388 KB | 
| 最終ジャッジ日時 | 2024-06-22 07:28:31 | 
| 合計ジャッジ時間 | 2,450 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 27 | 
ソースコード
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).any) {
        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;
}
            
            
            
        