結果

問題 No.1 道のショートカット
ユーザー kou6839kou6839
提出日時 2015-02-26 22:52:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 1,074 bytes
コンパイル時間 3,479 ms
コンパイル使用メモリ 74,844 KB
実行使用メモリ 61,868 KB
最終ジャッジ日時 2023-09-27 21:40:46
合計ジャッジ時間 12,083 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
56,044 KB
testcase_01 AC 108 ms
55,856 KB
testcase_02 AC 105 ms
55,876 KB
testcase_03 AC 117 ms
55,612 KB
testcase_04 AC 110 ms
56,344 KB
testcase_05 AC 106 ms
57,928 KB
testcase_06 AC 114 ms
55,928 KB
testcase_07 AC 119 ms
56,216 KB
testcase_08 AC 200 ms
59,464 KB
testcase_09 AC 182 ms
59,060 KB
testcase_10 AC 194 ms
59,252 KB
testcase_11 AC 205 ms
59,784 KB
testcase_12 AC 205 ms
59,804 KB
testcase_13 AC 212 ms
59,380 KB
testcase_14 AC 136 ms
56,528 KB
testcase_15 AC 107 ms
55,772 KB
testcase_16 AC 171 ms
55,788 KB
testcase_17 AC 111 ms
56,016 KB
testcase_18 AC 153 ms
56,036 KB
testcase_19 AC 138 ms
56,416 KB
testcase_20 AC 173 ms
56,440 KB
testcase_21 AC 166 ms
55,780 KB
testcase_22 AC 135 ms
56,444 KB
testcase_23 AC 209 ms
61,868 KB
testcase_24 AC 195 ms
57,604 KB
testcase_25 AC 176 ms
56,672 KB
testcase_26 AC 167 ms
56,448 KB
testcase_27 AC 196 ms
59,508 KB
testcase_28 AC 116 ms
56,256 KB
testcase_29 AC 197 ms
57,112 KB
testcase_30 AC 168 ms
58,188 KB
testcase_31 AC 173 ms
59,184 KB
testcase_32 AC 185 ms
58,904 KB
testcase_33 AC 186 ms
59,000 KB
testcase_34 AC 196 ms
59,588 KB
testcase_35 AC 181 ms
58,784 KB
testcase_36 AC 190 ms
59,048 KB
testcase_37 AC 181 ms
58,960 KB
testcase_38 AC 130 ms
56,504 KB
testcase_39 AC 158 ms
54,396 KB
testcase_40 AC 160 ms
59,132 KB
testcase_41 AC 151 ms
56,288 KB
testcase_42 AC 108 ms
55,680 KB
testcase_43 AC 109 ms
56,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int v = sc.nextInt();
		int[] s= new int[v];
		int[] t = new int[v];
		int[] y=new int[v];
		int[] m=new int[v];
		for(int i=0;i<v;i++){
			s[i]=sc.nextInt();
		}
		for(int i=0;i<v;i++){
			t[i]=sc.nextInt();
		}
		for(int i=0;i<v;i++){
			y[i]=sc.nextInt();
		}
		for(int i=0;i<v;i++){
			m[i]=sc.nextInt();
		}
		int[][] dp=new int[n+1][c+1];
		for(int i=1;i<=n;i++){
			Arrays.fill(dp[i], Integer.MAX_VALUE-2000);
		}
		Arrays.fill(dp[1], 0);
		for(int i=1;i<n;i++){
			for(int j=0;j<v;j++){
				if(s[j]==i){
					for(int k=0;k<=c;k++){
						if(k!=Integer.MAX_VALUE-2000 && k+y[j]<=c){
							dp[t[j]][k+y[j]]=Math.min(dp[t[j]][k+y[j]], dp[i][k]+m[j]);
						}
					}
				}
			}
		}
		int ans=Integer.MAX_VALUE-2000;
		for(int i=0;i<=c;i++){
			ans=Math.min(ans, dp[n][i]);
		}
		if(ans==Integer.MAX_VALUE-2000){
			System.out.println(-1);
		}else{
			System.out.println(ans);
		}
	}
}
0