結果
問題 | No.1972 Modulo Set |
ユーザー | tenten |
提出日時 | 2023-04-19 14:09:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 395 ms / 2,000 ms |
コード長 | 2,148 bytes |
コンパイル時間 | 2,752 ms |
コンパイル使用メモリ | 89,896 KB |
実行使用メモリ | 53,340 KB |
最終ジャッジ日時 | 2024-10-14 14:08:26 |
合計ジャッジ時間 | 13,858 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
36,968 KB |
testcase_01 | AC | 55 ms
37,000 KB |
testcase_02 | AC | 55 ms
37,168 KB |
testcase_03 | AC | 186 ms
43,316 KB |
testcase_04 | AC | 190 ms
43,548 KB |
testcase_05 | AC | 202 ms
44,628 KB |
testcase_06 | AC | 231 ms
45,452 KB |
testcase_07 | AC | 285 ms
47,448 KB |
testcase_08 | AC | 196 ms
44,568 KB |
testcase_09 | AC | 115 ms
39,408 KB |
testcase_10 | AC | 210 ms
44,496 KB |
testcase_11 | AC | 285 ms
46,536 KB |
testcase_12 | AC | 157 ms
41,312 KB |
testcase_13 | AC | 116 ms
39,708 KB |
testcase_14 | AC | 125 ms
39,992 KB |
testcase_15 | AC | 292 ms
47,596 KB |
testcase_16 | AC | 309 ms
48,180 KB |
testcase_17 | AC | 222 ms
44,976 KB |
testcase_18 | AC | 58 ms
37,180 KB |
testcase_19 | AC | 277 ms
47,848 KB |
testcase_20 | AC | 299 ms
48,300 KB |
testcase_21 | AC | 215 ms
44,164 KB |
testcase_22 | AC | 268 ms
47,068 KB |
testcase_23 | AC | 358 ms
52,400 KB |
testcase_24 | AC | 238 ms
46,864 KB |
testcase_25 | AC | 281 ms
48,200 KB |
testcase_26 | AC | 325 ms
49,740 KB |
testcase_27 | AC | 371 ms
52,340 KB |
testcase_28 | AC | 248 ms
46,748 KB |
testcase_29 | AC | 293 ms
48,648 KB |
testcase_30 | AC | 330 ms
50,104 KB |
testcase_31 | AC | 122 ms
39,640 KB |
testcase_32 | AC | 329 ms
48,988 KB |
testcase_33 | AC | 391 ms
52,812 KB |
testcase_34 | AC | 394 ms
53,340 KB |
testcase_35 | AC | 395 ms
52,448 KB |
testcase_36 | AC | 392 ms
52,984 KB |
ソースコード
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(); } }