結果
| 問題 | No.45 回転寿司 |
| ユーザー |
tenten
|
| 提出日時 | 2020-11-17 09:16:22 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 5,000 ms |
| コード長 | 626 bytes |
| 記録 | |
| コンパイル時間 | 1,638 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 45,896 KB |
| 最終ジャッジ日時 | 2026-04-03 12:03:48 |
| 合計ジャッジ時間 | 6,883 ms |
|
ジャッジサーバーID (参考情報) |
judge5_1 / judge4_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
import java.util.*;
public class Main {
static int[] values;
static int[] dp;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
values = new int[n];
for (int i = 0; i < n; i++) {
values[i] = sc.nextInt();
}
dp = new int[n];
System.out.println(dfw(n - 1));
}
static int dfw(int idx) {
if (idx < 0) {
return 0;
}
if (dp[idx] == 0) {
dp[idx] = Math.max(dfw(idx - 1), dfw(idx - 2) + values[idx]);
}
return dp[idx];
}
}
tenten