結果

問題 No.45 回転寿司
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-14 13:50:57
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 672 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 74,356 KB
実行使用メモリ 57,816 KB
最終ジャッジ日時 2023-10-25 01:20:37
合計ジャッジ時間 9,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
57,712 KB
testcase_01 AC 183 ms
57,712 KB
testcase_02 AC 180 ms
57,716 KB
testcase_03 AC 190 ms
57,684 KB
testcase_04 AC 189 ms
57,700 KB
testcase_05 AC 148 ms
57,556 KB
testcase_06 AC 181 ms
57,484 KB
testcase_07 AC 185 ms
55,704 KB
testcase_08 AC 170 ms
57,736 KB
testcase_09 AC 190 ms
57,712 KB
testcase_10 AC 184 ms
57,564 KB
testcase_11 AC 166 ms
55,656 KB
testcase_12 AC 186 ms
57,720 KB
testcase_13 AC 144 ms
57,676 KB
testcase_14 AC 144 ms
57,476 KB
testcase_15 AC 186 ms
57,492 KB
testcase_16 AC 166 ms
57,712 KB
testcase_17 AC 183 ms
57,492 KB
testcase_18 AC 164 ms
57,676 KB
testcase_19 AC 189 ms
57,724 KB
testcase_20 AC 143 ms
57,612 KB
testcase_21 AC 142 ms
57,672 KB
testcase_22 AC 133 ms
57,704 KB
testcase_23 AC 133 ms
57,512 KB
testcase_24 AC 132 ms
55,700 KB
testcase_25 RE -
testcase_26 AC 183 ms
57,668 KB
testcase_27 AC 185 ms
57,816 KB
testcase_28 AC 191 ms
57,728 KB
testcase_29 AC 193 ms
57,696 KB
testcase_30 AC 191 ms
57,744 KB
testcase_31 AC 134 ms
57,484 KB
testcase_32 AC 134 ms
57,456 KB
testcase_33 AC 185 ms
57,532 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];
    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