結果

問題 No.45 回転寿司
ユーザー YamaKasaYamaKasa
提出日時 2018-06-24 00:38:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 567 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 71,644 KB
実行使用メモリ 58,056 KB
最終ジャッジ日時 2023-08-27 16:31:29
合計ジャッジ時間 7,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
55,972 KB
testcase_01 AC 157 ms
56,200 KB
testcase_02 AC 157 ms
58,056 KB
testcase_03 AC 158 ms
56,684 KB
testcase_04 AC 153 ms
56,328 KB
testcase_05 AC 121 ms
56,000 KB
testcase_06 AC 152 ms
56,636 KB
testcase_07 AC 158 ms
56,420 KB
testcase_08 AC 130 ms
56,036 KB
testcase_09 AC 151 ms
56,248 KB
testcase_10 AC 149 ms
56,020 KB
testcase_11 AC 122 ms
55,748 KB
testcase_12 AC 159 ms
53,996 KB
testcase_13 AC 116 ms
56,252 KB
testcase_14 AC 112 ms
55,796 KB
testcase_15 AC 158 ms
56,180 KB
testcase_16 AC 129 ms
56,032 KB
testcase_17 AC 142 ms
56,292 KB
testcase_18 AC 127 ms
56,096 KB
testcase_19 AC 147 ms
56,196 KB
testcase_20 AC 117 ms
55,812 KB
testcase_21 AC 116 ms
56,568 KB
testcase_22 AC 109 ms
55,800 KB
testcase_23 AC 109 ms
55,980 KB
testcase_24 AC 108 ms
55,504 KB
testcase_25 AC 108 ms
55,616 KB
testcase_26 AC 144 ms
56,200 KB
testcase_27 AC 157 ms
56,592 KB
testcase_28 AC 157 ms
55,780 KB
testcase_29 AC 156 ms
56,332 KB
testcase_30 AC 155 ms
56,164 KB
testcase_31 AC 106 ms
55,752 KB
testcase_32 AC 107 ms
55,784 KB
testcase_33 AC 159 ms
56,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int []V = new int[N];
		for(int i = 0; i < N; i++) {
			V[i] = scan.nextInt();
		}
		scan.close();
		if(N == 1) {
			System.out.println(V[0]);
			System.exit(0);
		}
		int []dp = new int[N];
		Arrays.fill(dp, 0);
		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(dp[N - 1]);

	}
}
0