結果

問題 No.1972 Modulo Set
ユーザー tentententen
提出日時 2023-08-08 14:10:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 2,332 bytes
コンパイル時間 2,831 ms
コンパイル使用メモリ 95,956 KB
実行使用メモリ 63,060 KB
最終ジャッジ日時 2024-04-26 06:53:19
合計ジャッジ時間 13,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,468 KB
testcase_01 AC 53 ms
50,160 KB
testcase_02 AC 52 ms
50,024 KB
testcase_03 AC 162 ms
54,072 KB
testcase_04 AC 176 ms
55,160 KB
testcase_05 AC 172 ms
55,892 KB
testcase_06 AC 238 ms
56,268 KB
testcase_07 AC 270 ms
58,548 KB
testcase_08 AC 216 ms
55,872 KB
testcase_09 AC 106 ms
52,084 KB
testcase_10 AC 174 ms
54,896 KB
testcase_11 AC 271 ms
56,460 KB
testcase_12 AC 154 ms
55,728 KB
testcase_13 AC 117 ms
52,160 KB
testcase_14 AC 114 ms
52,156 KB
testcase_15 AC 271 ms
58,768 KB
testcase_16 AC 282 ms
58,904 KB
testcase_17 AC 188 ms
55,252 KB
testcase_18 AC 55 ms
50,304 KB
testcase_19 AC 246 ms
58,552 KB
testcase_20 AC 284 ms
58,916 KB
testcase_21 AC 225 ms
55,904 KB
testcase_22 AC 245 ms
58,476 KB
testcase_23 AC 326 ms
63,024 KB
testcase_24 AC 229 ms
58,528 KB
testcase_25 AC 244 ms
58,368 KB
testcase_26 AC 285 ms
60,764 KB
testcase_27 AC 320 ms
62,876 KB
testcase_28 AC 237 ms
58,656 KB
testcase_29 AC 277 ms
58,956 KB
testcase_30 AC 300 ms
60,772 KB
testcase_31 AC 110 ms
52,144 KB
testcase_32 AC 282 ms
60,872 KB
testcase_33 AC 358 ms
62,732 KB
testcase_34 AC 315 ms
62,916 KB
testcase_35 AC 318 ms
62,992 KB
testcase_36 AC 344 ms
63,060 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();
        long m = sc.nextLong();
        HashMap<Long, Integer> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong() % m;
            counts.put(x, counts.getOrDefault(x, 0) + 1);
        }
        int ans = 0;
        for (long x : counts.keySet()) {
            if (x == 0 || x * 2 == m) {
                ans++;
            } else {
                if (counts.containsKey(m - x)) {
                    if (counts.get(x) == counts.get(m - x)) {
                        if (x < m - x) {
                            ans += counts.get(x);
                        }
                    } else if (counts.get(x) > counts.get(m - x)) {
                        ans += counts.get(x);
                    }
                } else {
                    ans += counts.get(x);
                }
            }
        }
        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