結果

問題 No.37 遊園地のアトラクション
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-18 12:12:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,763 ms / 5,000 ms
コード長 1,137 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 77,152 KB
実行使用メモリ 54,408 KB
最終ジャッジ日時 2024-04-18 19:57:11
合計ジャッジ時間 10,365 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
53,644 KB
testcase_01 AC 160 ms
54,092 KB
testcase_02 AC 173 ms
53,648 KB
testcase_03 AC 158 ms
53,964 KB
testcase_04 AC 267 ms
54,408 KB
testcase_05 AC 215 ms
54,112 KB
testcase_06 AC 136 ms
54,236 KB
testcase_07 AC 227 ms
54,260 KB
testcase_08 AC 142 ms
53,680 KB
testcase_09 AC 114 ms
53,000 KB
testcase_10 AC 241 ms
53,624 KB
testcase_11 AC 193 ms
54,104 KB
testcase_12 AC 161 ms
54,152 KB
testcase_13 AC 191 ms
54,096 KB
testcase_14 AC 158 ms
54,100 KB
testcase_15 AC 183 ms
53,572 KB
testcase_16 AC 190 ms
54,300 KB
testcase_17 AC 160 ms
53,988 KB
testcase_18 AC 234 ms
54,120 KB
testcase_19 AC 124 ms
54,096 KB
testcase_20 AC 185 ms
54,328 KB
testcase_21 AC 143 ms
54,020 KB
testcase_22 AC 1,763 ms
53,488 KB
testcase_23 AC 286 ms
53,380 KB
testcase_24 AC 196 ms
54,192 KB
testcase_25 AC 203 ms
54,252 KB
testcase_26 AC 236 ms
54,280 KB
testcase_27 AC 249 ms
53,728 KB
testcase_28 AC 154 ms
53,512 KB
testcase_29 AC 273 ms
53,776 KB
testcase_30 AC 166 ms
53,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();
    int N = sc.nextInt();
    int[] c = new int[N];
    int[] v = new int[N];
    for(int i = 0; i < N; i++) {
      c[i] = sc.nextInt();
    }
    for(int i = 0; i < N; i++) {
      v[i] = sc.nextInt();
    }
    // dp[i][j]はj時間以内にアトラクションiまで乗った場合の満足度の最大値を表す
    int[][] dp = new int[N][10001];
    for(int j = 0; j < 10001; j++) {
      int t = j;
      int va = v[0];
      while(t > 0) {
        t -= c[0];
        if(t >= 0) {
          dp[0][j] += va;
          va /= 2;
        }
      }
    }
    for(int i = 1; i < N; i++) {
      for(int j = 0; j < 10001; j++) {
        int t = j;
        int va = v[i];
        int sumv = 0;
        dp[i][j] = dp[i - 1][j];
        while(t > 0) {
          t -= c[i];
          if(t >= 0) {
            sumv += va;
            dp[i][j] = Math.max(dp[i][j], dp[i - 1][t] + sumv);
            va /= 2;
          }
        }
      }
    }
    System.out.println(dp[N - 1][T]);
  }
}
0