結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
rurun
|
| 提出日時 | 2024-03-31 13:59:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,814 ms / 2,000 ms |
| コード長 | 1,116 bytes |
| コンパイル時間 | 1,967 ms |
| コンパイル使用メモリ | 203,152 KB |
| 最終ジャッジ日時 | 2025-02-20 16:48:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T>
T modpow(T a, T b, T mod=998244353) {
T res = 1;
while (b > 0) {
if (b&1) (res *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return res;
}
int main() {
lint n, p, q;
cin >> n >> p >> q;
vector<lint> vec(n);
for (int i = 0; i < n; i++) cin >> vec[i];
sort(vec.begin(), vec.end());
vector<vector<lint>> cnt(n+1, vector<lint>(p)); // iより後ろでjあまるものの数
vector rui = cnt;
for (int i = 0; i < n; i++) {
cnt[i][modpow(5LL, vec[i], p)]++;
}
for (int i = n-1; i >= 0; i--) {
for (int j = 0; j < p; j++) {
rui[i][j] = rui[i+1][j]+cnt[i+1][j];
}
}
lint ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
for (int k = j+1; k < n; k++) {
lint now = modpow(10LL, vec[i], p)+modpow(9LL, vec[j], p)+ modpow(7LL, vec[k], p);
now %= p;
ans += rui[k][(q+p-now)%p];
}
}
}
cout << ans << endl;
return 0;
for (auto x : rui) {
for (auto y : x) cout << y << " ";
cout << endl;
}
}
rurun