結果
問題 | No.1972 Modulo Set |
ユーザー | tenten |
提出日時 | 2022-06-13 11:17:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 486 ms / 2,000 ms |
コード長 | 1,485 bytes |
コンパイル時間 | 2,911 ms |
コンパイル使用メモリ | 78,456 KB |
実行使用メモリ | 52,996 KB |
最終ジャッジ日時 | 2024-04-15 09:00:09 |
合計ジャッジ時間 | 14,908 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
37,188 KB |
testcase_01 | AC | 61 ms
37,080 KB |
testcase_02 | AC | 62 ms
36,732 KB |
testcase_03 | AC | 198 ms
42,092 KB |
testcase_04 | AC | 239 ms
44,720 KB |
testcase_05 | AC | 215 ms
43,528 KB |
testcase_06 | AC | 257 ms
45,644 KB |
testcase_07 | AC | 319 ms
47,604 KB |
testcase_08 | AC | 211 ms
44,624 KB |
testcase_09 | AC | 121 ms
39,544 KB |
testcase_10 | AC | 206 ms
43,708 KB |
testcase_11 | AC | 316 ms
46,520 KB |
testcase_12 | AC | 185 ms
42,736 KB |
testcase_13 | AC | 138 ms
40,044 KB |
testcase_14 | AC | 139 ms
40,128 KB |
testcase_15 | AC | 336 ms
47,752 KB |
testcase_16 | AC | 358 ms
47,764 KB |
testcase_17 | AC | 224 ms
44,124 KB |
testcase_18 | AC | 71 ms
37,264 KB |
testcase_19 | AC | 338 ms
47,684 KB |
testcase_20 | AC | 364 ms
48,100 KB |
testcase_21 | AC | 268 ms
45,288 KB |
testcase_22 | AC | 329 ms
46,992 KB |
testcase_23 | AC | 427 ms
52,320 KB |
testcase_24 | AC | 294 ms
47,088 KB |
testcase_25 | AC | 334 ms
48,324 KB |
testcase_26 | AC | 370 ms
49,616 KB |
testcase_27 | AC | 449 ms
52,540 KB |
testcase_28 | AC | 285 ms
46,344 KB |
testcase_29 | AC | 361 ms
48,640 KB |
testcase_30 | AC | 404 ms
49,616 KB |
testcase_31 | AC | 142 ms
39,932 KB |
testcase_32 | AC | 382 ms
49,176 KB |
testcase_33 | AC | 486 ms
52,480 KB |
testcase_34 | AC | 476 ms
52,980 KB |
testcase_35 | AC | 467 ms
52,996 KB |
testcase_36 | AC | 467 ms
52,780 KB |
ソースコード
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 x = sc.nextLong() % m; counts.put(x, counts.getOrDefault(x, 0) + 1); } int sum = 0; for (long x : counts.keySet()) { if (x == 0) { n -= counts.get(x) - 1; } else if (x * 2 == m) { n -= counts.get(x) - 1; } else { sum += Math.min(counts.get(x), counts.getOrDefault(m - x, 0)); } } System.out.println(n - sum / 2); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }