結果

問題 No.45 回転寿司
ユーザー tenten
提出日時 2020-11-17 09:16:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 195 ms / 5,000 ms
コード長 626 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 74,572 KB
実行使用メモリ 54,700 KB
最終ジャッジ日時 2024-07-23 01:56:11
合計ジャッジ時間 9,495 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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];
    }
}
0