結果

問題 No.2709 1975 Powers
ユーザー Basin-BugBasin-Bug
提出日時 2024-03-31 14:21:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,306 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 91,884 KB
実行使用メモリ 363,264 KB
最終ジャッジ日時 2024-03-31 14:22:06
合計ジャッジ時間 9,108 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 186 ms
110,464 KB
testcase_03 AC 286 ms
181,376 KB
testcase_04 AC 466 ms
306,304 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 51 ms
36,864 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 56 ms
38,912 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 158 ms
101,632 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 618 ms
363,264 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 431 ms
278,400 KB
testcase_26 AC 480 ms
310,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

long long pow(long long x, long long n, long long P) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % P;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % P;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main() {
    int N, P, Q;
    cin >> N >> P >> Q;
    vector<int> A(N);
    for (int &a : A) cin >> a;

    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(5, vector<int>(P, 0)));
    dp[0][0][0] = 1;

    for (int i = 1; i <= N; ++i) {
        int a = pow(10, A[i - 1], P);
        int b = pow(9, A[i - 1], P);
        int c = pow(7, A[i - 1], P);
        int d = pow(5, A[i - 1], P);

        for (int j = 0; j < P; ++j) {
            dp[i][0][j] += dp[i - 1][0][j];
            dp[i][1][(j + a) % P] += dp[i - 1][0][j];
            dp[i][1][j] += dp[i - 1][1][j];
            dp[i][2][(j + b) % P] += dp[i - 1][1][j];
            dp[i][2][j] += dp[i - 1][2][j];
            dp[i][3][(j + c) % P] += dp[i - 1][2][j];
            dp[i][3][j] += dp[i - 1][3][j];
            dp[i][4][(j + d) % P] += dp[i - 1][3][j];
            dp[i][4][j] += dp[i - 1][4][j];
        }
    }

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