結果

問題 No.974 最後の日までに
ユーザー htensaihtensai
提出日時 2020-01-26 08:44:49
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,208 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 66,264 KB
最終ジャッジ日時 2023-10-12 11:53:36
合計ジャッジ時間 11,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 120 ms
55,900 KB
testcase_36 AC 120 ms
55,292 KB
testcase_37 AC 237 ms
66,264 KB
testcase_38 AC 120 ms
56,076 KB
testcase_39 AC 119 ms
55,664 KB
testcase_40 AC 170 ms
57,860 KB
testcase_41 AC 170 ms
57,932 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 120 ms
56,332 KB
testcase_50 AC 121 ms
56,200 KB
testcase_51 AC 120 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long[] incomes;
    static long[] likes;
    static long[] costs;
    static HashMap<Long, Long>[] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        incomes = new long[w + 1];
        likes = new long[w + 1];
        costs = new long[w + 1];
        dp = new HashMap[w + 1];
        for (int i = 1; i <= w; i++) {
            incomes[i] = sc.nextInt();
            likes[i] = sc.nextInt();
            costs[i] = sc.nextInt();
            dp[i] = new HashMap<Long, Long>();
        }
        
        System.out.println(dfw(w, 0));
    }
    
    static long dfw(int idx, long money) {
        if (idx == 0) {
            if (money > 0) {
                return Long.MIN_VALUE;
            } else {
                return 0;
            }
        }
        if (dp[idx].containsKey(money)) {
            return dp[idx].get(money);
        }
        long ans = dfw(idx - 1, money - incomes[idx]);
        if (idx >= 2) {
            ans = Math.max(ans, dfw(idx - 2, money + costs[idx]) + likes[idx]);
        }
        dp[idx].put(money, ans);
        return ans;
    }
    
}
0