結果

問題 No.45 回転寿司
ユーザー tentententen
提出日時 2020-11-17 09:16:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 5,000 ms
コード長 626 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 71,424 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-09-30 07:42:01
合計ジャッジ時間 9,172 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
55,960 KB
testcase_01 AC 181 ms
56,020 KB
testcase_02 AC 188 ms
56,196 KB
testcase_03 AC 187 ms
56,032 KB
testcase_04 AC 184 ms
55,908 KB
testcase_05 AC 136 ms
55,996 KB
testcase_06 AC 170 ms
56,004 KB
testcase_07 AC 186 ms
55,920 KB
testcase_08 AC 156 ms
55,952 KB
testcase_09 AC 187 ms
56,124 KB
testcase_10 AC 169 ms
56,316 KB
testcase_11 AC 146 ms
56,140 KB
testcase_12 AC 177 ms
56,376 KB
testcase_13 AC 136 ms
56,016 KB
testcase_14 AC 134 ms
55,520 KB
testcase_15 AC 181 ms
56,348 KB
testcase_16 AC 161 ms
56,108 KB
testcase_17 AC 175 ms
55,916 KB
testcase_18 AC 152 ms
56,116 KB
testcase_19 AC 186 ms
56,372 KB
testcase_20 AC 131 ms
55,992 KB
testcase_21 AC 134 ms
55,752 KB
testcase_22 AC 126 ms
55,692 KB
testcase_23 AC 125 ms
56,080 KB
testcase_24 AC 126 ms
56,064 KB
testcase_25 AC 125 ms
56,040 KB
testcase_26 AC 178 ms
56,552 KB
testcase_27 AC 183 ms
56,380 KB
testcase_28 AC 171 ms
56,352 KB
testcase_29 AC 185 ms
56,556 KB
testcase_30 AC 182 ms
56,276 KB
testcase_31 AC 127 ms
55,676 KB
testcase_32 AC 127 ms
56,064 KB
testcase_33 AC 186 ms
56,412 KB
権限があれば一括ダウンロードができます

ソースコード

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