結果

問題 No.1 道のショートカット
ユーザー GrenacheGrenache
提出日時 2016-03-04 23:44:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 5,000 ms
コード長 1,933 bytes
コンパイル時間 2,876 ms
コンパイル使用メモリ 74,452 KB
実行使用メモリ 60,668 KB
最終ジャッジ日時 2023-09-27 21:52:58
合計ジャッジ時間 11,603 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
56,032 KB
testcase_01 AC 109 ms
55,504 KB
testcase_02 AC 108 ms
55,640 KB
testcase_03 AC 112 ms
55,812 KB
testcase_04 AC 106 ms
55,848 KB
testcase_05 AC 110 ms
56,004 KB
testcase_06 AC 113 ms
55,656 KB
testcase_07 AC 118 ms
55,752 KB
testcase_08 AC 219 ms
59,452 KB
testcase_09 AC 209 ms
60,016 KB
testcase_10 AC 202 ms
59,980 KB
testcase_11 AC 218 ms
60,336 KB
testcase_12 AC 221 ms
60,668 KB
testcase_13 AC 231 ms
60,316 KB
testcase_14 AC 157 ms
56,536 KB
testcase_15 AC 109 ms
55,612 KB
testcase_16 AC 191 ms
59,184 KB
testcase_17 AC 116 ms
55,736 KB
testcase_18 AC 169 ms
55,876 KB
testcase_19 AC 159 ms
55,912 KB
testcase_20 AC 174 ms
58,268 KB
testcase_21 AC 167 ms
56,948 KB
testcase_22 AC 137 ms
55,492 KB
testcase_23 AC 210 ms
60,428 KB
testcase_24 AC 216 ms
59,492 KB
testcase_25 AC 178 ms
59,344 KB
testcase_26 AC 164 ms
56,532 KB
testcase_27 AC 211 ms
59,748 KB
testcase_28 AC 116 ms
53,808 KB
testcase_29 AC 199 ms
59,340 KB
testcase_30 AC 171 ms
58,884 KB
testcase_31 AC 185 ms
58,516 KB
testcase_32 AC 207 ms
59,328 KB
testcase_33 AC 201 ms
58,616 KB
testcase_34 AC 210 ms
60,196 KB
testcase_35 AC 190 ms
58,812 KB
testcase_36 AC 183 ms
57,604 KB
testcase_37 AC 177 ms
58,588 KB
testcase_38 AC 134 ms
56,440 KB
testcase_39 AC 172 ms
57,388 KB
testcase_40 AC 171 ms
58,708 KB
testcase_41 AC 154 ms
56,336 KB
testcase_42 AC 112 ms
55,784 KB
testcase_43 AC 114 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;


public class Main_yukicoder1 {

    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();
        }

        List<List<Triple>> edges = new ArrayList<List<Triple>>();
        for (int i = 0; i < n; i++) {
        	edges.add(new ArrayList<Triple>());
        }

        for (int i = 0; i < v; i++) {
        	edges.get(s[i] - 1).add(new Triple(t[i] - 1, y[i], m[i]));
        }

        final int INF = Integer.MAX_VALUE / 2;
        int[][] dp = new int[n][c + 1];
        for (int i = 0; i < n; i++) {
        	Arrays.fill(dp[i], INF);
        }
        dp[0][0] = 0;

        for (int i = 0; i < n; i++) {
        	for (int j = 0; j <= c; j++) {
        		for (Triple e : edges.get(i)) {
        			if (j + e.b <= c) {
        				dp[e.a][j + e.b] = Math.min(dp[e.a][j + e.b], dp[i][j] + e.c);
        			}
        		}
        	}
        }

        int min = INF;
        for (int i = 0; i <= c; i++) {
        	min = Math.min(min, dp[n - 1][i]);
        }

        if (min == INF) {
        	System.out.println(-1);
        } else {
        	System.out.println(min);
        }

        sc.close();
    }

    private static class Triple {
    	int a;
    	int b;
    	int c;

    	Triple(int a, int b, int c) {
    		this.a = a;
    		this.b = b;
    		this.c = c;
    	}
    }
}
0