結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 12:43:12 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,495 bytes |
コンパイル時間 | 4,367 ms |
コンパイル使用メモリ | 75,104 KB |
実行使用メモリ | 63,356 KB |
最終ジャッジ日時 | 2023-10-14 21:19:00 |
合計ジャッジ時間 | 14,226 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,804 KB |
testcase_01 | AC | 289 ms
58,440 KB |
testcase_02 | WA | - |
testcase_03 | AC | 44 ms
49,464 KB |
testcase_04 | AC | 44 ms
49,660 KB |
testcase_05 | AC | 44 ms
47,504 KB |
testcase_06 | AC | 228 ms
57,248 KB |
testcase_07 | AC | 340 ms
59,756 KB |
testcase_08 | AC | 294 ms
60,564 KB |
testcase_09 | AC | 297 ms
60,664 KB |
testcase_10 | AC | 301 ms
61,144 KB |
testcase_11 | AC | 299 ms
60,552 KB |
testcase_12 | AC | 298 ms
62,336 KB |
testcase_13 | AC | 45 ms
49,388 KB |
testcase_14 | AC | 45 ms
49,576 KB |
testcase_15 | AC | 43 ms
49,436 KB |
testcase_16 | AC | 44 ms
49,392 KB |
testcase_17 | AC | 44 ms
49,476 KB |
testcase_18 | AC | 295 ms
60,800 KB |
testcase_19 | AC | 295 ms
60,952 KB |
testcase_20 | AC | 295 ms
60,700 KB |
testcase_21 | AC | 289 ms
60,868 KB |
testcase_22 | AC | 296 ms
61,204 KB |
testcase_23 | WA | - |
testcase_24 | AC | 42 ms
49,436 KB |
testcase_25 | AC | 42 ms
49,548 KB |
testcase_26 | WA | - |
testcase_27 | AC | 41 ms
49,440 KB |
testcase_28 | AC | 42 ms
49,472 KB |
testcase_29 | AC | 42 ms
49,468 KB |
testcase_30 | AC | 42 ms
49,644 KB |
testcase_31 | AC | 42 ms
49,384 KB |
testcase_32 | AC | 42 ms
49,448 KB |
testcase_33 | AC | 42 ms
49,740 KB |
testcase_34 | AC | 264 ms
59,276 KB |
testcase_35 | AC | 179 ms
55,924 KB |
testcase_36 | AC | 259 ms
57,008 KB |
testcase_37 | AC | 250 ms
58,772 KB |
testcase_38 | AC | 218 ms
55,968 KB |
testcase_39 | AC | 188 ms
55,624 KB |
testcase_40 | AC | 213 ms
55,916 KB |
testcase_41 | AC | 168 ms
56,220 KB |
testcase_42 | AC | 258 ms
58,116 KB |
testcase_43 | AC | 253 ms
58,692 KB |
testcase_44 | AC | 235 ms
57,168 KB |
testcase_45 | AC | 232 ms
57,544 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; } } if (all1) { System.out.println(-1); return; } int limit = (m + max - 1) / max; if (limit <= 1) { 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(); } }