結果

問題 No.37 遊園地のアトラクション
ユーザー tentententen
提出日時 2021-11-10 09:56:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 1,996 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 78,196 KB
実行使用メモリ 51,476 KB
最終ジャッジ日時 2024-04-30 20:45:28
合計ジャッジ時間 5,460 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,384 KB
testcase_01 AC 54 ms
50,120 KB
testcase_02 AC 63 ms
50,680 KB
testcase_03 AC 58 ms
50,516 KB
testcase_04 AC 64 ms
50,512 KB
testcase_05 AC 66 ms
50,296 KB
testcase_06 AC 55 ms
50,568 KB
testcase_07 AC 79 ms
51,272 KB
testcase_08 AC 54 ms
49,952 KB
testcase_09 AC 55 ms
50,448 KB
testcase_10 AC 83 ms
51,476 KB
testcase_11 AC 65 ms
50,628 KB
testcase_12 AC 61 ms
50,472 KB
testcase_13 AC 56 ms
50,084 KB
testcase_14 AC 56 ms
50,476 KB
testcase_15 AC 65 ms
50,580 KB
testcase_16 AC 65 ms
50,668 KB
testcase_17 AC 57 ms
50,440 KB
testcase_18 AC 83 ms
51,320 KB
testcase_19 AC 55 ms
50,408 KB
testcase_20 AC 66 ms
50,460 KB
testcase_21 AC 55 ms
50,296 KB
testcase_22 AC 57 ms
50,284 KB
testcase_23 AC 56 ms
50,408 KB
testcase_24 AC 56 ms
50,416 KB
testcase_25 AC 55 ms
50,444 KB
testcase_26 AC 55 ms
50,432 KB
testcase_27 AC 66 ms
50,312 KB
testcase_28 AC 55 ms
50,200 KB
testcase_29 AC 65 ms
50,620 KB
testcase_30 AC 57 ms
50,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static int[][] dp;
    static int[] costs;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        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];
        System.out.println(dfw(n - 1, t));
    }
    
    static int dfw(int idx, int t) {
        if (t < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][t] == 0) {
            int time = costs[idx];
            int atract = values[idx];
            int sum = atract;
            dp[idx][t] = dfw(idx - 1, t);
            while (time <= t && atract > 0) {
                dp[idx][t] = Math.max(dp[idx][t], dfw(idx - 1, t - time) + sum);
                time += costs[idx];
                atract /= 2;
                sum += atract;
            }
        }
        return dp[idx][t];
    }
}
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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0