結果

問題 No.37 遊園地のアトラクション
ユーザー tentententen
提出日時 2021-12-02 16:12:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 1,985 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 75,308 KB
実行使用メモリ 51,812 KB
最終ジャッジ日時 2023-09-18 10:21:24
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,520 KB
testcase_01 AC 44 ms
49,228 KB
testcase_02 AC 58 ms
50,872 KB
testcase_03 AC 46 ms
49,212 KB
testcase_04 AC 56 ms
51,124 KB
testcase_05 AC 58 ms
50,972 KB
testcase_06 AC 43 ms
49,228 KB
testcase_07 AC 60 ms
50,900 KB
testcase_08 AC 44 ms
49,528 KB
testcase_09 AC 43 ms
49,396 KB
testcase_10 AC 67 ms
51,812 KB
testcase_11 AC 56 ms
50,756 KB
testcase_12 AC 50 ms
49,324 KB
testcase_13 AC 45 ms
49,168 KB
testcase_14 AC 43 ms
49,216 KB
testcase_15 AC 56 ms
50,860 KB
testcase_16 AC 57 ms
51,252 KB
testcase_17 AC 47 ms
49,308 KB
testcase_18 AC 70 ms
51,348 KB
testcase_19 AC 42 ms
49,576 KB
testcase_20 AC 59 ms
50,896 KB
testcase_21 AC 42 ms
49,228 KB
testcase_22 AC 47 ms
49,304 KB
testcase_23 AC 42 ms
49,184 KB
testcase_24 AC 43 ms
49,584 KB
testcase_25 AC 43 ms
51,304 KB
testcase_26 AC 44 ms
49,280 KB
testcase_27 AC 69 ms
51,768 KB
testcase_28 AC 44 ms
49,200 KB
testcase_29 AC 56 ms
50,760 KB
testcase_30 AC 44 ms
49,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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