結果

問題 No.37 遊園地のアトラクション
ユーザー tenten
提出日時 2020-10-23 08:44:45
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,211 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 77,188 KB
実行使用メモリ 83,336 KB
最終ジャッジ日時 2024-07-21 09:49:02
合計ジャッジ時間 13,486 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 22 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

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