結果

問題 No.1 道のショートカット
ユーザー CrazyBBBCrazyBBB
提出日時 2016-03-05 18:15:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 1,165 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 74,148 KB
実行使用メモリ 60,312 KB
最終ジャッジ日時 2023-09-27 21:54:11
合計ジャッジ時間 13,394 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,752 KB
testcase_01 AC 112 ms
56,060 KB
testcase_02 AC 111 ms
55,776 KB
testcase_03 AC 118 ms
55,780 KB
testcase_04 AC 111 ms
56,096 KB
testcase_05 AC 109 ms
55,752 KB
testcase_06 AC 117 ms
57,780 KB
testcase_07 AC 122 ms
54,072 KB
testcase_08 AC 275 ms
60,076 KB
testcase_09 AC 260 ms
59,820 KB
testcase_10 AC 243 ms
60,244 KB
testcase_11 AC 262 ms
59,868 KB
testcase_12 AC 282 ms
60,312 KB
testcase_13 AC 284 ms
60,216 KB
testcase_14 AC 162 ms
56,012 KB
testcase_15 AC 118 ms
55,944 KB
testcase_16 AC 196 ms
57,076 KB
testcase_17 AC 116 ms
56,160 KB
testcase_18 AC 171 ms
56,244 KB
testcase_19 AC 160 ms
56,048 KB
testcase_20 AC 198 ms
56,568 KB
testcase_21 AC 187 ms
56,568 KB
testcase_22 AC 150 ms
56,280 KB
testcase_23 AC 255 ms
60,172 KB
testcase_24 AC 259 ms
60,252 KB
testcase_25 AC 199 ms
57,328 KB
testcase_26 AC 188 ms
56,780 KB
testcase_27 AC 272 ms
60,180 KB
testcase_28 AC 117 ms
55,804 KB
testcase_29 AC 220 ms
59,972 KB
testcase_30 AC 180 ms
58,820 KB
testcase_31 AC 186 ms
59,348 KB
testcase_32 AC 262 ms
59,744 KB
testcase_33 AC 223 ms
59,288 KB
testcase_34 AC 253 ms
60,148 KB
testcase_35 AC 186 ms
58,972 KB
testcase_36 AC 206 ms
59,024 KB
testcase_37 AC 190 ms
59,136 KB
testcase_38 AC 140 ms
56,124 KB
testcase_39 AC 185 ms
56,736 KB
testcase_40 AC 194 ms
58,840 KB
testcase_41 AC 169 ms
54,184 KB
testcase_42 AC 119 ms
56,060 KB
testcase_43 AC 113 ms
56,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static int[] S;
	static int[] T;
	static int[] Y;
	static int[] M;
	static int[][] dp;
	static final int INF = Integer.MAX_VALUE/2;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int C = sc.nextInt();
		int V = sc.nextInt();
		dp = new int[N][C+1];
		S = new int[V];
		for (int i=0; i<V; i++) {
			S[i] = sc.nextInt()-1;
		}
		T = new int[V];
		for (int i=0; i<V; i++) {
			T[i] = sc.nextInt()-1;
		}
		Y = new int[V];
		for (int i=0; i<V; i++) {
			Y[i] = sc.nextInt();
		}
		M = new int[V];
		for (int i=0; i<V; i++) {
			M[i] = sc.nextInt();
		}

		for (int i=0; i<N; i++) {
			for (int j=0; j<=C; j++) {
				dp[i][j] = INF;
			}
		}
		for (int i=0; i<=C; i++) {
			dp[0][i] = 0;
		}

		for (int i=0; i<N; i++) {
			for (int j=0; j<=C; j++) {
				for (int k=0; k<V; k++) {
					if (S[k] == i) {
						if (j+Y[k]<=C) {
							dp[T[k]][j+Y[k]] = Math.min(dp[T[k]][j+Y[k]], dp[i][j]+M[k]);
						}
					}
				}
			}
		}

		int ans = dp[N-1][C];
		if (ans == INF) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}

		sc.close();
	}
}
0