結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2018-02-04 21:11:20 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 64 ms / 5,000 ms |
コード長 | 796 bytes |
コンパイル時間 | 5,208 ms |
コンパイル使用メモリ | 76,604 KB |
実行使用メモリ | 37,060 KB |
最終ジャッジ日時 | 2024-12-27 18:42:14 |
合計ジャッジ時間 | 8,158 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
package me.yukicoder.lv2; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No0045 { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int cntDish = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int[] v = new int[cntDish]; int[] max = new int[cntDish]; for (int i = 0; i < cntDish; i++) { v[i] = Integer.parseInt(str[i]); } max[0] = v[0]; if (max.length > 1) { max[1] = Math.max(v[0], v[1]); for (int i = 2; i < cntDish; i++) { max[i] = Math.max(max[i - 1], max[i - 2] + v[i]); } } System.out.println(max[cntDish - 1]); } catch (IOException e) { e.printStackTrace(); } } }