結果

問題 No.45 回転寿司
ユーザー maruyuki95maruyuki95
提出日時 2020-05-25 10:19:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 3,423 ms
コンパイル使用メモリ 74,864 KB
実行使用メモリ 42,508 KB
最終ジャッジ日時 2024-04-21 03:41:11
合計ジャッジ時間 9,494 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
41,600 KB
testcase_01 AC 180 ms
42,332 KB
testcase_02 AC 193 ms
42,308 KB
testcase_03 AC 190 ms
42,020 KB
testcase_04 AC 194 ms
42,072 KB
testcase_05 AC 146 ms
41,440 KB
testcase_06 AC 171 ms
42,224 KB
testcase_07 AC 167 ms
41,956 KB
testcase_08 AC 157 ms
41,772 KB
testcase_09 AC 184 ms
42,408 KB
testcase_10 AC 169 ms
41,296 KB
testcase_11 AC 153 ms
41,068 KB
testcase_12 AC 181 ms
42,040 KB
testcase_13 AC 145 ms
41,600 KB
testcase_14 AC 137 ms
41,448 KB
testcase_15 AC 174 ms
42,156 KB
testcase_16 AC 165 ms
41,636 KB
testcase_17 AC 172 ms
41,728 KB
testcase_18 AC 166 ms
41,740 KB
testcase_19 AC 198 ms
42,092 KB
testcase_20 AC 143 ms
41,436 KB
testcase_21 AC 139 ms
41,284 KB
testcase_22 AC 118 ms
39,964 KB
testcase_23 AC 136 ms
41,192 KB
testcase_24 AC 132 ms
41,108 KB
testcase_25 AC 134 ms
41,100 KB
testcase_26 AC 180 ms
41,608 KB
testcase_27 AC 186 ms
42,432 KB
testcase_28 AC 171 ms
41,712 KB
testcase_29 AC 181 ms
42,508 KB
testcase_30 AC 177 ms
42,284 KB
testcase_31 AC 130 ms
40,784 KB
testcase_32 AC 137 ms
41,400 KB
testcase_33 AC 194 ms
42,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sushiNum = sc.nextInt();
		int[] sushiTastes = new int[sushiNum];
		for (int i = 0; i < sushiNum; i++) {
			sushiTastes[i] = sc.nextInt();
		}

		int ret = new Main().execute(sushiNum, sushiTastes);
		System.out.println(ret);
	}

	int execute(int sushiNum, int[] sushiTastes) {
		int lastOnMaxTasteSum = 0;
		int lastOffMaxTasteSum = 0;
		boolean lastOff = true;

		for (int taste : sushiTastes) {
			if (lastOff) {
				lastOnMaxTasteSum = lastOffMaxTasteSum + taste;
				lastOff = false;
			} else {
				int newLastOnMaxTasteSum = lastOffMaxTasteSum + taste;
				int newLastOffMaxTasteSum = lastOnMaxTasteSum;

				lastOnMaxTasteSum = newLastOnMaxTasteSum;
				lastOffMaxTasteSum = newLastOffMaxTasteSum;

				if (lastOnMaxTasteSum <= lastOffMaxTasteSum) {
					lastOff = true;
				}
			}

		}

		return Math.max(lastOnMaxTasteSum, lastOffMaxTasteSum);
	}

}
0