結果

問題 No.45 回転寿司
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-06 05:28:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 168 ms / 5,000 ms
コード長 617 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 71,268 KB
実行使用メモリ 56,552 KB
最終ジャッジ日時 2023-08-27 15:15:08
合計ジャッジ時間 8,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
56,316 KB
testcase_01 AC 160 ms
56,040 KB
testcase_02 AC 168 ms
56,368 KB
testcase_03 AC 163 ms
56,104 KB
testcase_04 AC 153 ms
56,552 KB
testcase_05 AC 118 ms
55,844 KB
testcase_06 AC 157 ms
56,304 KB
testcase_07 AC 161 ms
56,212 KB
testcase_08 AC 140 ms
55,900 KB
testcase_09 AC 166 ms
55,908 KB
testcase_10 AC 147 ms
56,240 KB
testcase_11 AC 133 ms
56,248 KB
testcase_12 AC 148 ms
56,264 KB
testcase_13 AC 118 ms
55,556 KB
testcase_14 AC 117 ms
56,280 KB
testcase_15 AC 154 ms
55,976 KB
testcase_16 AC 145 ms
56,376 KB
testcase_17 AC 142 ms
55,940 KB
testcase_18 AC 135 ms
56,104 KB
testcase_19 AC 155 ms
56,188 KB
testcase_20 AC 120 ms
54,420 KB
testcase_21 AC 120 ms
55,984 KB
testcase_22 AC 115 ms
56,040 KB
testcase_23 AC 113 ms
55,716 KB
testcase_24 AC 112 ms
55,876 KB
testcase_25 AC 114 ms
55,980 KB
testcase_26 AC 160 ms
56,128 KB
testcase_27 AC 161 ms
55,868 KB
testcase_28 AC 165 ms
55,868 KB
testcase_29 AC 160 ms
56,120 KB
testcase_30 AC 162 ms
56,280 KB
testcase_31 AC 115 ms
55,636 KB
testcase_32 AC 112 ms
55,976 KB
testcase_33 AC 168 ms
56,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] V = new int [N];
        for(int i=0; i<N; i++){
            V[i]=sc.nextInt();
        }
        if(N==1){
            System.out.println(V[0]);
        }else{
            int [] dp = new int [N];
            dp[0]=V[0];
            dp[1]=Math.max(V[0],V[1]);
            for(int i=2; i<N; i++){
                dp[i]=Math.max(dp[i-1],dp[i-2]+V[i]);
            }
            System.out.println(Math.max(dp[N-1],dp[N-2]));
        }
    }
}
0