結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2017-03-21 20:26:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 196 ms / 5,000 ms |
コード長 | 742 bytes |
コンパイル時間 | 3,586 ms |
コンパイル使用メモリ | 78,064 KB |
実行使用メモリ | 42,488 KB |
最終ジャッジ日時 | 2024-12-27 16:13:40 |
合計ジャッジ時間 | 10,507 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.ArrayList; import java.util.Scanner; public class Kaitenzushi { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N = s.nextInt(); ArrayList<Integer> V = new ArrayList<>(); for(int i = 0;i < N;i++){ V.add(s.nextInt()); } int MAXp = 0,MAXn = 0; s.close(); if(N == 1){ MAXp = V.get(0); }else { int D1p = V.get(1),D2p = V.get(0); int D1n = D2p,D2n = 0; if(N == 2){ MAXp = Integer.max(D1p, D2p); }else{ for(int i = 2;i<N;i++){ MAXp = Integer.max(D2p + V.get(i),D2n + V.get(i)); MAXn = Integer.max(D1p,D2p); D2p = D1p; D2n = D1n; D1p = MAXp; D1n = MAXn; } } } System.out.println(Integer.max(MAXp, MAXn)); } }