結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 12:44:30 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,495 bytes |
コンパイル時間 | 2,371 ms |
コンパイル使用メモリ | 78,568 KB |
実行使用メモリ | 64,856 KB |
最終ジャッジ日時 | 2024-09-16 15:05:47 |
合計ジャッジ時間 | 12,483 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
36,628 KB |
testcase_01 | AC | 310 ms
47,792 KB |
testcase_02 | AC | 54 ms
37,080 KB |
testcase_03 | AC | 53 ms
36,512 KB |
testcase_04 | AC | 52 ms
36,516 KB |
testcase_05 | AC | 52 ms
37,040 KB |
testcase_06 | AC | 260 ms
45,976 KB |
testcase_07 | AC | 371 ms
48,552 KB |
testcase_08 | AC | 320 ms
50,344 KB |
testcase_09 | AC | 330 ms
50,456 KB |
testcase_10 | AC | 326 ms
50,288 KB |
testcase_11 | AC | 322 ms
50,424 KB |
testcase_12 | AC | 327 ms
50,240 KB |
testcase_13 | AC | 53 ms
36,828 KB |
testcase_14 | AC | 52 ms
37,020 KB |
testcase_15 | AC | 52 ms
36,508 KB |
testcase_16 | AC | 54 ms
36,528 KB |
testcase_17 | AC | 51 ms
36,696 KB |
testcase_18 | AC | 328 ms
50,400 KB |
testcase_19 | AC | 323 ms
50,336 KB |
testcase_20 | AC | 330 ms
50,156 KB |
testcase_21 | AC | 321 ms
50,228 KB |
testcase_22 | AC | 321 ms
50,352 KB |
testcase_23 | WA | - |
testcase_24 | AC | 51 ms
37,028 KB |
testcase_25 | AC | 54 ms
37,096 KB |
testcase_26 | WA | - |
testcase_27 | AC | 52 ms
37,092 KB |
testcase_28 | AC | 51 ms
37,092 KB |
testcase_29 | AC | 51 ms
37,224 KB |
testcase_30 | AC | 51 ms
36,836 KB |
testcase_31 | AC | 50 ms
36,832 KB |
testcase_32 | AC | 51 ms
37,076 KB |
testcase_33 | AC | 51 ms
36,824 KB |
testcase_34 | AC | 287 ms
47,668 KB |
testcase_35 | AC | 187 ms
43,792 KB |
testcase_36 | AC | 280 ms
47,400 KB |
testcase_37 | AC | 279 ms
47,376 KB |
testcase_38 | AC | 225 ms
44,536 KB |
testcase_39 | AC | 187 ms
44,352 KB |
testcase_40 | AC | 198 ms
44,376 KB |
testcase_41 | AC | 166 ms
43,296 KB |
testcase_42 | AC | 269 ms
47,564 KB |
testcase_43 | AC | 273 ms
46,784 KB |
testcase_44 | AC | 242 ms
46,364 KB |
testcase_45 | AC | 250 ms
46,192 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 p = sc.nextInt(); int max = 0; TreeMap<Integer, Integer> map = new TreeMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); max = Math.max(max, x); int count = 0; while (x % p == 0) { x /= p; count++; } map.put(count, Math.max(map.getOrDefault(count, 0), x)); } boolean all1 = true; for (int x : map.values()) { if (x > 1) { all1 = false; break; } } int limit = (m + max - 1) / max; if (limit <= 1) { System.out.println(1); return; } if (all1) { System.out.println(-1); return; } int ans = Integer.MAX_VALUE; Integer current = 0; TreeMap<Integer, Integer> dp = new TreeMap<>(); dp.put(1, 0); while ((current = dp.higherKey(current)) != null) { for (Map.Entry<Integer, Integer> entry : map.entrySet()) { int count = entry.getKey() + 1; int value = entry.getValue(); if (value == 1) { continue; } if (current * (long)value >= limit) { ans = Math.min(ans, dp.get(current) + count); } else { if (!dp.containsKey(current * value) || dp.get(current * value) > dp.get(current) + count) { dp.put(current * value, dp.get(current) + count); } } } } System.out.println(ans + 1); } } 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }