結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | htensai |
提出日時 | 2020-02-21 12:47:37 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,200 bytes |
コンパイル時間 | 2,001 ms |
コンパイル使用メモリ | 79,392 KB |
実行使用メモリ | 65,416 KB |
最終ジャッジ日時 | 2024-04-27 21:27:54 |
合計ジャッジ時間 | 11,097 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
41,148 KB |
testcase_01 | AC | 103 ms
41,060 KB |
testcase_02 | AC | 119 ms
41,688 KB |
testcase_03 | AC | 118 ms
41,260 KB |
testcase_04 | AC | 108 ms
40,888 KB |
testcase_05 | AC | 114 ms
41,356 KB |
testcase_06 | AC | 119 ms
41,156 KB |
testcase_07 | AC | 118 ms
41,368 KB |
testcase_08 | AC | 112 ms
40,820 KB |
testcase_09 | AC | 117 ms
41,148 KB |
testcase_10 | AC | 542 ms
51,088 KB |
testcase_11 | AC | 605 ms
49,340 KB |
testcase_12 | AC | 936 ms
58,168 KB |
testcase_13 | AC | 475 ms
48,352 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 584 ms
51,376 KB |
testcase_17 | WA | - |
testcase_18 | AC | 860 ms
58,012 KB |
testcase_19 | AC | 618 ms
48,476 KB |
testcase_20 | AC | 815 ms
65,416 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); char op = sc.next().charAt(0); if (op == '+') { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < m; i ++ ){ int mod = sc.nextInt() % k; if (map.containsKey(mod)) { map.put(mod, map.get(mod) + 1); } else { map.put(mod, 1); } } long count = 0; for (int i = 0; i < n; i++) { int mod = sc.nextInt() % k; if (map.containsKey(k - mod)) { count += map.get(k - mod); } } System.out.println(count); } else { HashMap<Integer, Integer> mapB = new HashMap<>(); for (int i = 0; i < m; i ++ ){ int gd = gcd(sc.nextInt(), k); if (mapB.containsKey(gd)) { mapB.put(gd, mapB.get(gd) + 1); } else { mapB.put(gd, 1); } } HashMap<Integer, Integer> mapA = new HashMap<>(); for (int i = 0; i < n; i++) { int gd = gcd(sc.nextInt(), k); if (mapA.containsKey(gd)) { mapA.put(gd, mapA.get(gd) + 1); } else { mapA.put(gd, 1); } } long count = 0; for (Map.Entry<Integer, Integer> entryA : mapA.entrySet()) { for (Map.Entry<Integer, Integer> entryB : mapB.entrySet()) { if ((long)entryA.getKey() * entryB.getKey() % k == 0) { count += (long)entryA.getValue() * entryB.getValue(); } } } System.out.println(count); } } static int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); } } }