結果
| 問題 | No.45 回転寿司 |
| ユーザー |
kohaku_kohaku
|
| 提出日時 | 2016-12-06 05:28:33 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
AC
|
| 実行時間 | 196 ms / 5,000 ms |
| コード長 | 617 bytes |
| 記録 | |
| コンパイル時間 | 2,805 ms |
| コンパイル使用メモリ | 74,760 KB |
| 実行使用メモリ | 42,732 KB |
| 最終ジャッジ日時 | 2024-12-27 15:40:11 |
| 合計ジャッジ時間 | 9,180 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int [] V = new int [N];
for(int i=0; i<N; i++){
V[i]=sc.nextInt();
}
if(N==1){
System.out.println(V[0]);
}else{
int [] dp = new int [N];
dp[0]=V[0];
dp[1]=Math.max(V[0],V[1]);
for(int i=2; i<N; i++){
dp[i]=Math.max(dp[i-1],dp[i-2]+V[i]);
}
System.out.println(Math.max(dp[N-1],dp[N-2]));
}
}
}
kohaku_kohaku