結果

問題 No.1 道のショートカット
ユーザー k_kadorak_kadora
提出日時 2015-06-15 02:32:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 317 ms / 5,000 ms
コード長 1,141 bytes
コンパイル時間 4,680 ms
コンパイル使用メモリ 74,684 KB
実行使用メモリ 60,592 KB
最終ジャッジ日時 2023-09-27 21:46:48
合計ジャッジ時間 14,341 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,824 KB
testcase_01 AC 114 ms
55,780 KB
testcase_02 AC 119 ms
55,936 KB
testcase_03 AC 125 ms
56,188 KB
testcase_04 AC 116 ms
55,800 KB
testcase_05 AC 115 ms
55,764 KB
testcase_06 AC 119 ms
56,000 KB
testcase_07 AC 127 ms
55,716 KB
testcase_08 AC 276 ms
60,592 KB
testcase_09 AC 245 ms
59,792 KB
testcase_10 AC 227 ms
59,892 KB
testcase_11 AC 271 ms
60,312 KB
testcase_12 AC 317 ms
60,136 KB
testcase_13 AC 294 ms
60,168 KB
testcase_14 AC 168 ms
56,036 KB
testcase_15 AC 121 ms
56,200 KB
testcase_16 AC 212 ms
56,880 KB
testcase_17 AC 123 ms
55,796 KB
testcase_18 AC 160 ms
53,916 KB
testcase_19 AC 157 ms
56,236 KB
testcase_20 AC 198 ms
56,796 KB
testcase_21 AC 194 ms
56,516 KB
testcase_22 AC 146 ms
56,276 KB
testcase_23 AC 267 ms
59,948 KB
testcase_24 AC 279 ms
60,248 KB
testcase_25 AC 213 ms
57,008 KB
testcase_26 AC 188 ms
57,060 KB
testcase_27 AC 285 ms
60,112 KB
testcase_28 AC 123 ms
55,828 KB
testcase_29 AC 213 ms
59,608 KB
testcase_30 AC 178 ms
58,508 KB
testcase_31 AC 188 ms
59,308 KB
testcase_32 AC 270 ms
59,936 KB
testcase_33 AC 225 ms
59,380 KB
testcase_34 AC 250 ms
60,280 KB
testcase_35 AC 185 ms
58,964 KB
testcase_36 AC 204 ms
58,964 KB
testcase_37 AC 186 ms
59,224 KB
testcase_38 AC 139 ms
56,528 KB
testcase_39 AC 184 ms
56,700 KB
testcase_40 AC 183 ms
59,332 KB
testcase_41 AC 160 ms
55,976 KB
testcase_42 AC 113 ms
55,644 KB
testcase_43 AC 114 ms
55,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Yuki1{
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		int n,c,v,res = 50000;
		boolean find=false;
		n = sc.nextInt();
		c = sc.nextInt();
		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];
		dp[1][0] = 1;
		for(int i = 0;i<n+1;i++){
			for(int j = 0;j<c+1;j++){
				dp[i][j] = 50000;
			}
		}
		dp[1][0] = 0;
		for(int i = 1;i<n;i++){
			for(int j = 0;j<v;j++){
				for(int k = 0;k<=c-y[j];k++){
					if(dp[i][k] != 50000 && s[j] == i && dp[t[j]][k+y[j]] > dp[i][k] + m[j]){
						dp[t[j]][k+y[j]] = dp[i][k] + m[j];
					}
				}
			}
		}
		for(int i = 0; i<c+1;i++){
			if(dp[n][i] != 0){
				if(res > dp[n][i]){
					res = dp[n][i];
					find = true;
				}
			}
		}
		if(find){
			System.out.println(res);
		}else{
			System.out.println(-1);
		}
	}
}
0