結果

問題 No.2709 1975 Powers
ユーザー Today03
提出日時 2024-03-31 20:37:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,031 ms / 2,000 ms
コード長 1,373 bytes
コンパイル時間 5,150 ms
コンパイル使用メモリ 205,680 KB
最終ジャッジ日時 2025-02-20 18:20:08
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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