結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2016-01-20 14:44:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 71 ms / 5,000 ms |
コード長 | 916 bytes |
コンパイル時間 | 2,306 ms |
コンパイル使用メモリ | 77,648 KB |
実行使用メモリ | 37,168 KB |
最終ジャッジ日時 | 2024-12-27 12:48:37 |
合計ジャッジ時間 | 5,533 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(stdReader.readLine()); String[] temps = stdReader.readLine().split(" "); int[] nums = new int[N]; for(int i=0;i<N;i++){ nums[i] = Integer.parseInt(temps[i]); } int[] dp = new int[N]; if(N == 1){ System.out.println(nums[0]); }else{ dp[0] = nums[0]; dp[1] = Math.max(nums[0], nums[1]); int max = 0; for(int i=2;i<N;i++){ dp[i] = Math.max(dp[i-1], dp[i-2]+nums[i]); } System.out.println(dp[N-1]); } } catch (IOException e) { e.printStackTrace(); } } }