結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-20 14:31:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 5,000 ms |
| コード長 | 1,167 bytes |
| コンパイル時間 | 5,063 ms |
| コンパイル使用メモリ | 76,272 KB |
| 実行使用メモリ | 38,092 KB |
| 最終ジャッジ日時 | 2024-12-27 12:48:05 |
| 合計ジャッジ時間 | 5,468 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 if(N==2){
System.out.println(Math.max(nums[0], nums[1]));
}else{
dp[0] = nums[0];
dp[1] = nums[1];
int max = 0;
for(int i=2;i<N;i++){
max = 0;
for(int j=0;j<i-1;j++){
if(max < nums[i]+dp[j]) max = nums[i]+dp[j];
}
dp[i] = max;
}
max = 0;
for(int i=0;i<N;i++){
if(max < dp[i]) max = dp[i];
}
System.out.println(max);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
kuramu