結果

問題 No.45 回転寿司
ユーザー kuramukuramu
提出日時 2016-01-20 14:41:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 77,756 KB
実行使用メモリ 52,196 KB
最終ジャッジ日時 2024-05-03 11:31:05
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 53 ms
50,144 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 51 ms
50,192 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 53 ms
50,160 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 52 ms
50,304 KB
testcase_12 AC 53 ms
50,044 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 52 ms
50,340 KB
testcase_17 AC 51 ms
49,968 KB
testcase_18 WA -
testcase_19 AC 54 ms
50,324 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 51 ms
49,796 KB
testcase_23 AC 50 ms
49,964 KB
testcase_24 AC 50 ms
50,308 KB
testcase_25 AC 51 ms
50,156 KB
testcase_26 AC 53 ms
50,284 KB
testcase_27 AC 54 ms
50,356 KB
testcase_28 WA -
testcase_29 AC 53 ms
50,292 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 51 ms
50,116 KB
testcase_33 AC 54 ms
50,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[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();
	      }
	}	
}
0