結果

問題 No.1972 Modulo Set
ユーザー ks2mks2m
提出日時 2022-06-10 22:22:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 78,864 KB
実行使用メモリ 77,720 KB
最終ジャッジ日時 2024-04-15 08:51:47
合計ジャッジ時間 14,292 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,020 KB
testcase_01 AC 53 ms
49,964 KB
testcase_02 AC 54 ms
50,368 KB
testcase_03 AC 167 ms
55,020 KB
testcase_04 AC 204 ms
56,308 KB
testcase_05 AC 211 ms
58,132 KB
testcase_06 AC 276 ms
60,496 KB
testcase_07 AC 300 ms
62,700 KB
testcase_08 AC 230 ms
58,464 KB
testcase_09 AC 110 ms
51,920 KB
testcase_10 AC 193 ms
56,120 KB
testcase_11 AC 299 ms
62,536 KB
testcase_12 AC 148 ms
54,616 KB
testcase_13 AC 126 ms
54,136 KB
testcase_14 AC 126 ms
54,368 KB
testcase_15 AC 315 ms
63,064 KB
testcase_16 AC 349 ms
63,468 KB
testcase_17 AC 235 ms
58,216 KB
testcase_18 AC 57 ms
50,228 KB
testcase_19 AC 344 ms
63,756 KB
testcase_20 AC 312 ms
63,616 KB
testcase_21 AC 229 ms
58,456 KB
testcase_22 AC 312 ms
62,696 KB
testcase_23 AC 463 ms
68,928 KB
testcase_24 AC 262 ms
62,736 KB
testcase_25 AC 364 ms
65,528 KB
testcase_26 AC 360 ms
63,532 KB
testcase_27 AC 491 ms
75,936 KB
testcase_28 AC 273 ms
62,600 KB
testcase_29 AC 358 ms
65,380 KB
testcase_30 AC 425 ms
67,172 KB
testcase_31 AC 121 ms
51,960 KB
testcase_32 AC 446 ms
63,984 KB
testcase_33 AC 500 ms
77,720 KB
testcase_34 AC 510 ms
75,312 KB
testcase_35 AC 505 ms
75,916 KB
testcase_36 AC 530 ms
75,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long m = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		Map<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			long k = a[i] % m;
			map.put(k, map.getOrDefault(k, 0) + 1);
		}

		long m2 = m % 2 == 0 ? m / 2 : 0;
		int ans = 0;
		Set<Long> set = new HashSet<>();
		for (long key : map.keySet()) {
			int v1 = map.get(key);
			if (key == 0 || key == m2) {
				ans++;
			} else if (!set.contains(key)) {
				set.add(m - key);
				int v2 = map.getOrDefault(m - key, 0);
				ans += Math.max(v1, v2);
			}
			set.add(key);
		}
		System.out.println(ans);
	}
}
0