結果

問題 No.45 回転寿司
ユーザー bambambambam
提出日時 2019-08-22 11:46:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 196 ms / 5,000 ms
コード長 695 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 77,588 KB
実行使用メモリ 54,592 KB
最終ジャッジ日時 2024-04-20 09:00:47
合計ジャッジ時間 9,553 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
54,592 KB
testcase_01 AC 169 ms
54,184 KB
testcase_02 AC 178 ms
54,320 KB
testcase_03 AC 182 ms
54,280 KB
testcase_04 AC 159 ms
54,252 KB
testcase_05 AC 138 ms
54,204 KB
testcase_06 AC 171 ms
54,304 KB
testcase_07 AC 185 ms
54,524 KB
testcase_08 AC 165 ms
54,356 KB
testcase_09 AC 159 ms
54,092 KB
testcase_10 AC 165 ms
54,400 KB
testcase_11 AC 137 ms
54,140 KB
testcase_12 AC 185 ms
54,372 KB
testcase_13 AC 130 ms
54,124 KB
testcase_14 AC 130 ms
53,952 KB
testcase_15 AC 158 ms
54,064 KB
testcase_16 AC 149 ms
54,012 KB
testcase_17 AC 155 ms
54,288 KB
testcase_18 AC 164 ms
54,144 KB
testcase_19 AC 194 ms
54,396 KB
testcase_20 AC 147 ms
54,080 KB
testcase_21 AC 146 ms
54,336 KB
testcase_22 AC 139 ms
53,996 KB
testcase_23 AC 138 ms
53,852 KB
testcase_24 AC 134 ms
53,980 KB
testcase_25 AC 116 ms
53,000 KB
testcase_26 AC 180 ms
54,164 KB
testcase_27 AC 184 ms
54,256 KB
testcase_28 AC 186 ms
54,296 KB
testcase_29 AC 184 ms
54,380 KB
testcase_30 AC 188 ms
54,308 KB
testcase_31 AC 128 ms
53,876 KB
testcase_32 AC 130 ms
54,520 KB
testcase_33 AC 196 ms
54,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		if (n > 1) {
			int[] dp = new int[n];
			int[] v = new int[n];
			for (int i = 0; i < n; i++) {
				v[i] = sc.nextInt();
			}
			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]);
			}
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, dp[i]);
			}
			System.out.println(max);
		} else {
			int v = sc.nextInt();
			System.out.println(v);
		}

	}
}
0