結果

問題 No.45 回転寿司
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-15 17:33:04
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 624 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 71,456 KB
実行使用メモリ 57,648 KB
最終ジャッジ日時 2023-08-27 01:47:06
合計ジャッジ時間 8,845 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
56,048 KB
testcase_01 AC 169 ms
56,136 KB
testcase_02 AC 171 ms
55,552 KB
testcase_03 AC 160 ms
56,160 KB
testcase_04 AC 171 ms
56,296 KB
testcase_05 AC 132 ms
55,524 KB
testcase_06 AC 159 ms
57,648 KB
testcase_07 AC 171 ms
56,364 KB
testcase_08 AC 146 ms
55,616 KB
testcase_09 AC 169 ms
55,952 KB
testcase_10 AC 167 ms
56,032 KB
testcase_11 AC 132 ms
55,860 KB
testcase_12 AC 171 ms
56,744 KB
testcase_13 AC 127 ms
55,564 KB
testcase_14 AC 126 ms
55,864 KB
testcase_15 AC 167 ms
56,300 KB
testcase_16 AC 142 ms
55,824 KB
testcase_17 AC 157 ms
55,988 KB
testcase_18 AC 155 ms
55,668 KB
testcase_19 AC 170 ms
56,236 KB
testcase_20 AC 122 ms
55,624 KB
testcase_21 AC 125 ms
55,664 KB
testcase_22 AC 119 ms
55,556 KB
testcase_23 AC 117 ms
55,596 KB
testcase_24 AC 116 ms
55,768 KB
testcase_25 RE -
testcase_26 AC 170 ms
55,728 KB
testcase_27 AC 165 ms
56,264 KB
testcase_28 AC 168 ms
55,620 KB
testcase_29 AC 176 ms
56,156 KB
testcase_30 AC 162 ms
55,900 KB
testcase_31 AC 119 ms
55,584 KB
testcase_32 AC 113 ms
55,704 KB
testcase_33 AC 171 ms
56,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		
		int[] dp = new int[n];
		dp[0] = ar[0]; //流れてきたのが1皿のときは、その1皿のみに美味しさを求めるしかない
		dp[1] = Math.max(ar[0],ar[1]); //2皿のときは、1皿目をとるか、2皿目をとるかのどちらかである
		for (int i=1; i<n; i++) {
			if (i>1) {dp[i] = Math.max(dp[i-2]+ar[i],dp[i-1]);}
		}
		
		System.out.println(dp[n-1]);
	}
}

0