結果

問題 No.1 道のショートカット
ユーザー CrazyBBBCrazyBBB
提出日時 2016-03-05 19:08:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 317 ms / 5,000 ms
コード長 1,579 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 73,748 KB
実行使用メモリ 60,464 KB
最終ジャッジ日時 2023-09-27 21:54:26
合計ジャッジ時間 11,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,592 KB
testcase_01 AC 109 ms
55,892 KB
testcase_02 AC 114 ms
55,620 KB
testcase_03 AC 120 ms
55,516 KB
testcase_04 AC 112 ms
55,584 KB
testcase_05 AC 118 ms
56,076 KB
testcase_06 AC 130 ms
55,344 KB
testcase_07 AC 130 ms
55,688 KB
testcase_08 AC 274 ms
59,904 KB
testcase_09 AC 270 ms
60,464 KB
testcase_10 AC 243 ms
60,016 KB
testcase_11 AC 255 ms
60,144 KB
testcase_12 AC 314 ms
60,152 KB
testcase_13 AC 317 ms
60,060 KB
testcase_14 AC 161 ms
55,796 KB
testcase_15 AC 114 ms
55,668 KB
testcase_16 AC 209 ms
56,192 KB
testcase_17 AC 114 ms
55,868 KB
testcase_18 AC 150 ms
56,632 KB
testcase_19 AC 160 ms
55,944 KB
testcase_20 AC 193 ms
56,796 KB
testcase_21 AC 190 ms
56,808 KB
testcase_22 AC 151 ms
56,420 KB
testcase_23 AC 256 ms
59,764 KB
testcase_24 AC 247 ms
60,372 KB
testcase_25 AC 192 ms
56,228 KB
testcase_26 AC 192 ms
57,276 KB
testcase_27 AC 279 ms
59,952 KB
testcase_28 AC 122 ms
55,624 KB
testcase_29 AC 211 ms
60,008 KB
testcase_30 AC 179 ms
58,784 KB
testcase_31 AC 182 ms
58,800 KB
testcase_32 AC 278 ms
59,608 KB
testcase_33 AC 252 ms
59,408 KB
testcase_34 AC 265 ms
60,084 KB
testcase_35 AC 172 ms
58,864 KB
testcase_36 AC 210 ms
59,104 KB
testcase_37 AC 182 ms
58,856 KB
testcase_38 AC 135 ms
55,984 KB
testcase_39 AC 196 ms
56,824 KB
testcase_40 AC 186 ms
58,416 KB
testcase_41 AC 164 ms
56,484 KB
testcase_42 AC 119 ms
56,144 KB
testcase_43 AC 115 ms
55,908 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