結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | tenten |
提出日時 | 2022-08-30 12:48:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 545 ms / 2,000 ms |
コード長 | 2,796 bytes |
コンパイル時間 | 2,189 ms |
コンパイル使用メモリ | 79,260 KB |
実行使用メモリ | 60,920 KB |
最終ジャッジ日時 | 2024-04-24 22:46:33 |
合計ジャッジ時間 | 7,479 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
36,984 KB |
testcase_01 | AC | 47 ms
36,652 KB |
testcase_02 | AC | 47 ms
37,080 KB |
testcase_03 | AC | 46 ms
37,108 KB |
testcase_04 | AC | 46 ms
37,104 KB |
testcase_05 | AC | 49 ms
37,044 KB |
testcase_06 | AC | 48 ms
36,920 KB |
testcase_07 | AC | 48 ms
37,120 KB |
testcase_08 | AC | 48 ms
36,904 KB |
testcase_09 | AC | 47 ms
37,072 KB |
testcase_10 | AC | 306 ms
49,420 KB |
testcase_11 | AC | 288 ms
45,972 KB |
testcase_12 | AC | 539 ms
48,416 KB |
testcase_13 | AC | 241 ms
45,392 KB |
testcase_14 | AC | 315 ms
46,444 KB |
testcase_15 | AC | 261 ms
45,120 KB |
testcase_16 | AC | 337 ms
49,456 KB |
testcase_17 | AC | 222 ms
45,728 KB |
testcase_18 | AC | 545 ms
48,688 KB |
testcase_19 | AC | 339 ms
46,240 KB |
testcase_20 | AC | 517 ms
60,920 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(); int m = sc.nextInt(); int k = sc.nextInt(); if (sc.next().charAt(0) == '+') { HashMap<Integer, Long> bCounts = new HashMap<>(); for (int i = 0; i < m; i++) { int x = sc.nextInt() % k; bCounts.put(x, bCounts.getOrDefault(x, 0L) + 1); } HashMap<Integer, Long> aCounts = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt() % k; aCounts.put(x, aCounts.getOrDefault(x, 0L) + 1); } long ans = 0; for (int x : bCounts.keySet()) { if (x == 0) { ans += aCounts.getOrDefault(x, 0L) * bCounts.get(x); } else { ans += aCounts.getOrDefault(k - x, 0L) * bCounts.get(x); } } System.out.println(ans); } else { HashMap<Integer, Long> bCounts = new HashMap<>(); for (int i = 0; i < m; i++) { int x = getGCD(k, sc.nextInt()); bCounts.put(x, bCounts.getOrDefault(x, 0L) + 1); } HashMap<Integer, Long> aCounts = new HashMap<>(); for (int i = 0; i < n; i++) { int x = getGCD(k, sc.nextInt()); aCounts.put(x, aCounts.getOrDefault(x, 0L) + 1); } long ans = 0; for (int x : bCounts.keySet()) { for (int y : aCounts.keySet()) { if (y % (k / x) == 0) { ans += bCounts.get(x) * aCounts.get(y); } } } System.out.println(ans); } } static int getGCD(int x, int y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } } 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(); } }