結果

問題 No.2709 1975 Powers
ユーザー t98slidert98slider
提出日時 2024-03-31 14:09:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 926 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 209,440 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-03-31 14:09:25
合計ジャッジ時間 15,265 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 45 ms
6,676 KB
testcase_03 AC 370 ms
6,676 KB
testcase_04 AC 1,898 ms
6,676 KB
testcase_05 AC 1,087 ms
6,676 KB
testcase_06 AC 1,038 ms
6,676 KB
testcase_07 AC 10 ms
6,676 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 11 ms
6,676 KB
testcase_11 AC 151 ms
6,676 KB
testcase_12 AC 666 ms
6,676 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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--){
            for(int k = 0; k < p; k++){
                if(dp[j][k] == 0) continue;
                int v2 = modpow(b[j], v, p) + k;
                if(v2 >= p) v2 -= p;
                dp[j + 1][v2] += dp[j][k];
            }
        }
    }
    cout << dp[4][q] << '\n';
}
0