結果

問題 No.2394 部分和乗総和
ユーザー CyanmondCyanmond
提出日時 2023-07-28 21:40:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 705 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 195,848 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 05:30:31
合計ジャッジ時間 4,431 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include "atcoder/modint"

using i64 = long long;
// using Fp = atcoder::modint998244353;

i64 modPow(i64 a, i64 n, i64 mod) {
    i64 b = a, res = 1;
    while (n != 0) {
        if (n % 2 == 1) {
            res *= b;
            res %= mod;
        }
        b *= b;
        b %= mod;
        n /= 2;
    }
    return res;
}

int main() {
    int N, M;
    i64 B;
    std::cin >> N >> M >> B;
    std::vector<i64> A(N);
    for (auto &e : A) std::cin >> e;
    M %= B;
    std::vector<i64> dp(N + 1);
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        dp[i + 1] = dp[i] + dp[i] * modPow(M, A[i], B);
        dp[i + 1] %= B;
    }
    std::cout << dp[N] << std::endl;
}
0