結果

問題 No.45 回転寿司
ユーザー joybeeeejoybeeee
提出日時 2020-05-07 15:43:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 71,864 KB
実行使用メモリ 58,268 KB
最終ジャッジ日時 2023-09-16 07:54:00
合計ジャッジ時間 9,008 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
56,308 KB
testcase_01 AC 172 ms
58,268 KB
testcase_02 AC 166 ms
56,136 KB
testcase_03 AC 181 ms
56,844 KB
testcase_04 AC 178 ms
56,460 KB
testcase_05 AC 132 ms
55,448 KB
testcase_06 AC 174 ms
56,120 KB
testcase_07 AC 180 ms
56,448 KB
testcase_08 AC 159 ms
56,540 KB
testcase_09 AC 179 ms
56,264 KB
testcase_10 AC 174 ms
56,408 KB
testcase_11 AC 148 ms
55,536 KB
testcase_12 AC 184 ms
56,232 KB
testcase_13 AC 130 ms
55,864 KB
testcase_14 AC 127 ms
55,652 KB
testcase_15 AC 178 ms
56,376 KB
testcase_16 AC 159 ms
55,872 KB
testcase_17 AC 175 ms
56,232 KB
testcase_18 AC 158 ms
56,116 KB
testcase_19 AC 178 ms
56,108 KB
testcase_20 AC 131 ms
55,936 KB
testcase_21 AC 135 ms
55,872 KB
testcase_22 AC 123 ms
55,632 KB
testcase_23 AC 123 ms
55,788 KB
testcase_24 AC 123 ms
55,712 KB
testcase_25 AC 131 ms
55,688 KB
testcase_26 AC 162 ms
56,028 KB
testcase_27 AC 177 ms
56,188 KB
testcase_28 AC 177 ms
56,460 KB
testcase_29 AC 164 ms
56,092 KB
testcase_30 AC 166 ms
56,048 KB
testcase_31 AC 122 ms
55,864 KB
testcase_32 AC 126 ms
55,968 KB
testcase_33 AC 186 ms
54,680 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 prevPrev = sc.nextInt();
      if(n == 1) {
          System.out.println(prevPrev);
          return;
      }
      
      int prev = Math.max(prevPrev, sc.nextInt());
      int res = Math.max(prevPrev, prev);
      for(int i = 3; i <= n; i++) {
        int num = sc.nextInt();
        res = Math.max(num + prevPrev, prev);
        prevPrev = prev;
        prev = res;
      }
      System.out.println(res);
  }
}
0