結果

問題 No.1 道のショートカット
ユーザー scachescache
提出日時 2014-11-12 23:06:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 248 ms / 5,000 ms
コード長 1,717 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 79,688 KB
実行使用メモリ 60,040 KB
最終ジャッジ日時 2023-09-27 21:36:36
合計ジャッジ時間 13,612 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,904 KB
testcase_01 AC 129 ms
55,932 KB
testcase_02 AC 128 ms
55,740 KB
testcase_03 AC 138 ms
55,936 KB
testcase_04 AC 132 ms
55,816 KB
testcase_05 AC 130 ms
55,756 KB
testcase_06 AC 135 ms
55,468 KB
testcase_07 AC 145 ms
55,964 KB
testcase_08 AC 232 ms
59,736 KB
testcase_09 AC 222 ms
59,152 KB
testcase_10 AC 236 ms
60,040 KB
testcase_11 AC 241 ms
59,484 KB
testcase_12 AC 244 ms
59,740 KB
testcase_13 AC 247 ms
59,636 KB
testcase_14 AC 173 ms
56,184 KB
testcase_15 AC 128 ms
55,912 KB
testcase_16 AC 202 ms
56,164 KB
testcase_17 AC 131 ms
55,584 KB
testcase_18 AC 164 ms
56,272 KB
testcase_19 AC 172 ms
56,236 KB
testcase_20 AC 201 ms
56,356 KB
testcase_21 AC 193 ms
56,680 KB
testcase_22 AC 158 ms
53,932 KB
testcase_23 AC 248 ms
59,604 KB
testcase_24 AC 234 ms
59,348 KB
testcase_25 AC 210 ms
58,288 KB
testcase_26 AC 198 ms
56,344 KB
testcase_27 AC 237 ms
59,296 KB
testcase_28 AC 136 ms
55,460 KB
testcase_29 AC 242 ms
59,792 KB
testcase_30 AC 198 ms
58,684 KB
testcase_31 AC 221 ms
59,272 KB
testcase_32 AC 220 ms
58,932 KB
testcase_33 AC 212 ms
58,500 KB
testcase_34 AC 236 ms
59,560 KB
testcase_35 AC 231 ms
59,184 KB
testcase_36 AC 229 ms
59,668 KB
testcase_37 AC 224 ms
59,348 KB
testcase_38 AC 157 ms
55,844 KB
testcase_39 AC 193 ms
56,632 KB
testcase_40 AC 209 ms
58,952 KB
testcase_41 AC 193 ms
56,748 KB
testcase_42 AC 128 ms
55,832 KB
testcase_43 AC 130 ms
55,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class ShortCut {
	public static void main(String[] args) {
		ShortCut p = new ShortCut();
	}

	public ShortCut() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int v = sc.nextInt();
		Edge[] e = new Edge[v];
		for(int i=0;i<e.length;i++)
			e[i] = new Edge();
		for(int i=0;i<e.length;i++)
			e[i].s = sc.nextInt();
		for(int i=0;i<e.length;i++)
			e[i].t = sc.nextInt();
		for(int i=0;i<e.length;i++)
			e[i].y = sc.nextInt();
		for(int i=0;i<e.length;i++)
			e[i].m = sc.nextInt();
		
		solve(n, c, v, e);
	}

	private final int INF = 1000000;
	private void solve(int n, int c, int v, Edge[] edge) {
		Arrays.sort(edge);
		
		// dp[i,j] : 1からiへコストjで行く時の最小時間
		int[][] dp = new int[50+1][300+1];
		for(int i=2;i<dp.length;i++)
			Arrays.fill(dp[i], INF);
			
		for(int i=0;i<edge.length;i++){
			Edge e = edge[i];
			for(int j=1;j<dp[e.t].length;j++){
				if(j-e.y >= 0)
					dp[e.t][j] = Math.min(dp[e.t][j], Math.min(dp[e.s][j-e.y] + e.m, dp[e.t][j-1]));
			}
		}
		
		int res = INF;
		for(int i=1;i<=c;i++){
			res = Math.min(res, dp[n][i]);
		}
		
		if(res >= INF)
			System.out.println(-1);
		else
			System.out.println(res);
		
		
	}


	private class Edge implements Comparable<Edge>{
		int s;
		int t;
		int y;
		int m;
		
		public Edge(int s, int t, int y, int m) {
			this.s = s;
			this.t = t;
			this.y = y;
			this.m = m;
		}

		public Edge() {
		}

		@Override
		public int compareTo(Edge o) {
			if(this.s != o.s)
				return this.s - o.s;
			else
				return this.t - o.t;
		}

	}
}
0