結果

問題 No.2709 1975 Powers
ユーザー うえこうえこ
提出日時 2024-03-31 14:15:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,978 ms / 2,000 ms
コード長 1,419 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 177,640 KB
実行使用メモリ 17,316 KB
最終ジャッジ日時 2024-04-06 16:47:13
合計ジャッジ時間 28,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 584 ms
16,160 KB
testcase_03 AC 942 ms
10,848 KB
testcase_04 AC 1,648 ms
14,500 KB
testcase_05 AC 1,284 ms
13,212 KB
testcase_06 AC 397 ms
7,476 KB
testcase_07 AC 178 ms
15,196 KB
testcase_08 AC 1,232 ms
15,900 KB
testcase_09 AC 1,453 ms
14,344 KB
testcase_10 AC 191 ms
15,368 KB
testcase_11 AC 268 ms
8,368 KB
testcase_12 AC 993 ms
17,316 KB
testcase_13 AC 1,784 ms
16,348 KB
testcase_14 AC 524 ms
9,948 KB
testcase_15 AC 1,179 ms
17,096 KB
testcase_16 AC 725 ms
9,348 KB
testcase_17 AC 206 ms
10,668 KB
testcase_18 AC 1,050 ms
16,960 KB
testcase_19 AC 1,450 ms
13,252 KB
testcase_20 AC 542 ms
16,680 KB
testcase_21 AC 1,228 ms
15,892 KB
testcase_22 AC 1,978 ms
16,164 KB
testcase_23 AC 1,562 ms
13,492 KB
testcase_24 AC 881 ms
9,196 KB
testcase_25 AC 1,487 ms
13,192 KB
testcase_26 AC 1,662 ms
14,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
const long long INF=1LL<<60;
ll h,w;
long long power(long long a, long long n, ll m) {
    long long res = 1;
    while (n > 0) {
        if (n%2==1){
          res = res * a % m;
          n-=1;
        }
        a = a * a % m;
        n/=2;
    }
    return res;
}
int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
    ll n,p,q;
    std::cin >> n >> p >> q;
    std::vector<ll>A(n);
    for(auto&a:A)std::cin >> a;
    std::sort(A.begin(),A.end());
    std::vector<ll>ten(n),nine(n),seven(n),five(n);
    for(int i=0;i<n;++i){
        ten[i]=power(10, A[i], p);
        nine[i]=power(9, A[i], p);
        seven[i]=power(7, A[i], p);
        five[i]=power(5, A[i], p);
    }
    ll ans=0;
    std::vector<std::vector<ll>> dp(p,std::vector<ll>(5));
    dp[0][0]=1;
    for(int i=0;i<n;++i){
        std::vector<std::vector<ll>>nw=dp;
        for(int rem=0;rem<p;++rem){
            for(int cnt=0;cnt<5;++cnt){
                if(cnt!=4){
                    ll add=0;
                    if(cnt==0)add+=ten[i];
                    else if(cnt==1)add+=nine[i];
                    else if(cnt==2)add+=seven[i];
                    else add+=five[i];
                    ll nrem=rem+add;nrem%=p;
                    nw[nrem][cnt+1]+=dp[rem][cnt];
                }
            }
        }
        std::swap(nw,dp);
    }
    std::cout << dp[q].back() << '\n';
}
0