結果
| 問題 |
No.2260 Adic Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-07 22:13:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 972 bytes |
| コンパイル時間 | 2,216 ms |
| コンパイル使用メモリ | 203,720 KB |
| 最終ジャッジ日時 | 2025-02-12 01:36:11 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 TLE * 3 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
#define MOD 1000000007
#define Mod 998244353
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;
int main() {
ios::sync_with_stdio(0);cin.tie();
int N, P;
cin >> N >> P;
vector<ll> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
ll now = 1;
int M = 0;
while (now < 1000000000) {
M++;
now *= P;
}
vector<map<int, int>> C(M+1);
now = 1;
for (int i = 0; i <= M; i++) {
for (int j = 0; j < N; j++) C[i][A[j] % now]++;
now *= P;
}
ll ans = 0;
now = P;
for (int i = 1; i < M; i++) {
for (int j = 0; j < N; j++) {
ans += (ll)i * (C[i][A[j] % now] - C[i+1][A[j] % (now * P)]);
C[i][A[j] % now]--;
C[i+1][A[j] % (now * P)]--;
}
for (int j = 0; j < N; j++) C[i+1][A[j] % (now * P)]++;
now *= P;
}
cout << ans << endl;
}