結果

問題 No.45 回転寿司
ユーザー shin
提出日時 2026-06-17 16:31:13
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 965 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,685 ms
コンパイル使用メモリ 83,696 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2026-06-17 16:31:20
合計ジャッジ時間 6,192 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class No45 {

	public static void main(String[] args) throws IOException {
		
		String[] read = readStr();
		
		int N = Integer.parseInt(read[0]) , i = 0;
		String[] V = read[1].split(" ");
		
		int[] Vsum = new int[N];
		Vsum[0] = Integer.parseInt(V[0]);
		
		if(N > 1) {
			Vsum[1] = Math.max(Integer.parseInt(V[1]), Vsum[0]);
		}
		
		if(N > 2) {
			for(i = 2;i < N;i++) {
				Vsum[i] = Math.max(Vsum[i-2] + Integer.parseInt(V[i]), Vsum[i-1]);
			}
		}

		System.out.println(Vsum[N-1]);
		
	}
	
	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();

		do {
			list.add(br.readLine());
		}while(br.ready());

		br.close();

		String[] text = new String[list.size()];
		list.toArray(text);

		return text;

	}

}
0