結果

問題 No.37 遊園地のアトラクション
ユーザー htensaihtensai
提出日時 2019-12-07 10:38:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 77,244 KB
実行使用メモリ 54,284 KB
最終ジャッジ日時 2024-04-18 20:12:02
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
54,236 KB
testcase_01 AC 120 ms
53,496 KB
testcase_02 AC 133 ms
54,076 KB
testcase_03 AC 141 ms
54,232 KB
testcase_04 AC 121 ms
53,900 KB
testcase_05 AC 130 ms
54,012 KB
testcase_06 AC 104 ms
52,588 KB
testcase_07 AC 125 ms
54,264 KB
testcase_08 AC 124 ms
54,032 KB
testcase_09 AC 121 ms
54,048 KB
testcase_10 AC 125 ms
53,992 KB
testcase_11 AC 138 ms
54,284 KB
testcase_12 AC 130 ms
54,164 KB
testcase_13 AC 123 ms
54,132 KB
testcase_14 AC 120 ms
54,120 KB
testcase_15 AC 133 ms
54,120 KB
testcase_16 AC 143 ms
54,032 KB
testcase_17 AC 115 ms
53,984 KB
testcase_18 AC 124 ms
54,000 KB
testcase_19 AC 116 ms
54,052 KB
testcase_20 AC 126 ms
53,984 KB
testcase_21 AC 122 ms
54,020 KB
testcase_22 AC 149 ms
54,164 KB
testcase_23 AC 125 ms
54,128 KB
testcase_24 AC 125 ms
53,988 KB
testcase_25 AC 124 ms
54,084 KB
testcase_26 AC 127 ms
54,168 KB
testcase_27 AC 142 ms
54,024 KB
testcase_28 AC 114 ms
52,956 KB
testcase_29 AC 145 ms
54,236 KB
testcase_30 AC 131 ms
53,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int t;
    static int n;
    static int[] tArr;
    static int[] vArr;
    static int[][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		t = sc.nextInt();
		n = sc.nextInt();
		tArr = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    tArr[i] = sc.nextInt();
		}
		vArr = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    vArr[i] = sc.nextInt();
		}
		dp = new int[n + 1][t + 1];
		System.out.println(dfw(n, t));
   }
   
   static int dfw(int idx, int time) {
       if (idx == 0) {
           return 0;
       }
       if (dp[idx][time] != 0) {
           return dp[idx][time];
       }
       int value = vArr[idx];
       int total = 0;
       for (int i = 0; i * tArr[idx] <= time ; i++) {
           dp[idx][time] = Math.max(dp[idx][time], total + dfw(idx - 1, time - i * tArr[idx]));
           if (value <= 0) {
               break;
           }
           total += value;
           value /= 2;
       }
       return dp[idx][time];
   }
}

0