結果

問題 No.2709 1975 Powers
ユーザー t98slidert98slider
提出日時 2024-03-31 14:11:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 209,320 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:11:39
合計ジャッジ時間 4,773 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 29 ms
6,676 KB
testcase_03 AC 47 ms
6,676 KB
testcase_04 AC 95 ms
6,676 KB
testcase_05 AC 69 ms
6,676 KB
testcase_06 AC 32 ms
6,676 KB
testcase_07 AC 11 ms
6,676 KB
testcase_08 AC 87 ms
6,676 KB
testcase_09 AC 87 ms
6,676 KB
testcase_10 AC 12 ms
6,676 KB
testcase_11 AC 18 ms
6,676 KB
testcase_12 AC 65 ms
6,676 KB
testcase_13 AC 124 ms
6,676 KB
testcase_14 AC 31 ms
6,676 KB
testcase_15 AC 60 ms
6,676 KB
testcase_16 AC 47 ms
6,676 KB
testcase_17 AC 13 ms
6,676 KB
testcase_18 AC 72 ms
6,676 KB
testcase_19 AC 105 ms
6,676 KB
testcase_20 AC 29 ms
6,676 KB
testcase_21 AC 88 ms
6,676 KB
testcase_22 AC 103 ms
6,676 KB
testcase_23 AC 113 ms
6,676 KB
testcase_24 AC 70 ms
6,676 KB
testcase_25 AC 80 ms
6,676 KB
testcase_26 AC 80 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

ll modpow(ll a, ll b, ll p){ 
    ll ans = 1; 
    while(b){ 
        if(b & 1) (ans *= a) %= p; 
        (a *= a) %= p; 
        b /= 2; 
    } 
    return ans; 
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p, q;
    cin >> n >> p >> q;
    vector dp(5, vector<int>(p));
    vector<int> a(n), b = {10, 9, 7, 5};
    cin >> a;
    sort(a.begin(), a.end());
    dp[0][0] = 1;
    for(auto &&v : a){
        for(int j = 3; j >= 0; j--){
            int v3 = modpow(b[j], v, p);
            for(int k = 0; k < p; k++){
                if(dp[j][k] == 0) continue;
                int v2 = v3 + k;
                if(v2 >= p) v2 -= p;
                dp[j + 1][v2] += dp[j][k];
            }
        }
    }
    cout << dp[4][q] << '\n';
}
0