結果

問題 No.2709 1975 Powers
ユーザー Today03Today03
提出日時 2024-03-31 20:37:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,343 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 210,920 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2024-03-31 20:37:43
合計ジャッジ時間 17,082 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 318 ms
22,400 KB
testcase_03 AC 487 ms
14,336 KB
testcase_04 AC 881 ms
20,096 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 107 ms
21,120 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 115 ms
21,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 280 ms
13,056 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,045 ms
22,400 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 789 ms
17,920 KB
testcase_26 AC 883 ms
19,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

ll pow_mod(ll x, ll n, ll mod) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

const vector<int> E = {10, 9, 7, 5};

int main() {
    int N, P, Q;
    cin >> N >> P >> Q;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<vector<ll>> B(N, vector<ll>(4));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            B[i][j] = pow_mod(E[j], A[i], P);
        }
    }

    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(P, vector<ll>(5, 0)));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < P; j++) {
            for (int k = 0; k < 5; k++) {
                dp[1 - i % 2][j][k] += dp[i % 2][j][k];
                if (k == 4) {
                    continue;
                }
                dp[1 - i % 2][(j + B[i][k]) % P][k + 1] += dp[i % 2][j][k];
            }
        }
        for (int j = 0; j < P; j++) {
            for (int k = 0; k < 5; k++) {
                dp[i % 2][j][k] = 0;
            }
        }
    }

    cout << dp[N % 2][Q][4] << endl;
}
0