結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-23 08:58:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,220 bytes |
| コンパイル時間 | 2,153 ms |
| コンパイル使用メモリ | 77,204 KB |
| 実行使用メモリ | 41,912 KB |
| 最終ジャッジ日時 | 2024-07-21 09:49:37 |
| 合計ジャッジ時間 | 6,479 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 8 WA * 19 |
ソースコード
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 && v > 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];
}
}
tenten