結果

問題 No.45 回転寿司
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-14 15:25:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 444 bytes
コンパイル時間 5,249 ms
コンパイル使用メモリ 71,948 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-08-27 16:02:18
合計ジャッジ時間 11,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
55,956 KB
testcase_01 AC 197 ms
55,824 KB
testcase_02 AC 193 ms
56,164 KB
testcase_03 AC 191 ms
56,424 KB
testcase_04 AC 190 ms
54,128 KB
testcase_05 AC 141 ms
55,796 KB
testcase_06 AC 180 ms
56,128 KB
testcase_07 AC 189 ms
55,932 KB
testcase_08 AC 158 ms
55,820 KB
testcase_09 AC 192 ms
55,672 KB
testcase_10 AC 186 ms
55,748 KB
testcase_11 AC 148 ms
55,544 KB
testcase_12 AC 192 ms
56,296 KB
testcase_13 AC 142 ms
55,768 KB
testcase_14 AC 137 ms
55,756 KB
testcase_15 AC 184 ms
55,912 KB
testcase_16 AC 166 ms
56,020 KB
testcase_17 AC 177 ms
55,632 KB
testcase_18 AC 159 ms
55,960 KB
testcase_19 AC 191 ms
55,792 KB
testcase_20 AC 136 ms
55,836 KB
testcase_21 AC 140 ms
55,404 KB
testcase_22 AC 130 ms
56,096 KB
testcase_23 AC 130 ms
55,408 KB
testcase_24 AC 130 ms
55,688 KB
testcase_25 AC 131 ms
55,756 KB
testcase_26 AC 186 ms
55,972 KB
testcase_27 AC 189 ms
56,164 KB
testcase_28 AC 191 ms
56,000 KB
testcase_29 AC 193 ms
55,972 KB
testcase_30 AC 187 ms
56,088 KB
testcase_31 AC 128 ms
55,520 KB
testcase_32 AC 129 ms
55,808 KB
testcase_33 AC 189 ms
55,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No45 {
	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();
		}
		int dp[] = new int[N];
		dp[0] = V[0];
		if(N >= 2) {
			dp[1] = Math.max(dp[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