結果

問題 No.2709 1975 Powers
ユーザー shinchanshinchan
提出日時 2024-03-31 13:45:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,224 ms / 2,000 ms
コード長 1,825 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 212,508 KB
実行使用メモリ 104,768 KB
最終ジャッジ日時 2024-03-31 13:45:25
合計ジャッジ時間 22,354 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
97,124 KB
testcase_01 AC 219 ms
97,124 KB
testcase_02 AC 521 ms
104,160 KB
testcase_03 AC 704 ms
101,148 KB
testcase_04 AC 1,061 ms
103,348 KB
testcase_05 AC 887 ms
102,580 KB
testcase_06 AC 423 ms
99,344 KB
testcase_07 AC 311 ms
103,664 KB
testcase_08 AC 857 ms
103,984 KB
testcase_09 AC 958 ms
103,124 KB
testcase_10 AC 314 ms
103,748 KB
testcase_11 AC 359 ms
99,856 KB
testcase_12 AC 742 ms
104,768 KB
testcase_13 AC 1,136 ms
104,392 KB
testcase_14 AC 489 ms
100,636 KB
testcase_15 AC 828 ms
104,592 KB
testcase_16 AC 591 ms
100,352 KB
testcase_17 AC 326 ms
101,132 KB
testcase_18 AC 752 ms
104,592 KB
testcase_19 AC 966 ms
102,508 KB
testcase_20 AC 497 ms
104,372 KB
testcase_21 AC 850 ms
104,112 KB
testcase_22 AC 1,224 ms
104,160 KB
testcase_23 AC 1,006 ms
102,672 KB
testcase_24 AC 676 ms
100,344 KB
testcase_25 AC 971 ms
102,572 KB
testcase_26 AC 1,073 ms
103,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modinv(long long a, long long MOD) {
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; std::swap(a, b);
        u -= t * v; std::swap(u, v);
    }
    u %= MOD; 
    if (u < 0) u += MOD;
    return u;
}

long long modpow(long long a, long long n, long long MOD) {
    long long res = 1;
    a %= MOD;
    if(n < 0) {
        n = -n;
        a = modinv(a, MOD);
    }
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p, q;
    cin >> n >> p >> q;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<vector<ll>> dp(5, vector<ll> (p, 0));
    ll N = 3000000;
    vector<ll> pow10(N, 1);
    vector<ll> pow9(N, 1);
    vector<ll> pow7(N, 1);
    vector<ll> pow5(N, 1);
    rep(i, N - 1) pow10[i + 1] = pow10[i] * 10 % p;
    rep(i, N - 1) pow9[i + 1] = pow9[i] * 9 % p;
    rep(i, N - 1) pow7[i + 1] = pow7[i] * 7 % p;
    rep(i, N - 1) pow5[i + 1] = pow5[i] * 5 % p;
    dp[0][0] = 1;
    foa(e, a) {
        vector<vector<ll>> nx = dp;
        for(int i = 0; i < p; i ++) {
            nx[1][(i + pow10[e]) % p] += dp[0][i];
            nx[2][(i + pow9[e]) % p] += dp[1][i];
            nx[3][(i + pow7[e]) % p] += dp[2][i];
            nx[4][(i + pow5[e]) % p] += dp[3][i];
        }
        swap(nx, dp);
    }
    cout << dp[4][q] << endl;

    return 0;
}
0