結果
問題 | No.1972 Modulo Set |
ユーザー | tenten |
提出日時 | 2023-08-08 14:10:19 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 2,332 bytes |
コンパイル時間 | 2,590 ms |
コンパイル使用メモリ | 97,136 KB |
実行使用メモリ | 53,092 KB |
最終ジャッジ日時 | 2024-11-08 19:51:31 |
合計ジャッジ時間 | 13,199 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
36,892 KB |
testcase_01 | AC | 50 ms
36,708 KB |
testcase_02 | AC | 51 ms
36,760 KB |
testcase_03 | AC | 161 ms
42,840 KB |
testcase_04 | AC | 195 ms
44,808 KB |
testcase_05 | AC | 167 ms
44,452 KB |
testcase_06 | AC | 206 ms
45,436 KB |
testcase_07 | AC | 253 ms
47,828 KB |
testcase_08 | AC | 204 ms
44,404 KB |
testcase_09 | AC | 103 ms
39,168 KB |
testcase_10 | AC | 195 ms
44,764 KB |
testcase_11 | AC | 252 ms
46,592 KB |
testcase_12 | AC | 141 ms
41,672 KB |
testcase_13 | AC | 109 ms
39,808 KB |
testcase_14 | AC | 112 ms
39,784 KB |
testcase_15 | AC | 282 ms
48,188 KB |
testcase_16 | AC | 290 ms
48,736 KB |
testcase_17 | AC | 216 ms
44,988 KB |
testcase_18 | AC | 52 ms
36,884 KB |
testcase_19 | AC | 282 ms
47,964 KB |
testcase_20 | AC | 289 ms
48,724 KB |
testcase_21 | AC | 212 ms
44,820 KB |
testcase_22 | AC | 252 ms
47,348 KB |
testcase_23 | AC | 339 ms
52,284 KB |
testcase_24 | AC | 210 ms
47,032 KB |
testcase_25 | AC | 245 ms
48,080 KB |
testcase_26 | AC | 301 ms
49,788 KB |
testcase_27 | AC | 360 ms
52,456 KB |
testcase_28 | AC | 219 ms
46,820 KB |
testcase_29 | AC | 260 ms
48,548 KB |
testcase_30 | AC | 301 ms
50,084 KB |
testcase_31 | AC | 112 ms
39,680 KB |
testcase_32 | AC | 286 ms
49,016 KB |
testcase_33 | AC | 350 ms
52,860 KB |
testcase_34 | AC | 339 ms
52,652 KB |
testcase_35 | AC | 331 ms
52,832 KB |
testcase_36 | AC | 330 ms
53,092 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 || x * 2 == m) { ans++; } else { if (counts.containsKey(m - x)) { if (counts.get(x) == counts.get(m - x)) { if (x < m - x) { ans += counts.get(x); } } else if (counts.get(x) > counts.get(m - x)) { ans += counts.get(x); } } else { ans += counts.get(x); } } } 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(); } }