結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 349 ms
22,400 KB
testcase_03 AC 489 ms
14,336 KB
testcase_04 AC 885 ms
20,096 KB
testcase_05 AC 680 ms
17,920 KB
testcase_06 AC 208 ms
9,472 KB
testcase_07 AC 109 ms
21,120 KB
testcase_08 AC 648 ms
22,144 KB
testcase_09 AC 772 ms
19,584 KB
testcase_10 AC 116 ms
21,376 KB
testcase_11 AC 144 ms
10,880 KB
testcase_12 AC 527 ms
24,192 KB
testcase_13 AC 957 ms
22,912 KB
testcase_14 AC 277 ms
13,056 KB
testcase_15 AC 658 ms
23,808 KB
testcase_16 AC 377 ms
12,160 KB
testcase_17 AC 117 ms
14,336 KB
testcase_18 AC 574 ms
23,808 KB
testcase_19 AC 754 ms
18,304 KB
testcase_20 AC 296 ms
23,296 KB
testcase_21 AC 649 ms
22,144 KB
testcase_22 AC 1,059 ms
22,400 KB
testcase_23 AC 806 ms
18,432 KB
testcase_24 AC 456 ms
12,160 KB
testcase_25 AC 774 ms
17,920 KB
testcase_26 AC 870 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];
    }
    sort(A.begin(), A.end());
    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