結果

問題 No.45 回転寿司
ユーザー amyuamyu
提出日時 2017-12-01 11:16:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 71,400 KB
実行使用メモリ 57,872 KB
最終ジャッジ日時 2023-08-27 15:51:44
合計ジャッジ時間 9,657 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
55,956 KB
testcase_01 AC 196 ms
55,848 KB
testcase_02 AC 195 ms
56,240 KB
testcase_03 AC 193 ms
55,804 KB
testcase_04 AC 193 ms
55,892 KB
testcase_05 AC 141 ms
55,680 KB
testcase_06 AC 192 ms
55,608 KB
testcase_07 AC 198 ms
53,896 KB
testcase_08 AC 163 ms
55,908 KB
testcase_09 AC 195 ms
56,036 KB
testcase_10 AC 161 ms
57,572 KB
testcase_11 AC 150 ms
55,676 KB
testcase_12 AC 195 ms
56,648 KB
testcase_13 AC 143 ms
55,616 KB
testcase_14 AC 140 ms
55,452 KB
testcase_15 AC 190 ms
55,600 KB
testcase_16 AC 167 ms
55,552 KB
testcase_17 AC 174 ms
55,800 KB
testcase_18 AC 160 ms
56,096 KB
testcase_19 AC 192 ms
55,648 KB
testcase_20 AC 138 ms
55,840 KB
testcase_21 AC 139 ms
55,616 KB
testcase_22 AC 129 ms
55,860 KB
testcase_23 AC 130 ms
55,696 KB
testcase_24 AC 131 ms
55,700 KB
testcase_25 AC 130 ms
55,516 KB
testcase_26 AC 179 ms
53,836 KB
testcase_27 AC 192 ms
55,916 KB
testcase_28 AC 188 ms
55,600 KB
testcase_29 AC 188 ms
57,872 KB
testcase_30 AC 192 ms
55,908 KB
testcase_31 AC 133 ms
55,716 KB
testcase_32 AC 132 ms
55,612 KB
testcase_33 AC 194 ms
55,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for(int i=0;i<n;i++){
			v[i] = sc.nextInt();
		}
		int[] dp = new int[n];
		dp[0] = v[0];
		for(int i=1;i<n;i++){
			if(i==1){
				dp[i] = Math.max(v[i],v[i-1]);
			}
			else{
				dp[i] = Math.max(dp[i-2]+v[i],dp[i-1]);
			}
		}
		System.out.println(dp[n-1]);
	}
}
0