結果

問題 No.45 回転寿司
ユーザー core123core123
提出日時 2019-04-17 14:23:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 1,151 bytes
コンパイル時間 3,006 ms
コンパイル使用メモリ 76,036 KB
実行使用メモリ 56,716 KB
最終ジャッジ日時 2023-08-27 16:58:33
合計ジャッジ時間 9,695 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 187 ms
56,188 KB
testcase_01 AC 187 ms
56,156 KB
testcase_02 AC 192 ms
56,184 KB
testcase_03 AC 189 ms
56,616 KB
testcase_04 AC 189 ms
56,164 KB
testcase_05 AC 139 ms
56,024 KB
testcase_06 AC 191 ms
56,344 KB
testcase_07 AC 194 ms
56,008 KB
testcase_08 AC 155 ms
55,764 KB
testcase_09 AC 191 ms
56,416 KB
testcase_10 AC 182 ms
56,492 KB
testcase_11 AC 148 ms
55,816 KB
testcase_12 AC 194 ms
56,716 KB
testcase_13 AC 143 ms
55,948 KB
testcase_14 AC 140 ms
55,900 KB
testcase_15 AC 186 ms
55,980 KB
testcase_16 AC 156 ms
56,024 KB
testcase_17 AC 158 ms
55,908 KB
testcase_18 AC 158 ms
55,920 KB
testcase_19 AC 194 ms
56,580 KB
testcase_20 AC 139 ms
55,768 KB
testcase_21 AC 142 ms
55,872 KB
testcase_22 AC 128 ms
55,912 KB
testcase_23 AC 133 ms
55,984 KB
testcase_24 AC 127 ms
55,604 KB
testcase_25 AC 126 ms
56,404 KB
testcase_26 AC 186 ms
56,296 KB
testcase_27 AC 192 ms
56,276 KB
testcase_28 AC 183 ms
56,144 KB
testcase_29 AC 195 ms
54,208 KB
testcase_30 AC 194 ms
56,204 KB
testcase_31 AC 131 ms
55,792 KB
testcase_32 AC 132 ms
55,780 KB
testcase_33 AC 198 ms
56,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.*;
import static java.lang.Math.*;
public class Main{
	public static void main(String... args){
		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];
		for(int i=0;i<n;i++){
			dp[i]=v[i];
		}
		for(int i=0;i<n;i++){
			for(int j=i+2;j<n&&j<=i+3;j++){
				dp[j]=max(dp[j],dp[i]+v[j]);
			}
		}
		put(Arrays.stream(dp).max().orElse(0));
		
	}
	public static class Pair{
		final int x,y;
		Pair(int x,int y){
			this.x=x;
			this.y=y;
		}
		@Override
		public String toString(){
			return String.format("Pair(%d,%d)",x,y);
		}
	}
	public static void print(Object object){
        System.out.print(object);
    }
    public static void put(Object object) {
        System.out.println(object);
    }
    public static void put(){
        System.out.println();
    }
 
    public static void print(String format,Object... args){
        System.out.print(String.format(format,args));
    }
    public static void put(String format,Object... args) {
        System.out.println(String.format(format,args));
    }
}
0