結果

問題 No.1972 Modulo Set
ユーザー tentententen
提出日時 2023-02-25 12:33:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 2,085 bytes
コンパイル時間 3,678 ms
コンパイル使用メモリ 92,088 KB
実行使用メモリ 63,776 KB
最終ジャッジ日時 2023-10-11 12:03:42
合計ジャッジ時間 15,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,728 KB
testcase_01 AC 43 ms
49,584 KB
testcase_02 AC 43 ms
49,456 KB
testcase_03 AC 168 ms
55,968 KB
testcase_04 AC 178 ms
55,128 KB
testcase_05 AC 199 ms
55,808 KB
testcase_06 AC 232 ms
56,168 KB
testcase_07 AC 259 ms
58,144 KB
testcase_08 AC 204 ms
55,268 KB
testcase_09 AC 91 ms
52,528 KB
testcase_10 AC 184 ms
55,692 KB
testcase_11 AC 248 ms
56,232 KB
testcase_12 AC 139 ms
54,912 KB
testcase_13 AC 102 ms
52,564 KB
testcase_14 AC 108 ms
52,832 KB
testcase_15 AC 269 ms
58,576 KB
testcase_16 AC 265 ms
58,704 KB
testcase_17 AC 201 ms
55,920 KB
testcase_18 AC 46 ms
49,512 KB
testcase_19 AC 279 ms
58,600 KB
testcase_20 AC 281 ms
58,820 KB
testcase_21 AC 221 ms
55,960 KB
testcase_22 AC 245 ms
58,680 KB
testcase_23 AC 329 ms
63,164 KB
testcase_24 AC 238 ms
58,724 KB
testcase_25 AC 272 ms
58,672 KB
testcase_26 AC 297 ms
60,992 KB
testcase_27 AC 343 ms
62,488 KB
testcase_28 AC 236 ms
58,688 KB
testcase_29 AC 273 ms
58,592 KB
testcase_30 AC 319 ms
60,832 KB
testcase_31 AC 97 ms
52,504 KB
testcase_32 AC 298 ms
60,984 KB
testcase_33 AC 356 ms
63,688 KB
testcase_34 AC 339 ms
63,148 KB
testcase_35 AC 338 ms
63,776 KB
testcase_36 AC 373 ms
63,356 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++;
                continue;
            }
            long y = m - x;
            if (counts.get(x) > counts.getOrDefault(y, 0) || (counts.get(x) == counts.getOrDefault(y, 0) && x > y)) {
                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