結果
問題 | No.2709 1975 Powers |
ユーザー |
|
提出日時 | 2024-03-31 14:11:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 951 bytes |
コンパイル時間 | 2,081 ms |
コンパイル使用メモリ | 201,220 KB |
最終ジャッジ日時 | 2025-02-20 17:02:00 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#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--){ int v3 = modpow(b[j], v, p); for(int k = 0; k < p; k++){ if(dp[j][k] == 0) continue; int v2 = v3 + k; if(v2 >= p) v2 -= p; dp[j + 1][v2] += dp[j][k]; } } } cout << dp[4][q] << '\n'; }