結果

問題 No.45 回転寿司
ユーザー リチウムリチウム
提出日時 2014-10-25 15:05:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 5,000 ms
コード長 545 bytes
コンパイル時間 2,896 ms
コンパイル使用メモリ 72,356 KB
実行使用メモリ 58,124 KB
最終ジャッジ日時 2023-08-27 13:43:46
合計ジャッジ時間 8,952 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
56,028 KB
testcase_01 AC 183 ms
56,180 KB
testcase_02 AC 186 ms
56,040 KB
testcase_03 AC 187 ms
56,172 KB
testcase_04 AC 184 ms
56,304 KB
testcase_05 AC 136 ms
55,800 KB
testcase_06 AC 170 ms
56,316 KB
testcase_07 AC 185 ms
56,568 KB
testcase_08 AC 152 ms
56,072 KB
testcase_09 AC 187 ms
56,016 KB
testcase_10 AC 161 ms
56,028 KB
testcase_11 AC 144 ms
55,524 KB
testcase_12 AC 183 ms
56,256 KB
testcase_13 AC 134 ms
56,072 KB
testcase_14 AC 134 ms
55,536 KB
testcase_15 AC 184 ms
55,876 KB
testcase_16 AC 154 ms
55,748 KB
testcase_17 AC 180 ms
55,908 KB
testcase_18 AC 153 ms
55,524 KB
testcase_19 AC 188 ms
56,164 KB
testcase_20 AC 134 ms
55,676 KB
testcase_21 AC 135 ms
56,140 KB
testcase_22 AC 127 ms
55,872 KB
testcase_23 AC 125 ms
55,764 KB
testcase_24 AC 127 ms
55,828 KB
testcase_25 AC 128 ms
58,124 KB
testcase_26 AC 171 ms
56,240 KB
testcase_27 AC 188 ms
56,036 KB
testcase_28 AC 160 ms
57,396 KB
testcase_29 AC 185 ms
56,396 KB
testcase_30 AC 185 ms
56,992 KB
testcase_31 AC 127 ms
55,816 KB
testcase_32 AC 127 ms
55,888 KB
testcase_33 AC 188 ms
56,844 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 v[]=new int[n];
		for(int i=0;i<n;i++){
			v[i]=sc.nextInt();
		}
		if(n==1){
			System.out.println(v[0]);
			return;
		}
		if(n==2){
			System.out.println(Math.max(v[0],v[1]));
			return;
		}
		int ans[]=new int[n];
		ans[0]=v[0];
		ans[1]=Math.max(v[0],v[1]);
		for(int i=2;i<n;i++){
			ans[i]=Math.max(ans[i-1],ans[i-2]+v[i]);
		}
		System.out.println(ans[n-1]);
	}
	}
0