結果

問題 No.45 回転寿司
ユーザー kano_townkano_town
提出日時 2014-12-08 21:47:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 189 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 3,636 ms
コンパイル使用メモリ 72,048 KB
実行使用メモリ 56,956 KB
最終ジャッジ日時 2023-08-27 13:52:04
合計ジャッジ時間 10,547 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
56,956 KB
testcase_01 AC 183 ms
56,148 KB
testcase_02 AC 185 ms
56,816 KB
testcase_03 AC 185 ms
56,588 KB
testcase_04 AC 187 ms
56,380 KB
testcase_05 AC 140 ms
55,984 KB
testcase_06 AC 185 ms
56,252 KB
testcase_07 AC 189 ms
55,948 KB
testcase_08 AC 158 ms
55,876 KB
testcase_09 AC 186 ms
56,068 KB
testcase_10 AC 166 ms
56,012 KB
testcase_11 AC 146 ms
55,740 KB
testcase_12 AC 188 ms
55,988 KB
testcase_13 AC 135 ms
55,924 KB
testcase_14 AC 136 ms
55,888 KB
testcase_15 AC 178 ms
55,816 KB
testcase_16 AC 151 ms
56,240 KB
testcase_17 AC 170 ms
55,876 KB
testcase_18 AC 152 ms
55,920 KB
testcase_19 AC 183 ms
56,300 KB
testcase_20 AC 133 ms
55,568 KB
testcase_21 AC 135 ms
55,684 KB
testcase_22 AC 126 ms
56,024 KB
testcase_23 AC 127 ms
56,400 KB
testcase_24 AC 126 ms
56,092 KB
testcase_25 AC 125 ms
55,772 KB
testcase_26 AC 181 ms
55,764 KB
testcase_27 AC 182 ms
56,188 KB
testcase_28 AC 181 ms
56,296 KB
testcase_29 AC 188 ms
56,036 KB
testcase_30 AC 186 ms
56,604 KB
testcase_31 AC 125 ms
55,940 KB
testcase_32 AC 127 ms
55,628 KB
testcase_33 AC 177 ms
56,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder45 {

	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 + 1];

		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 - 2] + v[i], dp[i - 1]);
		}
		System.out.println(dp[n - 1]);
	}
}
0