結果

問題 No.1972 Modulo Set
ユーザー tentententen
提出日時 2023-04-19 14:09:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 2,148 bytes
コンパイル時間 2,702 ms
コンパイル使用メモリ 91,580 KB
実行使用メモリ 63,168 KB
最終ジャッジ日時 2024-04-22 15:03:18
合計ジャッジ時間 12,946 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
50,368 KB
testcase_01 AC 54 ms
50,384 KB
testcase_02 AC 53 ms
50,240 KB
testcase_03 AC 161 ms
54,992 KB
testcase_04 AC 180 ms
55,404 KB
testcase_05 AC 197 ms
55,872 KB
testcase_06 AC 214 ms
56,100 KB
testcase_07 AC 265 ms
57,800 KB
testcase_08 AC 192 ms
55,212 KB
testcase_09 AC 106 ms
52,084 KB
testcase_10 AC 191 ms
56,056 KB
testcase_11 AC 268 ms
56,268 KB
testcase_12 AC 147 ms
54,324 KB
testcase_13 AC 105 ms
52,156 KB
testcase_14 AC 116 ms
52,152 KB
testcase_15 AC 269 ms
58,464 KB
testcase_16 AC 282 ms
58,216 KB
testcase_17 AC 202 ms
55,808 KB
testcase_18 AC 56 ms
50,116 KB
testcase_19 AC 249 ms
58,388 KB
testcase_20 AC 276 ms
58,440 KB
testcase_21 AC 184 ms
56,064 KB
testcase_22 AC 247 ms
58,352 KB
testcase_23 AC 334 ms
62,772 KB
testcase_24 AC 227 ms
58,252 KB
testcase_25 AC 258 ms
58,380 KB
testcase_26 AC 298 ms
60,604 KB
testcase_27 AC 327 ms
62,612 KB
testcase_28 AC 232 ms
58,280 KB
testcase_29 AC 270 ms
58,760 KB
testcase_30 AC 306 ms
60,672 KB
testcase_31 AC 106 ms
52,088 KB
testcase_32 AC 280 ms
60,688 KB
testcase_33 AC 355 ms
63,168 KB
testcase_34 AC 349 ms
62,544 KB
testcase_35 AC 348 ms
62,536 KB
testcase_36 AC 329 ms
62,876 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) {
                ans++;
            } else if (x * 2 == m) {
                ans++;
            } else {
                int left = counts.get(x);
                int right = counts.getOrDefault(m - x, 0);
                if (left > right || (left == right && x * 2 < m)) {
                    ans += left;
                }
            }
        }
        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