結果
| 問題 |
No.2260 Adic Sum
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-04-07 21:37:43 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 508 ms / 2,000 ms |
| コード長 | 1,084 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 30,336 KB |
| 実行使用メモリ | 5,912 KB |
| 最終ジャッジ日時 | 2024-10-06 07:08:54 |
| 合計ジャッジ時間 | 4,649 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
int cmp_ll (const void *ap, const void *bp) {
long long a = *(long long *)ap;
long long b = *(long long *)bp;
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
int main () {
int n = 0;
long long p = 0LL;
long long a[100000] = {};
int res = 0;
long long ans = 0LL;
long long rem[100000][2] = {};
long long max = 0LL;
long long pow = 1LL;
res = scanf("%d", &n);
res = scanf("%lld", &p);
for (int i = 0; i < n; i++) {
res = scanf("%lld", a+i);
if (a[i] > max) {
max = a[i];
}
}
while (pow <= max/p) {
int ucnt = 1;
pow *= p;
for (int i = 0; i < n; i++) {
rem[i][0] = a[i]%pow;
}
qsort(rem, n, sizeof(long long)*2, cmp_ll);
rem[0][1] = 1LL;
for (int i = 1; i < n; i++) {
if (rem[i-1][0] != rem[i][0]) {
rem[ucnt][0] = rem[i][0];
rem[ucnt][1] = 0LL;
ucnt++;
}
ans += rem[ucnt-1][1];
rem[ucnt-1][1] += 1LL;
}
}
printf("%lld\n", ans);
return 0;
}
chro_96