結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 12:44:30 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,495 bytes |
コンパイル時間 | 2,204 ms |
コンパイル使用メモリ | 75,356 KB |
実行使用メモリ | 62,868 KB |
最終ジャッジ日時 | 2023-10-14 21:19:13 |
合計ジャッジ時間 | 12,002 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,812 KB |
testcase_01 | AC | 284 ms
58,432 KB |
testcase_02 | AC | 42 ms
49,460 KB |
testcase_03 | AC | 41 ms
49,668 KB |
testcase_04 | AC | 42 ms
50,056 KB |
testcase_05 | AC | 41 ms
49,400 KB |
testcase_06 | AC | 236 ms
57,704 KB |
testcase_07 | AC | 336 ms
59,488 KB |
testcase_08 | AC | 289 ms
60,720 KB |
testcase_09 | AC | 294 ms
61,184 KB |
testcase_10 | AC | 300 ms
58,292 KB |
testcase_11 | AC | 291 ms
60,052 KB |
testcase_12 | AC | 296 ms
60,460 KB |
testcase_13 | AC | 44 ms
49,468 KB |
testcase_14 | AC | 44 ms
49,380 KB |
testcase_15 | AC | 43 ms
49,568 KB |
testcase_16 | AC | 46 ms
49,676 KB |
testcase_17 | AC | 43 ms
49,472 KB |
testcase_18 | AC | 297 ms
60,744 KB |
testcase_19 | AC | 296 ms
61,516 KB |
testcase_20 | AC | 299 ms
58,980 KB |
testcase_21 | AC | 301 ms
61,072 KB |
testcase_22 | AC | 292 ms
61,036 KB |
testcase_23 | WA | - |
testcase_24 | AC | 43 ms
49,528 KB |
testcase_25 | AC | 43 ms
49,464 KB |
testcase_26 | WA | - |
testcase_27 | AC | 45 ms
49,528 KB |
testcase_28 | AC | 44 ms
49,352 KB |
testcase_29 | AC | 43 ms
49,356 KB |
testcase_30 | AC | 43 ms
49,472 KB |
testcase_31 | AC | 44 ms
49,672 KB |
testcase_32 | AC | 43 ms
49,356 KB |
testcase_33 | AC | 43 ms
49,452 KB |
testcase_34 | AC | 271 ms
58,712 KB |
testcase_35 | AC | 188 ms
55,584 KB |
testcase_36 | AC | 263 ms
58,556 KB |
testcase_37 | AC | 250 ms
57,124 KB |
testcase_38 | AC | 233 ms
56,324 KB |
testcase_39 | AC | 200 ms
55,664 KB |
testcase_40 | AC | 206 ms
55,664 KB |
testcase_41 | AC | 171 ms
55,552 KB |
testcase_42 | AC | 255 ms
58,736 KB |
testcase_43 | AC | 267 ms
59,180 KB |
testcase_44 | AC | 231 ms
57,004 KB |
testcase_45 | AC | 233 ms
57,888 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(); } }