結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 10:23:43 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,404 bytes |
コンパイル時間 | 3,622 ms |
コンパイル使用メモリ | 78,604 KB |
実行使用メモリ | 52,320 KB |
最終ジャッジ日時 | 2024-09-16 15:01:12 |
合計ジャッジ時間 | 14,262 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
36,988 KB |
testcase_01 | AC | 293 ms
46,876 KB |
testcase_02 | WA | - |
testcase_03 | AC | 51 ms
36,960 KB |
testcase_04 | AC | 49 ms
36,820 KB |
testcase_05 | AC | 49 ms
36,800 KB |
testcase_06 | AC | 239 ms
45,396 KB |
testcase_07 | AC | 347 ms
48,480 KB |
testcase_08 | AC | 308 ms
49,856 KB |
testcase_09 | AC | 309 ms
49,992 KB |
testcase_10 | AC | 309 ms
49,756 KB |
testcase_11 | AC | 309 ms
49,796 KB |
testcase_12 | AC | 301 ms
50,164 KB |
testcase_13 | AC | 53 ms
36,860 KB |
testcase_14 | AC | 51 ms
36,692 KB |
testcase_15 | AC | 50 ms
36,520 KB |
testcase_16 | AC | 49 ms
36,924 KB |
testcase_17 | AC | 50 ms
36,864 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 342 ms
52,320 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 50 ms
36,820 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 51 ms
36,496 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 | 243 ms
45,948 KB |
testcase_45 | AC | 247 ms
45,676 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(); } }