結果

問題 No.1 道のショートカット
ユーザー kuramukuramu
提出日時 2016-01-29 17:34:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,115 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 73,940 KB
実行使用メモリ 53,684 KB
最終ジャッジ日時 2023-09-22 12:37:51
合計ジャッジ時間 6,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,280 KB
testcase_01 AC 42 ms
49,192 KB
testcase_02 AC 42 ms
49,252 KB
testcase_03 AC 42 ms
49,156 KB
testcase_04 WA -
testcase_05 AC 42 ms
49,384 KB
testcase_06 AC 42 ms
49,960 KB
testcase_07 AC 42 ms
49,272 KB
testcase_08 AC 59 ms
51,588 KB
testcase_09 AC 55 ms
50,288 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 41 ms
49,424 KB
testcase_16 WA -
testcase_17 AC 44 ms
49,260 KB
testcase_18 AC 46 ms
49,192 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 48 ms
49,296 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 50 ms
49,360 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 43 ms
49,364 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 55 ms
50,316 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 45 ms
49,588 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 42 ms
49,248 KB
testcase_43 AC 42 ms
49,188 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());
	    	  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[][] cost = new int[N+1][N+1];
	    	  int[][] money = new int[N+1][N+1];
	    	  
	    	  for(int i=1;i<V+1;i++){
	    		  cost[S[i]][T[i]] = Y[i];
	    		  money[S[i]][T[i]] = M[i];
	    	  }
	    	  
	    	  int[] costDP = new int[N+1];
	    	  int[] moneyDP = new int[N+1];
	    	  moneyDP[0] = 0;
	    	  
	    	  for(int i=1;i<N+1;i++){
	    		  for(int j=i-1;j>=1;j--){
	    			  if(money[i-j][i]!=0){
	    				  if((i-j) != 1){
		    				  if(moneyDP[i-j]!=0 && (moneyDP[i] == 0 || moneyDP[i]>moneyDP[i-j]+money[i-j][i])){
		    					  if(costDP[i-j]+cost[i-j][i]<=C){
		    						  moneyDP[i] = moneyDP[i-j]+money[i-j][i];
		    						  costDP[i] = costDP[i-j]+cost[i-j][i];
		    					  }
		    				  }
	    				  }else{
	    					  if(costDP[i-j]+cost[i-j][i]<=C){
	    						  moneyDP[i] = moneyDP[i-j]+money[i-j][i];
	    						  costDP[i] = costDP[i-j]+cost[i-j][i];
	    					  }
	    				  }
	    			  }
	    		  }
	    	  }    	  
	    	  System.out.println(moneyDP[N]!=0?moneyDP[N]:-1);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
}
0