結果

問題 No.2709 1975 Powers
ユーザー うえこ
提出日時 2024-03-31 13:56:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,379 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 176,520 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2024-09-30 18:40:08
合計ジャッジ時間 6,205 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 MLE * 2 -- * 22
権限があれば一括ダウンロードができます

ソースコード

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;
    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<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+=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;
                    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