結果

問題 No.1 道のショートカット
ユーザー kuramu
提出日時 2016-01-29 18:40:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 1,911 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 77,660 KB
実行使用メモリ 39,032 KB
最終ジャッジ日時 2024-07-20 16:20:00
合計ジャッジ時間 5,246 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

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