結果

問題 No.2260 Adic Sum
ユーザー ks2mks2m
提出日時 2023-04-07 23:40:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,131 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 78,200 KB
実行使用メモリ 57,064 KB
最終ジャッジ日時 2024-04-15 23:58:54
合計ジャッジ時間 15,503 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,144 KB
testcase_01 AC 55 ms
37,032 KB
testcase_02 AC 55 ms
37,012 KB
testcase_03 AC 55 ms
36,780 KB
testcase_04 AC 56 ms
36,940 KB
testcase_05 AC 55 ms
36,736 KB
testcase_06 AC 57 ms
36,884 KB
testcase_07 AC 55 ms
37,056 KB
testcase_08 AC 83 ms
38,520 KB
testcase_09 AC 62 ms
37,296 KB
testcase_10 AC 85 ms
38,652 KB
testcase_11 AC 59 ms
37,216 KB
testcase_12 AC 99 ms
39,264 KB
testcase_13 AC 87 ms
38,824 KB
testcase_14 AC 219 ms
48,152 KB
testcase_15 AC 268 ms
48,488 KB
testcase_16 AC 200 ms
46,340 KB
testcase_17 AC 273 ms
48,016 KB
testcase_18 AC 754 ms
56,240 KB
testcase_19 AC 836 ms
55,764 KB
testcase_20 AC 630 ms
55,212 KB
testcase_21 AC 652 ms
56,132 KB
testcase_22 AC 569 ms
56,320 KB
testcase_23 AC 472 ms
55,196 KB
testcase_24 AC 753 ms
55,892 KB
testcase_25 AC 334 ms
54,532 KB
testcase_26 AC 319 ms
54,428 KB
testcase_27 AC 329 ms
54,728 KB
testcase_28 AC 317 ms
54,396 KB
testcase_29 AC 325 ms
54,244 KB
testcase_30 AC 334 ms
52,860 KB
testcase_31 AC 598 ms
54,484 KB
testcase_32 AC 661 ms
54,620 KB
testcase_33 AC 332 ms
54,756 KB
testcase_34 AC 492 ms
55,944 KB
testcase_35 AC 1,131 ms
57,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int p = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long ans = 0;
		long p2 = p;
		while (p2 <= 1000000000) {
			Map<Integer, Integer> map = new HashMap<>();
			for (int i = 0; i < n; i++) {
				int k = (int) (a[i] % p2);
				int v = map.getOrDefault(k, 0);
				ans += v;
				map.put(k, v + 1);
			}
			p2 *= p;
		}
		System.out.println(ans);
	}
}
0