結果

問題 No.2260 Adic Sum
ユーザー tentententen
提出日時 2023-04-10 10:34:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,410 ms / 2,000 ms
コード長 2,353 bytes
コンパイル時間 3,479 ms
コンパイル使用メモリ 91,824 KB
実行使用メモリ 67,724 KB
最終ジャッジ日時 2024-04-16 00:03:55
合計ジャッジ時間 21,044 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
50,280 KB
testcase_01 AC 58 ms
50,624 KB
testcase_02 AC 60 ms
50,312 KB
testcase_03 AC 61 ms
50,172 KB
testcase_04 AC 61 ms
50,584 KB
testcase_05 AC 59 ms
50,472 KB
testcase_06 AC 60 ms
50,312 KB
testcase_07 AC 59 ms
50,536 KB
testcase_08 AC 112 ms
52,052 KB
testcase_09 AC 82 ms
51,452 KB
testcase_10 AC 111 ms
52,396 KB
testcase_11 AC 62 ms
50,328 KB
testcase_12 AC 120 ms
52,044 KB
testcase_13 AC 119 ms
51,892 KB
testcase_14 AC 291 ms
59,016 KB
testcase_15 AC 369 ms
49,812 KB
testcase_16 AC 259 ms
48,276 KB
testcase_17 AC 358 ms
49,416 KB
testcase_18 AC 1,069 ms
58,176 KB
testcase_19 AC 1,146 ms
67,724 KB
testcase_20 AC 884 ms
56,972 KB
testcase_21 AC 874 ms
56,884 KB
testcase_22 AC 858 ms
57,152 KB
testcase_23 AC 641 ms
66,296 KB
testcase_24 AC 1,114 ms
58,836 KB
testcase_25 AC 435 ms
52,748 KB
testcase_26 AC 445 ms
51,980 KB
testcase_27 AC 449 ms
52,148 KB
testcase_28 AC 458 ms
52,552 KB
testcase_29 AC 460 ms
51,856 KB
testcase_30 AC 416 ms
50,420 KB
testcase_31 AC 674 ms
54,536 KB
testcase_32 AC 1,192 ms
58,956 KB
testcase_33 AC 365 ms
54,264 KB
testcase_34 AC 567 ms
59,272 KB
testcase_35 AC 1,410 ms
57,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int p = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        int current = 1;
        ArrayList<Integer> ps = new ArrayList<>();
        while (current * (long)p <= 1000000000) {
            current *= p;
            ps.add(current);
        }
        long ans = 0;
        for (int x : ps) {
            int[] mods = new int[n];
            HashMap<Integer, Integer> counts = new HashMap<>();
            for (int i = 0; i < n; i++) {
                mods[i] = values[i] % x;
                counts.put(mods[i], counts.getOrDefault(mods[i], 0) + 1);
            }
            for (int i = 0; i < n; i++) {
                counts.put(mods[i], counts.get(mods[i]) - 1);
                ans += counts.getOrDefault(mods[i], 0);
            }
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0