結果

問題 No.45 回転寿司
ユーザー tsunabittsunabit
提出日時 2019-09-11 21:43:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 444 bytes
コンパイル時間 3,754 ms
コンパイル使用メモリ 71,816 KB
実行使用メモリ 56,732 KB
最終ジャッジ日時 2023-09-15 13:58:29
合計ジャッジ時間 10,881 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
55,884 KB
testcase_01 AC 177 ms
56,040 KB
testcase_02 AC 179 ms
56,732 KB
testcase_03 AC 180 ms
55,872 KB
testcase_04 AC 177 ms
56,176 KB
testcase_05 AC 136 ms
56,092 KB
testcase_06 AC 178 ms
55,896 KB
testcase_07 AC 177 ms
56,324 KB
testcase_08 AC 157 ms
56,240 KB
testcase_09 AC 179 ms
55,628 KB
testcase_10 AC 161 ms
55,820 KB
testcase_11 AC 144 ms
55,744 KB
testcase_12 AC 180 ms
56,016 KB
testcase_13 AC 131 ms
55,964 KB
testcase_14 AC 132 ms
55,472 KB
testcase_15 AC 163 ms
56,392 KB
testcase_16 AC 158 ms
56,000 KB
testcase_17 AC 161 ms
56,188 KB
testcase_18 AC 159 ms
55,880 KB
testcase_19 AC 181 ms
56,260 KB
testcase_20 AC 132 ms
56,164 KB
testcase_21 AC 134 ms
56,244 KB
testcase_22 AC 124 ms
54,736 KB
testcase_23 AC 123 ms
55,812 KB
testcase_24 AC 124 ms
55,860 KB
testcase_25 AC 124 ms
55,804 KB
testcase_26 AC 176 ms
56,080 KB
testcase_27 AC 182 ms
55,892 KB
testcase_28 AC 184 ms
56,228 KB
testcase_29 AC 180 ms
55,912 KB
testcase_30 AC 169 ms
56,464 KB
testcase_31 AC 120 ms
55,812 KB
testcase_32 AC 125 ms
55,704 KB
testcase_33 AC 186 ms
56,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No45 {
	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[] r = new int[n];
		r[0] = v[0];
		if(n > 1) r[1] = Math.max(r[0], v[1]);
		for(int i = 2; i < n; i++) r[i] = Math.max(r[i-1], r[i-2] + v[i]);
		System.out.println(r[n-1]);
	}
}
0