結果

問題 No.45 回転寿司
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-15 17:30:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 454 bytes
コンパイル時間 3,416 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 56,568 KB
最終ジャッジ日時 2023-08-27 16:03:41
合計ジャッジ時間 8,657 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
55,900 KB
testcase_01 AC 168 ms
55,740 KB
testcase_02 AC 183 ms
55,952 KB
testcase_03 AC 182 ms
55,804 KB
testcase_04 AC 176 ms
56,224 KB
testcase_05 AC 132 ms
55,484 KB
testcase_06 AC 164 ms
56,152 KB
testcase_07 AC 181 ms
55,780 KB
testcase_08 AC 159 ms
56,140 KB
testcase_09 AC 180 ms
56,172 KB
testcase_10 AC 172 ms
55,980 KB
testcase_11 AC 141 ms
55,872 KB
testcase_12 AC 180 ms
56,420 KB
testcase_13 AC 134 ms
55,992 KB
testcase_14 AC 133 ms
55,764 KB
testcase_15 AC 178 ms
55,976 KB
testcase_16 AC 159 ms
55,596 KB
testcase_17 AC 174 ms
56,208 KB
testcase_18 AC 162 ms
56,032 KB
testcase_19 AC 181 ms
53,900 KB
testcase_20 AC 130 ms
55,880 KB
testcase_21 AC 132 ms
55,836 KB
testcase_22 AC 122 ms
56,076 KB
testcase_23 AC 123 ms
55,744 KB
testcase_24 AC 123 ms
55,648 KB
testcase_25 AC 122 ms
55,736 KB
testcase_26 AC 173 ms
56,076 KB
testcase_27 AC 177 ms
56,536 KB
testcase_28 AC 176 ms
56,204 KB
testcase_29 AC 181 ms
56,568 KB
testcase_30 AC 179 ms
56,308 KB
testcase_31 AC 120 ms
55,688 KB
testcase_32 AC 122 ms
55,880 KB
testcase_33 AC 184 ms
56,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		
		int[] dp = new int[n];
		dp[0] = ar[0];
		for (int i=1; i<n; i++) {
			if (i==1) {dp[i] = Math.max(dp[i-1],ar[i]);}
			if (i>1) {dp[i] = Math.max(dp[i-2]+ar[i],dp[i-1]);}
		}
		
		System.out.println(dp[n-1]);
	}
}

0