結果

問題 No.45 回転寿司
ユーザー shinwisteriashinwisteria
提出日時 2017-03-21 20:02:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 594 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 73,868 KB
実行使用メモリ 58,508 KB
最終ジャッジ日時 2023-09-18 15:35:38
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
55,744 KB
testcase_01 AC 180 ms
58,508 KB
testcase_02 WA -
testcase_03 AC 183 ms
55,620 KB
testcase_04 AC 175 ms
56,676 KB
testcase_05 AC 131 ms
55,412 KB
testcase_06 AC 173 ms
58,072 KB
testcase_07 AC 179 ms
56,596 KB
testcase_08 WA -
testcase_09 AC 181 ms
53,936 KB
testcase_10 AC 175 ms
56,236 KB
testcase_11 WA -
testcase_12 AC 178 ms
56,088 KB
testcase_13 AC 131 ms
55,880 KB
testcase_14 AC 131 ms
56,344 KB
testcase_15 AC 167 ms
56,568 KB
testcase_16 WA -
testcase_17 AC 171 ms
56,056 KB
testcase_18 AC 150 ms
55,956 KB
testcase_19 WA -
testcase_20 AC 128 ms
55,872 KB
testcase_21 AC 133 ms
55,892 KB
testcase_22 AC 121 ms
55,852 KB
testcase_23 WA -
testcase_24 AC 121 ms
56,016 KB
testcase_25 AC 120 ms
55,680 KB
testcase_26 AC 172 ms
55,960 KB
testcase_27 WA -
testcase_28 AC 174 ms
56,672 KB
testcase_29 AC 177 ms
55,660 KB
testcase_30 AC 177 ms
56,044 KB
testcase_31 AC 122 ms
55,868 KB
testcase_32 AC 120 ms
53,832 KB
testcase_33 AC 191 ms
56,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Kaitenzushi { 

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		ArrayList<Integer> V = new ArrayList<>();
		for(int i = 0;i < N;i++){
			V.add(s.nextInt());	
		}
		int MAX = 0;
		s.close();
		if(N == 1){
			MAX = V.get(0);
		}else {
			int D2 = V.get(1),D1 = V.get(0);
			if(N == 2){
				MAX = Integer.max(D1, D2);
			}else{
				for(int i = 2;i<N;i++){
					MAX = Integer.max(D1+V.get(i), D2);
					D1 = D2;
					D2 = MAX;
				}
			}
		}
		System.out.println(MAX);
	}
}
0