結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
うえこ
|
| 提出日時 | 2024-03-31 14:12:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,395 bytes |
| コンパイル時間 | 1,781 ms |
| コンパイル使用メモリ | 174,432 KB |
| 実行使用メモリ | 17,424 KB |
| 最終ジャッジ日時 | 2024-09-30 19:08:40 |
| 合計ジャッジ時間 | 25,073 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 16 |
ソースコード
#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<ll>> dp(p,std::vector<ll>(5));
dp[0][0]=1;
for(int i=0;i<n;++i){
std::vector<std::vector<ll>>nw(p,std::vector<ll>(5));
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];
}
nw[rem][cnt]+=dp[rem][cnt];
}
}
std::swap(nw,dp);
}
std::cout << dp[q].back() << '\n';
}
うえこ