結果

問題 No.45 回転寿司
ユーザー kuramukuramu
提出日時 2016-01-20 14:31:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 1,167 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 51,700 KB
最終ジャッジ日時 2023-08-27 14:34:06
合計ジャッジ時間 5,435 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
49,436 KB
testcase_01 AC 57 ms
50,032 KB
testcase_02 AC 80 ms
51,700 KB
testcase_03 AC 71 ms
51,268 KB
testcase_04 AC 63 ms
51,552 KB
testcase_05 AC 47 ms
47,844 KB
testcase_06 AC 54 ms
49,292 KB
testcase_07 AC 66 ms
50,976 KB
testcase_08 AC 49 ms
49,316 KB
testcase_09 AC 70 ms
51,324 KB
testcase_10 AC 51 ms
49,472 KB
testcase_11 AC 49 ms
49,336 KB
testcase_12 AC 66 ms
51,488 KB
testcase_13 AC 46 ms
49,260 KB
testcase_14 AC 47 ms
49,416 KB
testcase_15 AC 53 ms
49,668 KB
testcase_16 AC 49 ms
49,144 KB
testcase_17 AC 51 ms
49,280 KB
testcase_18 AC 50 ms
49,772 KB
testcase_19 AC 60 ms
50,760 KB
testcase_20 AC 46 ms
49,196 KB
testcase_21 AC 47 ms
49,392 KB
testcase_22 AC 45 ms
49,420 KB
testcase_23 AC 45 ms
49,756 KB
testcase_24 AC 46 ms
49,388 KB
testcase_25 AC 46 ms
49,600 KB
testcase_26 AC 52 ms
49,444 KB
testcase_27 AC 62 ms
50,328 KB
testcase_28 AC 55 ms
49,216 KB
testcase_29 AC 67 ms
50,864 KB
testcase_30 AC 61 ms
50,520 KB
testcase_31 AC 46 ms
49,388 KB
testcase_32 AC 46 ms
49,308 KB
testcase_33 AC 80 ms
49,592 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 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();
	      }
	}	
}
0