結果
問題 | No.1330 Multiply or Divide |
ユーザー | tenten |
提出日時 | 2021-08-04 12:43:12 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,495 bytes |
コンパイル時間 | 4,478 ms |
コンパイル使用メモリ | 78,380 KB |
実行使用メモリ | 52,600 KB |
最終ジャッジ日時 | 2024-09-16 15:05:34 |
合計ジャッジ時間 | 13,342 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,940 KB |
testcase_01 | AC | 309 ms
47,472 KB |
testcase_02 | WA | - |
testcase_03 | AC | 51 ms
37,088 KB |
testcase_04 | AC | 50 ms
36,488 KB |
testcase_05 | AC | 50 ms
36,540 KB |
testcase_06 | AC | 257 ms
46,700 KB |
testcase_07 | AC | 375 ms
48,316 KB |
testcase_08 | AC | 322 ms
49,948 KB |
testcase_09 | AC | 319 ms
50,568 KB |
testcase_10 | AC | 317 ms
50,292 KB |
testcase_11 | AC | 319 ms
50,456 KB |
testcase_12 | AC | 320 ms
50,236 KB |
testcase_13 | AC | 54 ms
36,912 KB |
testcase_14 | AC | 52 ms
36,932 KB |
testcase_15 | AC | 53 ms
36,908 KB |
testcase_16 | AC | 52 ms
37,224 KB |
testcase_17 | AC | 51 ms
37,028 KB |
testcase_18 | AC | 326 ms
49,960 KB |
testcase_19 | AC | 320 ms
50,396 KB |
testcase_20 | AC | 324 ms
50,340 KB |
testcase_21 | AC | 323 ms
50,332 KB |
testcase_22 | AC | 321 ms
50,460 KB |
testcase_23 | WA | - |
testcase_24 | AC | 50 ms
36,912 KB |
testcase_25 | AC | 52 ms
36,968 KB |
testcase_26 | WA | - |
testcase_27 | AC | 53 ms
37,108 KB |
testcase_28 | AC | 52 ms
36,696 KB |
testcase_29 | AC | 51 ms
36,972 KB |
testcase_30 | AC | 52 ms
36,656 KB |
testcase_31 | AC | 52 ms
37,084 KB |
testcase_32 | AC | 51 ms
36,964 KB |
testcase_33 | AC | 51 ms
37,012 KB |
testcase_34 | AC | 283 ms
47,352 KB |
testcase_35 | AC | 184 ms
44,500 KB |
testcase_36 | AC | 280 ms
47,360 KB |
testcase_37 | AC | 276 ms
47,364 KB |
testcase_38 | AC | 230 ms
44,592 KB |
testcase_39 | AC | 206 ms
44,236 KB |
testcase_40 | AC | 209 ms
44,708 KB |
testcase_41 | AC | 185 ms
43,456 KB |
testcase_42 | AC | 269 ms
46,684 KB |
testcase_43 | AC | 272 ms
46,752 KB |
testcase_44 | AC | 252 ms
46,000 KB |
testcase_45 | AC | 259 ms
46,256 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(); } }