結果

問題 No.45 回転寿司
ユーザー maruyuki95maruyuki95
提出日時 2020-05-25 10:27:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 182 ms / 5,000 ms
コード長 814 bytes
コンパイル時間 2,697 ms
コンパイル使用メモリ 73,624 KB
実行使用メモリ 42,620 KB
最終ジャッジ日時 2024-04-21 03:41:20
合計ジャッジ時間 9,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
41,804 KB
testcase_01 AC 163 ms
41,628 KB
testcase_02 AC 174 ms
42,268 KB
testcase_03 AC 166 ms
42,328 KB
testcase_04 AC 160 ms
41,640 KB
testcase_05 AC 131 ms
41,088 KB
testcase_06 AC 168 ms
41,624 KB
testcase_07 AC 171 ms
42,108 KB
testcase_08 AC 147 ms
41,272 KB
testcase_09 AC 169 ms
42,620 KB
testcase_10 AC 154 ms
42,008 KB
testcase_11 AC 143 ms
41,460 KB
testcase_12 AC 170 ms
42,440 KB
testcase_13 AC 125 ms
40,612 KB
testcase_14 AC 132 ms
41,308 KB
testcase_15 AC 160 ms
41,640 KB
testcase_16 AC 149 ms
41,696 KB
testcase_17 AC 157 ms
41,656 KB
testcase_18 AC 153 ms
41,384 KB
testcase_19 AC 169 ms
42,284 KB
testcase_20 AC 124 ms
41,316 KB
testcase_21 AC 131 ms
41,784 KB
testcase_22 AC 109 ms
40,296 KB
testcase_23 AC 124 ms
41,016 KB
testcase_24 AC 119 ms
40,372 KB
testcase_25 AC 121 ms
41,116 KB
testcase_26 AC 154 ms
41,544 KB
testcase_27 AC 182 ms
42,128 KB
testcase_28 AC 153 ms
41,668 KB
testcase_29 AC 163 ms
42,132 KB
testcase_30 AC 165 ms
41,832 KB
testcase_31 AC 124 ms
40,992 KB
testcase_32 AC 112 ms
39,964 KB
testcase_33 AC 174 ms
42,228 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(sushiTastes);
		System.out.println(ret);
	}

	int execute(int[] sushiTastes) {
		int lastOnMaxTasteSum = 0;
		int lastOffMaxTasteSum = 0;

		for (int taste : sushiTastes) {
			int newLastOnMaxTasteSum = lastOffMaxTasteSum + taste;
			int newLastOffMaxTasteSum = lastOnMaxTasteSum;

			lastOnMaxTasteSum = newLastOnMaxTasteSum;
			if (lastOffMaxTasteSum <= newLastOffMaxTasteSum) {
				lastOffMaxTasteSum = newLastOffMaxTasteSum;
			}

		}

		return Math.max(lastOnMaxTasteSum, lastOffMaxTasteSum);
	}

}
0