結果

問題 No.2260 Adic Sum
ユーザー 👑 chro_96chro_96
提出日時 2023-04-07 21:37:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2024-04-15 23:48:09
合計ジャッジ時間 5,109 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 291 ms
5,784 KB
testcase_19 AC 319 ms
5,780 KB
testcase_20 AC 211 ms
5,764 KB
testcase_21 AC 211 ms
5,528 KB
testcase_22 AC 177 ms
5,784 KB
testcase_23 AC 131 ms
5,760 KB
testcase_24 AC 322 ms
5,784 KB
testcase_25 AC 33 ms
5,376 KB
testcase_26 AC 32 ms
5,632 KB
testcase_27 AC 34 ms
5,632 KB
testcase_28 AC 32 ms
5,632 KB
testcase_29 AC 33 ms
5,632 KB
testcase_30 AC 49 ms
5,908 KB
testcase_31 AC 253 ms
5,780 KB
testcase_32 AC 253 ms
5,784 KB
testcase_33 AC 31 ms
5,504 KB
testcase_34 AC 67 ms
5,912 KB
testcase_35 AC 507 ms
5,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0