結果

問題 No.45 回転寿司
ユーザー GBGB
提出日時 2018-04-17 12:14:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 4,855 ms
コンパイル使用メモリ 71,188 KB
実行使用メモリ 57,840 KB
最終ジャッジ日時 2023-08-27 16:21:42
合計ジャッジ時間 9,623 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
56,036 KB
testcase_01 AC 192 ms
55,916 KB
testcase_02 AC 194 ms
56,208 KB
testcase_03 AC 195 ms
56,120 KB
testcase_04 AC 184 ms
55,856 KB
testcase_05 AC 142 ms
55,704 KB
testcase_06 AC 190 ms
55,996 KB
testcase_07 AC 190 ms
55,616 KB
testcase_08 AC 157 ms
55,604 KB
testcase_09 AC 190 ms
56,228 KB
testcase_10 AC 175 ms
56,092 KB
testcase_11 AC 149 ms
56,348 KB
testcase_12 AC 192 ms
55,716 KB
testcase_13 AC 140 ms
55,624 KB
testcase_14 AC 136 ms
55,440 KB
testcase_15 AC 182 ms
56,008 KB
testcase_16 AC 156 ms
55,508 KB
testcase_17 AC 183 ms
56,076 KB
testcase_18 AC 168 ms
56,036 KB
testcase_19 AC 190 ms
56,232 KB
testcase_20 AC 137 ms
55,584 KB
testcase_21 AC 138 ms
56,140 KB
testcase_22 AC 130 ms
57,840 KB
testcase_23 AC 131 ms
53,684 KB
testcase_24 AC 128 ms
55,320 KB
testcase_25 AC 128 ms
55,964 KB
testcase_26 AC 188 ms
56,088 KB
testcase_27 AC 189 ms
56,532 KB
testcase_28 AC 188 ms
56,100 KB
testcase_29 AC 194 ms
55,656 KB
testcase_30 AC 186 ms
55,960 KB
testcase_31 AC 129 ms
55,768 KB
testcase_32 AC 129 ms
55,552 KB
testcase_33 AC 193 ms
56,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=scan.nextInt();
    int[] a=new int[n+5];
    int[] dp=new int[n+5];

    for(int i=0;i<n;i++){
      a[i]=scan.nextInt();
    }

    dp[0]=a[0];

    for(int i=1;i<n;i++){
      if(i==1){
        dp[i]=Math.max(dp[i-1],a[i]);
      }
      if(i>1){
        dp[i]=Math.max(dp[i-1],dp[i-2]+a[i]);
      }
    }
    System.out.println(dp[n-1]);
  }
}
0