結果

問題 No.1972 Modulo Set
ユーザー tentententen
提出日時 2022-09-27 10:26:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,646 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 75,064 KB
実行使用メモリ 62,932 KB
最終ジャッジ日時 2023-08-24 03:42:43
合計ジャッジ時間 11,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,272 KB
testcase_01 AC 43 ms
49,240 KB
testcase_02 AC 43 ms
49,608 KB
testcase_03 AC 162 ms
55,908 KB
testcase_04 AC 175 ms
55,220 KB
testcase_05 AC 205 ms
56,128 KB
testcase_06 AC 224 ms
56,192 KB
testcase_07 AC 262 ms
58,340 KB
testcase_08 AC 217 ms
53,484 KB
testcase_09 AC 88 ms
52,752 KB
testcase_10 AC 168 ms
55,532 KB
testcase_11 AC 263 ms
56,348 KB
testcase_12 AC 142 ms
54,776 KB
testcase_13 AC 106 ms
52,704 KB
testcase_14 AC 111 ms
52,192 KB
testcase_15 AC 281 ms
58,496 KB
testcase_16 AC 287 ms
58,624 KB
testcase_17 AC 199 ms
55,780 KB
testcase_18 AC 46 ms
49,764 KB
testcase_19 AC 253 ms
58,624 KB
testcase_20 AC 285 ms
58,552 KB
testcase_21 AC 219 ms
55,696 KB
testcase_22 AC 245 ms
58,728 KB
testcase_23 AC 326 ms
62,576 KB
testcase_24 AC 234 ms
58,612 KB
testcase_25 AC 262 ms
58,696 KB
testcase_26 AC 296 ms
60,512 KB
testcase_27 AC 336 ms
62,660 KB
testcase_28 AC 240 ms
58,372 KB
testcase_29 AC 259 ms
58,688 KB
testcase_30 AC 303 ms
60,932 KB
testcase_31 AC 103 ms
53,012 KB
testcase_32 AC 281 ms
60,616 KB
testcase_33 AC 362 ms
62,852 KB
testcase_34 AC 351 ms
62,792 KB
testcase_35 AC 353 ms
62,784 KB
testcase_36 AC 340 ms
62,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 mod = sc.nextLong() % m;
            counts.put(mod, counts.getOrDefault(mod, 0) + 1);
        }
        int ans = 0;
        for (long x : counts.keySet()) {
            if (x == 0) {
                ans += 2;
            } else if (x * 2 == m) {
                ans += 2;
            } else {
                if (counts.containsKey(m - x)) {
                    ans += Math.max(counts.get(x), counts.get(m - x));
                } else {
                    ans += counts.get(x) * 2;
                }
            }
        }
        System.out.println(ans / 2);
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0