結果

問題 No.1084 積の積
ユーザー potoooooooopotoooooooo
提出日時 2020-06-19 21:57:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,380 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 201,708 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-09-16 14:06:29
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 26 ms
5,516 KB
testcase_05 WA -
testcase_06 AC 26 ms
5,452 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 16 ms
5,336 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 18 ms
5,432 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 12 ms
4,476 KB
testcase_19 AC 16 ms
4,996 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 9 ms
4,500 KB
testcase_25 AC 16 ms
5,056 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 14 ms
5,456 KB
testcase_28 AC 14 ms
5,256 KB
testcase_29 AC 14 ms
5,460 KB
testcase_30 AC 14 ms
5,396 KB
testcase_31 AC 14 ms
5,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 1000000007;
constexpr long long M = 1e9;

long long modpow(long long a, long long r) {
    assert(r > 0);
    long long ret = 1;
    while (r) {
        if (r & 1) ret = ret * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return ret;
}

long long solve(vector<long long> &A) {
    int N = A.size();
    long long curr = 1;
    long long Ans = 1;
    int l = 0;
    vector<long long> C(N+1, 0), D(N+1, 0);
    for (int i = 0; i < N; i++) {
        curr *= A[i];
        while (curr >= M) {
            C[l] += i - l;
            D[l] += 1, D[i] -= 1;
            curr = curr / A[l]; l++;
        }    
    }
    while (l < N) {
        C[l] += N - l;
        D[l] += 1, D[N] -= 1;
        l++;
    }
    for (int i = 0; i < N; i++) {
        Ans = Ans * modpow(A[i], C[i]) % mod;
        D[i+1] += D[i];
        C[i+1] += C[i] - D[i];
    }
    return Ans;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<long long> A;
    long long Ans = 1;
    for (int i = 0; i < N; i++) {
        long long x; cin >> x;
        if (x == 0) {
            Ans = Ans * solve(A) % mod;
            A.clear();
        } else {
            A.emplace_back(x);
        }
    }
    if (!A.empty()) Ans = Ans * solve(A) % mod;
    cout << Ans << "\n";
    return 0;
}
0