結果

問題 No.1 道のショートカット
ユーザー kuramukuramu
提出日時 2016-01-29 18:40:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 1,911 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 74,016 KB
実行使用メモリ 52,852 KB
最終ジャッジ日時 2023-09-27 21:51:43
合計ジャッジ時間 6,464 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,420 KB
testcase_01 AC 46 ms
49,428 KB
testcase_02 AC 45 ms
49,288 KB
testcase_03 AC 46 ms
49,564 KB
testcase_04 AC 45 ms
49,224 KB
testcase_05 AC 45 ms
49,348 KB
testcase_06 AC 46 ms
49,268 KB
testcase_07 AC 47 ms
49,384 KB
testcase_08 AC 72 ms
51,292 KB
testcase_09 AC 68 ms
51,260 KB
testcase_10 AC 69 ms
51,568 KB
testcase_11 AC 71 ms
52,312 KB
testcase_12 AC 102 ms
50,384 KB
testcase_13 AC 84 ms
52,852 KB
testcase_14 AC 49 ms
49,404 KB
testcase_15 AC 45 ms
49,268 KB
testcase_16 AC 54 ms
47,476 KB
testcase_17 AC 46 ms
49,840 KB
testcase_18 AC 49 ms
49,320 KB
testcase_19 AC 49 ms
49,288 KB
testcase_20 AC 55 ms
49,576 KB
testcase_21 AC 52 ms
49,596 KB
testcase_22 AC 48 ms
49,384 KB
testcase_23 AC 86 ms
52,408 KB
testcase_24 AC 71 ms
51,944 KB
testcase_25 AC 56 ms
49,408 KB
testcase_26 AC 52 ms
49,404 KB
testcase_27 AC 71 ms
51,284 KB
testcase_28 AC 45 ms
49,332 KB
testcase_29 AC 70 ms
51,732 KB
testcase_30 AC 57 ms
50,488 KB
testcase_31 AC 58 ms
50,320 KB
testcase_32 AC 70 ms
50,544 KB
testcase_33 AC 73 ms
50,492 KB
testcase_34 AC 72 ms
51,480 KB
testcase_35 AC 61 ms
51,616 KB
testcase_36 AC 68 ms
51,548 KB
testcase_37 AC 60 ms
51,672 KB
testcase_38 AC 48 ms
49,564 KB
testcase_39 AC 51 ms
49,468 KB
testcase_40 AC 55 ms
51,220 KB
testcase_41 AC 48 ms
49,348 KB
testcase_42 AC 45 ms
49,344 KB
testcase_43 AC 44 ms
49,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  int N = Integer.parseInt(stdReader.readLine());
	    	  int C = Integer.parseInt(stdReader.readLine());
	    	  int V = Integer.parseInt(stdReader.readLine());
	    	  String[] temp1 = stdReader.readLine().split(" ");
	    	  String[] temp2 = stdReader.readLine().split(" ");
	    	  String[] temp3 = stdReader.readLine().split(" ");
	    	  String[] temp4 = stdReader.readLine().split(" ");
	    	  int[] S = new int[V+1];
	    	  int[] T = new int[V+1];
	    	  int[] Y = new int[V+1];
	    	  int[] M = new int[V+1];
	    	  
	    	  for(int i=1;i<V+1;i++){
	    		  S[i] = Integer.parseInt(temp1[i-1]);
	    		  T[i] = Integer.parseInt(temp2[i-1]);
	    		  Y[i] = Integer.parseInt(temp3[i-1]);
	    		  M[i] = Integer.parseInt(temp4[i-1]);
	    	  }
	    	  int[][] dp = new int[N+1][C+1];

	    	  for(int i=1;i<N+1;i++){
	    		  Arrays.fill(dp[i], Integer.MAX_VALUE);
	    	  }
	    	  dp[1][C] = 100000;
	    	  
	    	  for(int i=1;i<N+1;i++){
	    		  for(int j=1;j<V+1;j++){
	    			  if(S[j] == i){
		    			  for(int k=0;k<C+1;k++){
		    				  if(dp[i][k]!=Integer.MAX_VALUE && k-Y[j]>=0){
		    					  if(dp[T[j]][k-Y[j]] > dp[i][k]+M[j]){
		    						  dp[T[j]][k-Y[j]] = dp[i][k]+M[j];
		    					  }
		    				  }
		    			  }
	    			  }
	    		  }
	    	  }
	    	  
	    	  int ans = Integer.MAX_VALUE;
	    	  for(int i=0;i<C+1;i++){
	    		  ans = Math.min(ans,dp[N][i]);
	    	  }
	    	  if(ans != Integer.MAX_VALUE){
	    		  System.out.println(ans-100000);
	    	  }else{
	    		  System.out.println(-1);
	    	  }
	    	  
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
}
0