結果

問題 No.45 回転寿司
ユーザー 37zigen37zigen
提出日時 2016-03-25 19:24:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 70,816 KB
実行使用メモリ 57,804 KB
最終ジャッジ日時 2023-08-27 14:39:04
合計ジャッジ時間 8,309 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
56,416 KB
testcase_01 AC 171 ms
55,908 KB
testcase_02 AC 172 ms
56,304 KB
testcase_03 AC 161 ms
56,360 KB
testcase_04 AC 165 ms
56,072 KB
testcase_05 AC 129 ms
55,804 KB
testcase_06 AC 161 ms
55,908 KB
testcase_07 AC 172 ms
56,604 KB
testcase_08 AC 148 ms
56,024 KB
testcase_09 AC 178 ms
56,372 KB
testcase_10 AC 161 ms
55,640 KB
testcase_11 AC 133 ms
55,644 KB
testcase_12 AC 171 ms
56,492 KB
testcase_13 AC 129 ms
55,716 KB
testcase_14 AC 129 ms
55,548 KB
testcase_15 AC 165 ms
56,184 KB
testcase_16 AC 146 ms
55,680 KB
testcase_17 AC 159 ms
55,984 KB
testcase_18 AC 146 ms
56,184 KB
testcase_19 AC 155 ms
56,248 KB
testcase_20 AC 123 ms
55,600 KB
testcase_21 AC 124 ms
55,548 KB
testcase_22 AC 114 ms
55,768 KB
testcase_23 AC 118 ms
55,676 KB
testcase_24 AC 116 ms
55,636 KB
testcase_25 AC 119 ms
55,644 KB
testcase_26 AC 167 ms
57,804 KB
testcase_27 AC 167 ms
56,836 KB
testcase_28 AC 181 ms
55,620 KB
testcase_29 AC 159 ms
56,420 KB
testcase_30 AC 162 ms
56,120 KB
testcase_31 AC 119 ms
55,596 KB
testcase_32 AC 118 ms
56,016 KB
testcase_33 AC 178 ms
56,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder045;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int[] v=new int[n];
		int[] dp=new int[n];
		for(int i=0;i<n;i++){
			v[i]=sc.nextInt();
		}
		dp[0]=v[0];
		if(n>1)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(dp[n-1]);
	}
}
0