結果

問題 No.45 回転寿司
ユーザー shinwisteriashinwisteria
提出日時 2017-03-21 20:26:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 5,000 ms
コード長 742 bytes
コンパイル時間 6,412 ms
コンパイル使用メモリ 79,776 KB
実行使用メモリ 56,636 KB
最終ジャッジ日時 2023-08-27 15:24:46
合計ジャッジ時間 13,313 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
56,000 KB
testcase_01 AC 182 ms
55,728 KB
testcase_02 AC 190 ms
56,636 KB
testcase_03 AC 189 ms
56,200 KB
testcase_04 AC 173 ms
56,156 KB
testcase_05 AC 136 ms
55,916 KB
testcase_06 AC 183 ms
55,880 KB
testcase_07 AC 189 ms
56,144 KB
testcase_08 AC 157 ms
55,704 KB
testcase_09 AC 187 ms
56,260 KB
testcase_10 AC 163 ms
56,100 KB
testcase_11 AC 148 ms
56,000 KB
testcase_12 AC 192 ms
54,544 KB
testcase_13 AC 136 ms
55,696 KB
testcase_14 AC 136 ms
56,028 KB
testcase_15 AC 155 ms
55,716 KB
testcase_16 AC 161 ms
56,064 KB
testcase_17 AC 165 ms
55,884 KB
testcase_18 AC 163 ms
56,040 KB
testcase_19 AC 184 ms
55,912 KB
testcase_20 AC 135 ms
55,828 KB
testcase_21 AC 135 ms
55,580 KB
testcase_22 AC 128 ms
56,240 KB
testcase_23 AC 125 ms
55,368 KB
testcase_24 AC 126 ms
55,620 KB
testcase_25 AC 126 ms
56,204 KB
testcase_26 AC 181 ms
56,040 KB
testcase_27 AC 187 ms
55,812 KB
testcase_28 AC 183 ms
55,800 KB
testcase_29 AC 187 ms
56,140 KB
testcase_30 AC 194 ms
55,780 KB
testcase_31 AC 129 ms
55,364 KB
testcase_32 AC 128 ms
55,636 KB
testcase_33 AC 195 ms
56,100 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 MAXp = 0,MAXn = 0;
		s.close();
		if(N == 1){
			MAXp = V.get(0);
		}else {
			int D1p = V.get(1),D2p = V.get(0);
			int D1n = D2p,D2n = 0;
			if(N == 2){
				MAXp = Integer.max(D1p, D2p);
			}else{
				for(int i = 2;i<N;i++){
					MAXp = Integer.max(D2p + V.get(i),D2n + V.get(i));
					MAXn = Integer.max(D1p,D2p);
					D2p = D1p;
					D2n = D1n;
					D1p = MAXp;
					D1n = MAXn;
				}
			}
		}
		System.out.println(Integer.max(MAXp, MAXn));
	}
}
0