結果

問題 No.1084 積の積
ユーザー nebukuro09nebukuro09
提出日時 2020-06-19 23:09:15
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 109,820 KB
実行使用メモリ 9,156 KB
最終ジャッジ日時 2023-09-04 08:15:26
合計ジャッジ時間 2,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 81 ms
7,720 KB
testcase_05 AC 9 ms
5,368 KB
testcase_06 AC 79 ms
7,744 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 12 ms
5,420 KB
testcase_13 AC 24 ms
7,828 KB
testcase_14 AC 10 ms
5,528 KB
testcase_15 AC 9 ms
5,500 KB
testcase_16 AC 27 ms
9,036 KB
testcase_17 AC 11 ms
5,104 KB
testcase_18 AC 17 ms
6,572 KB
testcase_19 AC 25 ms
7,880 KB
testcase_20 AC 7 ms
4,776 KB
testcase_21 AC 9 ms
5,232 KB
testcase_22 AC 8 ms
5,364 KB
testcase_23 AC 15 ms
5,936 KB
testcase_24 AC 14 ms
5,868 KB
testcase_25 AC 24 ms
7,988 KB
testcase_26 AC 24 ms
8,320 KB
testcase_27 AC 23 ms
9,156 KB
testcase_28 AC 24 ms
7,880 KB
testcase_29 AC 23 ms
7,920 KB
testcase_30 AC 24 ms
7,920 KB
testcase_31 AC 23 ms
8,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
}
0