結果
問題 | No.951 【本日限定】1枚頼むともう1枚無料! |
ユーザー | htensai |
提出日時 | 2020-05-13 18:28:07 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,755 bytes |
コンパイル時間 | 2,269 ms |
コンパイル使用メモリ | 81,392 KB |
実行使用メモリ | 547,768 KB |
最終ジャッジ日時 | 2023-10-12 17:01:44 |
合計ジャッジ時間 | 10,429 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
59,900 KB |
testcase_01 | AC | 123 ms
55,876 KB |
testcase_02 | AC | 160 ms
57,848 KB |
testcase_03 | AC | 127 ms
55,804 KB |
testcase_04 | AC | 129 ms
55,940 KB |
testcase_05 | AC | 123 ms
55,908 KB |
testcase_06 | AC | 158 ms
57,608 KB |
testcase_07 | AC | 131 ms
56,196 KB |
testcase_08 | AC | 133 ms
55,536 KB |
testcase_09 | AC | 624 ms
104,060 KB |
testcase_10 | AC | 425 ms
84,340 KB |
testcase_11 | AC | 351 ms
74,436 KB |
testcase_12 | MLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
ソースコード
import java.util.*; public class Main { static ArrayList<HashMap<Integer, Integer>> dpNone = new ArrayList<>(); static ArrayList<HashMap<Integer, Integer>> dpBonus = new ArrayList<>(); static Pizza[] pizzas; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); pizzas = new Pizza[n]; for (int i = 0; i < n; i++) { pizzas[i] = new Pizza(sc.nextInt(), sc.nextInt()); dpNone.add(new HashMap<>()); dpBonus.add(new HashMap<>()); } Arrays.sort(pizzas); System.out.println(dfw(n - 1, k, false)); } static int dfw(int idx, int money, boolean hasBonus) { if (money < 0) { return Integer.MIN_VALUE / 10; } if (idx < 0) { return 0; } ArrayList<HashMap<Integer, Integer>> dp; if (hasBonus) { dp = dpBonus; } else { dp = dpNone; } if (dp.get(idx).containsKey(money)) { return dp.get(idx).get(money); } int max = 0; max = Math.max(max, dfw(idx - 1, money, hasBonus)); if (hasBonus) { max = Math.max(max, dfw(idx - 1, money, false) + pizzas[idx].value); } else { max = Math.max(max, dfw(idx - 1, money - pizzas[idx].cost, true) + pizzas[idx].value); } dp.get(idx).put(money, max); return max; } static class Pizza implements Comparable<Pizza> { int cost; int value; public Pizza(int cost, int value) { this.cost = cost; this.value = value; } public int compareTo(Pizza another) { if (cost == another.cost) { return value - another.value; } else { return cost - another.cost; } } } }