結果

問題 No.37 遊園地のアトラクション
ユーザー tentententen
提出日時 2020-10-23 08:44:45
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,211 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 73,404 KB
実行使用メモリ 60,156 KB
最終ジャッジ日時 2023-09-28 15:07:17
合計ジャッジ時間 13,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
55,472 KB
testcase_01 AC 130 ms
55,636 KB
testcase_02 AC 154 ms
55,712 KB
testcase_03 AC 154 ms
55,788 KB
testcase_04 AC 149 ms
55,744 KB
testcase_05 AC 153 ms
55,512 KB
testcase_06 AC 148 ms
55,368 KB
testcase_07 AC 314 ms
55,440 KB
testcase_08 AC 139 ms
55,572 KB
testcase_09 AC 131 ms
55,688 KB
testcase_10 AC 260 ms
55,632 KB
testcase_11 AC 236 ms
55,460 KB
testcase_12 AC 149 ms
55,472 KB
testcase_13 AC 165 ms
55,368 KB
testcase_14 AC 142 ms
55,264 KB
testcase_15 AC 140 ms
55,932 KB
testcase_16 AC 181 ms
55,644 KB
testcase_17 AC 153 ms
55,856 KB
testcase_18 AC 245 ms
55,252 KB
testcase_19 AC 128 ms
55,820 KB
testcase_20 AC 164 ms
55,588 KB
testcase_21 AC 137 ms
55,256 KB
testcase_22 TLE -
testcase_23 AC 127 ms
55,460 KB
testcase_24 AC 127 ms
55,916 KB
testcase_25 AC 130 ms
57,800 KB
testcase_26 AC 129 ms
56,068 KB
testcase_27 AC 156 ms
55,472 KB
testcase_28 AC 129 ms
55,984 KB
testcase_29 AC 140 ms
55,852 KB
testcase_30 AC 128 ms
55,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] costs;
    static int[] values;
    static int[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int n = sc.nextInt();
        costs = new int[n];
        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new int[n][t + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(n - 1, t));
     }
     
     static int dfw(int idx, int time) {
         if (time < 0) {
             return Integer.MIN_VALUE;
         }
         if (idx < 0) {
             return 0;
         }
         if (dp[idx][time] < 0) {
             int v = values[idx];
             int t = time;
             int sum = 0;
             while (t >= 0) {
                 dp[idx][time] = Math.max(dp[idx][time], dfw(idx - 1, t) + sum);
                 sum += v;
                 v /= 2;
                 t -= costs[idx];
             }
         }
         return dp[idx][time];
     }
}
0