結果

問題 No.45 回転寿司
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-14 13:52:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 698 bytes
コンパイル時間 4,249 ms
コンパイル使用メモリ 72,036 KB
実行使用メモリ 56,800 KB
最終ジャッジ日時 2023-08-27 15:31:32
合計ジャッジ時間 10,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
55,888 KB
testcase_01 AC 163 ms
55,944 KB
testcase_02 AC 160 ms
56,624 KB
testcase_03 AC 150 ms
56,172 KB
testcase_04 AC 159 ms
56,800 KB
testcase_05 AC 120 ms
55,736 KB
testcase_06 AC 156 ms
55,692 KB
testcase_07 AC 159 ms
56,016 KB
testcase_08 AC 144 ms
56,004 KB
testcase_09 AC 164 ms
55,964 KB
testcase_10 AC 149 ms
55,880 KB
testcase_11 AC 138 ms
55,748 KB
testcase_12 AC 169 ms
55,692 KB
testcase_13 AC 120 ms
55,980 KB
testcase_14 AC 125 ms
56,120 KB
testcase_15 AC 159 ms
56,080 KB
testcase_16 AC 131 ms
55,692 KB
testcase_17 AC 138 ms
56,360 KB
testcase_18 AC 144 ms
55,892 KB
testcase_19 AC 151 ms
56,472 KB
testcase_20 AC 119 ms
55,652 KB
testcase_21 AC 122 ms
55,496 KB
testcase_22 AC 115 ms
55,872 KB
testcase_23 AC 116 ms
55,536 KB
testcase_24 AC 113 ms
55,772 KB
testcase_25 AC 112 ms
55,816 KB
testcase_26 AC 161 ms
54,052 KB
testcase_27 AC 166 ms
56,288 KB
testcase_28 AC 154 ms
56,052 KB
testcase_29 AC 162 ms
56,112 KB
testcase_30 AC 153 ms
56,116 KB
testcase_31 AC 112 ms
55,880 KB
testcase_32 AC 113 ms
55,368 KB
testcase_33 AC 169 ms
56,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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();
    }
    // dp[i]は最後の寿司が寿司iの場合の美味しさの最大値を表す
    int[] dp = new int[N];
    // max[i] = max(0≦j≦i)dp[j]
    int[] max = new int[N];
    dp[0] = v[0];
    max[0] = dp[0];
    if(N > 1) {
      dp[1] = v[1];
      max[1] = Math.max(max[0], dp[1]);
    }
    for(int i = 2; i < N; i++) {
      dp[i] = v[i] + max[i - 2];
      max[i] = Math.max(dp[i], max[i - 1]); 
    }
    System.out.println(max[N - 1]);
  }
}
0