結果

問題 No.1 道のショートカット
ユーザー nCk_cvnCk_cv
提出日時 2016-02-18 15:24:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 320 ms / 5,000 ms
コード長 1,122 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 60,716 KB
最終ジャッジ日時 2023-09-27 21:52:18
合計ジャッジ時間 11,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,864 KB
testcase_01 AC 112 ms
55,796 KB
testcase_02 AC 110 ms
53,880 KB
testcase_03 AC 121 ms
56,264 KB
testcase_04 AC 115 ms
55,752 KB
testcase_05 AC 113 ms
56,016 KB
testcase_06 AC 118 ms
55,840 KB
testcase_07 AC 123 ms
55,988 KB
testcase_08 AC 298 ms
59,836 KB
testcase_09 AC 267 ms
59,768 KB
testcase_10 AC 240 ms
60,716 KB
testcase_11 AC 244 ms
60,096 KB
testcase_12 AC 298 ms
60,152 KB
testcase_13 AC 320 ms
60,508 KB
testcase_14 AC 170 ms
56,436 KB
testcase_15 AC 115 ms
55,804 KB
testcase_16 AC 204 ms
57,044 KB
testcase_17 AC 119 ms
55,740 KB
testcase_18 AC 172 ms
56,468 KB
testcase_19 AC 142 ms
55,812 KB
testcase_20 AC 191 ms
57,036 KB
testcase_21 AC 182 ms
57,136 KB
testcase_22 AC 154 ms
55,976 KB
testcase_23 AC 246 ms
60,336 KB
testcase_24 AC 246 ms
60,104 KB
testcase_25 AC 191 ms
56,716 KB
testcase_26 AC 187 ms
57,460 KB
testcase_27 AC 269 ms
60,440 KB
testcase_28 AC 120 ms
55,536 KB
testcase_29 AC 214 ms
58,992 KB
testcase_30 AC 177 ms
58,856 KB
testcase_31 AC 190 ms
59,392 KB
testcase_32 AC 276 ms
59,704 KB
testcase_33 AC 237 ms
59,744 KB
testcase_34 AC 245 ms
59,972 KB
testcase_35 AC 186 ms
59,120 KB
testcase_36 AC 206 ms
59,396 KB
testcase_37 AC 186 ms
58,988 KB
testcase_38 AC 141 ms
56,148 KB
testcase_39 AC 196 ms
56,916 KB
testcase_40 AC 191 ms
58,732 KB
testcase_41 AC 167 ms
56,392 KB
testcase_42 AC 122 ms
55,912 KB
testcase_43 AC 120 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.awt.geom.*;
import java.io.*;

class Main {
	static int[] vx = {1,0,-1,0};
	static int[] vy = {0,1,0,-1};
	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()-1;
		}
		for(int i = 0; i < v; i++) {
			t[i] = sc.nextInt()-1;
		}
		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][c+1];
		for(int i = 0; i < n; i++) {
			Arrays.fill(dp[i], 2 << 28);
		}
		dp[0][0] = 0;
		for(int i = 0; i < n-1; i++) {
			for(int j = 0; j < c; j++) {
				for(int k = 0; k < v; k++) {
					if(s[k] != i || j + y[k] > c) continue;
					dp[t[k]][j + y[k]] = Math.min(dp[t[k]][j + y[k]],dp[i][j] + m[k]);
				}
			}
		}
		int min = dp[n-1][0];
		for(int i= 1; i <= c; i++) {
			min = Math.min(min, dp[n-1][i]);
		}
		System.out.println((min==2<<28?-1:min));
		
		
	}
}
0