結果

問題 No.1972 Modulo Set
ユーザー tentententen
提出日時 2022-09-27 10:25:40
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,645 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 74,836 KB
実行使用メモリ 63,204 KB
最終ジャッジ日時 2023-08-24 03:42:30
合計ジャッジ時間 12,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,492 KB
testcase_01 AC 42 ms
49,304 KB
testcase_02 AC 43 ms
49,392 KB
testcase_03 AC 148 ms
55,880 KB
testcase_04 AC 185 ms
55,648 KB
testcase_05 AC 171 ms
57,564 KB
testcase_06 AC 232 ms
55,772 KB
testcase_07 AC 256 ms
58,288 KB
testcase_08 AC 196 ms
55,508 KB
testcase_09 AC 104 ms
52,496 KB
testcase_10 AC 168 ms
55,448 KB
testcase_11 AC 237 ms
55,844 KB
testcase_12 AC 137 ms
54,928 KB
testcase_13 AC 104 ms
52,448 KB
testcase_14 AC 100 ms
52,412 KB
testcase_15 AC 275 ms
58,552 KB
testcase_16 AC 277 ms
58,984 KB
testcase_17 AC 192 ms
55,508 KB
testcase_18 AC 46 ms
49,452 KB
testcase_19 AC 272 ms
58,252 KB
testcase_20 AC 280 ms
58,472 KB
testcase_21 AC 215 ms
55,660 KB
testcase_22 AC 241 ms
58,676 KB
testcase_23 AC 325 ms
62,576 KB
testcase_24 AC 243 ms
58,328 KB
testcase_25 AC 278 ms
58,592 KB
testcase_26 AC 300 ms
60,300 KB
testcase_27 AC 323 ms
62,428 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 342 ms
62,656 KB
testcase_34 AC 347 ms
63,204 KB
testcase_35 AC 342 ms
62,968 KB
testcase_36 AC 335 ms
62,504 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.nextInt();
        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