結果

問題 No.2709 1975 Powers
ユーザー うえこうえこ
提出日時 2024-03-31 13:53:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 175,456 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2024-03-31 13:54:06
合計ジャッジ時間 5,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 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(){
    ll n,p,q;
    std::cin >> n >> p >> q;
    std::vector<ll>A(n);
    for(auto&a:A)std::cin >> a;
    ll ans=0;
    std::vector<std::vector<std::vector<ll>>>dp(n+1,std::vector<std::vector<ll>>(p,std::vector<ll>(5)));
    dp[0][0][0]=1;
    for(int i=0;i<n;++i){
        for(int rem=0;rem<p;++rem){
            for(int cnt=0;cnt<5;++cnt){
                if(cnt!=4){
                    ll add=0;
                    if(cnt==0)add+=power(10, A[i], p);
                    else if(cnt==1)add+=power(9, A[i], p);
                    else if(cnt==2)add+=power(7, A[i], p);
                    else add+=power(5, A[i], p);
                    ll nrem=rem+add;nrem%=p;
                    dp[i+1][nrem][cnt+1]+=dp[i][rem][cnt];
                }
                dp[i+1][rem][cnt]+=dp[i][rem][cnt];
            }
        }
    }
    std::cout << dp.back()[q].back() << '\n';
}
0