結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:09:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 926 bytes |
| コンパイル時間 | 2,202 ms |
| コンパイル使用メモリ | 200,092 KB |
| 最終ジャッジ日時 | 2025-02-20 16:57:53 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 2 -- * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> istream& operator >> (istream& is, vector<T>& vec) {
for(T& x : vec) is >> x;
return is;
}
ll modpow(ll a, ll b, ll p){
ll ans = 1;
while(b){
if(b & 1) (ans *= a) %= p;
(a *= a) %= p;
b /= 2;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
vector dp(5, vector<int>(p));
vector<int> a(n), b = {10, 9, 7, 5};
cin >> a;
sort(a.begin(), a.end());
dp[0][0] = 1;
for(auto &&v : a){
for(int j = 3; j >= 0; j--){
for(int k = 0; k < p; k++){
if(dp[j][k] == 0) continue;
int v2 = modpow(b[j], v, p) + k;
if(v2 >= p) v2 -= p;
dp[j + 1][v2] += dp[j][k];
}
}
}
cout << dp[4][q] << '\n';
}