結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 10:23:43 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,404 bytes |
コンパイル時間 | 5,707 ms |
コンパイル使用メモリ | 75,012 KB |
実行使用メモリ | 63,004 KB |
最終ジャッジ日時 | 2023-10-14 21:14:20 |
合計ジャッジ時間 | 19,344 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
49,228 KB |
testcase_01 | AC | 299 ms
57,728 KB |
testcase_02 | WA | - |
testcase_03 | AC | 45 ms
49,368 KB |
testcase_04 | AC | 45 ms
49,888 KB |
testcase_05 | AC | 45 ms
49,288 KB |
testcase_06 | AC | 239 ms
57,360 KB |
testcase_07 | AC | 353 ms
59,296 KB |
testcase_08 | AC | 308 ms
60,400 KB |
testcase_09 | AC | 306 ms
60,604 KB |
testcase_10 | AC | 302 ms
60,676 KB |
testcase_11 | AC | 300 ms
60,124 KB |
testcase_12 | AC | 306 ms
60,400 KB |
testcase_13 | AC | 48 ms
49,288 KB |
testcase_14 | AC | 47 ms
49,296 KB |
testcase_15 | AC | 46 ms
49,456 KB |
testcase_16 | AC | 46 ms
49,384 KB |
testcase_17 | AC | 45 ms
47,388 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 316 ms
63,004 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 44 ms
49,328 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 45 ms
49,196 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 241 ms
56,964 KB |
testcase_45 | AC | 237 ms
55,136 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; 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(); } }