結果

問題 No.45 回転寿司
ユーザー kuramukuramu
提出日時 2016-01-20 14:44:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 73,968 KB
実行使用メモリ 49,876 KB
最終ジャッジ日時 2023-08-27 14:34:17
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,200 KB
testcase_01 AC 48 ms
49,208 KB
testcase_02 AC 50 ms
49,876 KB
testcase_03 AC 50 ms
49,280 KB
testcase_04 AC 49 ms
49,460 KB
testcase_05 AC 44 ms
49,428 KB
testcase_06 AC 46 ms
49,300 KB
testcase_07 AC 49 ms
49,304 KB
testcase_08 AC 46 ms
49,380 KB
testcase_09 AC 49 ms
49,296 KB
testcase_10 AC 46 ms
49,348 KB
testcase_11 AC 44 ms
49,272 KB
testcase_12 AC 49 ms
49,380 KB
testcase_13 AC 43 ms
49,344 KB
testcase_14 AC 43 ms
49,312 KB
testcase_15 AC 46 ms
49,312 KB
testcase_16 AC 45 ms
49,260 KB
testcase_17 AC 45 ms
49,196 KB
testcase_18 AC 45 ms
49,516 KB
testcase_19 AC 48 ms
49,356 KB
testcase_20 AC 42 ms
49,400 KB
testcase_21 AC 43 ms
49,328 KB
testcase_22 AC 42 ms
49,240 KB
testcase_23 AC 43 ms
49,680 KB
testcase_24 AC 43 ms
49,200 KB
testcase_25 AC 43 ms
49,824 KB
testcase_26 AC 46 ms
49,744 KB
testcase_27 AC 48 ms
49,436 KB
testcase_28 AC 46 ms
49,256 KB
testcase_29 AC 48 ms
49,524 KB
testcase_30 AC 48 ms
49,340 KB
testcase_31 AC 42 ms
49,300 KB
testcase_32 AC 42 ms
49,424 KB
testcase_33 AC 49 ms
49,380 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[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();
	      }
	}	
}
0