結果

問題 No.45 回転寿司
ユーザー kou6839kou6839
提出日時 2014-11-22 19:18:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 196 ms / 5,000 ms
コード長 554 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 71,368 KB
実行使用メモリ 56,456 KB
最終ジャッジ日時 2023-08-27 13:49:46
合計ジャッジ時間 9,928 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
55,804 KB
testcase_01 AC 183 ms
56,444 KB
testcase_02 AC 190 ms
56,180 KB
testcase_03 AC 188 ms
56,196 KB
testcase_04 AC 185 ms
55,764 KB
testcase_05 AC 137 ms
55,720 KB
testcase_06 AC 182 ms
55,796 KB
testcase_07 AC 185 ms
55,808 KB
testcase_08 AC 163 ms
55,736 KB
testcase_09 AC 185 ms
55,540 KB
testcase_10 AC 168 ms
56,032 KB
testcase_11 AC 143 ms
55,600 KB
testcase_12 AC 186 ms
56,456 KB
testcase_13 AC 138 ms
55,592 KB
testcase_14 AC 136 ms
55,596 KB
testcase_15 AC 183 ms
55,820 KB
testcase_16 AC 154 ms
55,880 KB
testcase_17 AC 184 ms
55,796 KB
testcase_18 AC 154 ms
55,916 KB
testcase_19 AC 184 ms
55,852 KB
testcase_20 AC 132 ms
55,868 KB
testcase_21 AC 135 ms
55,608 KB
testcase_22 AC 126 ms
53,576 KB
testcase_23 AC 126 ms
55,332 KB
testcase_24 AC 136 ms
56,044 KB
testcase_25 AC 126 ms
55,896 KB
testcase_26 AC 185 ms
55,896 KB
testcase_27 AC 183 ms
56,268 KB
testcase_28 AC 183 ms
55,540 KB
testcase_29 AC 182 ms
56,116 KB
testcase_30 AC 181 ms
55,820 KB
testcase_31 AC 124 ms
55,608 KB
testcase_32 AC 125 ms
55,980 KB
testcase_33 AC 196 ms
56,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {

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