結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
うえこ
|
| 提出日時 | 2024-03-31 14:15:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,633 ms / 2,000 ms |
| コード長 | 1,419 bytes |
| コンパイル時間 | 1,839 ms |
| コンパイル使用メモリ | 177,984 KB |
| 実行使用メモリ | 17,104 KB |
| 最終ジャッジ日時 | 2024-10-01 03:54:36 |
| 合計ジャッジ時間 | 23,714 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#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';
}
うえこ