結果

問題 No.1 道のショートカット
ユーザー mastersatoshimastersatoshi
提出日時 2015-07-29 22:55:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 1,855 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 74,656 KB
実行使用メモリ 52,932 KB
最終ジャッジ日時 2023-09-27 21:47:20
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,292 KB
testcase_01 AC 41 ms
49,544 KB
testcase_02 AC 39 ms
49,432 KB
testcase_03 AC 41 ms
49,344 KB
testcase_04 AC 39 ms
49,232 KB
testcase_05 AC 39 ms
49,356 KB
testcase_06 AC 40 ms
49,464 KB
testcase_07 AC 41 ms
49,288 KB
testcase_08 AC 93 ms
52,328 KB
testcase_09 AC 79 ms
52,140 KB
testcase_10 AC 82 ms
52,104 KB
testcase_11 AC 89 ms
52,216 KB
testcase_12 AC 118 ms
52,312 KB
testcase_13 AC 130 ms
52,544 KB
testcase_14 AC 67 ms
51,376 KB
testcase_15 AC 41 ms
49,268 KB
testcase_16 AC 88 ms
51,620 KB
testcase_17 AC 42 ms
49,268 KB
testcase_18 AC 66 ms
51,812 KB
testcase_19 AC 88 ms
52,048 KB
testcase_20 AC 89 ms
51,928 KB
testcase_21 AC 77 ms
52,288 KB
testcase_22 AC 70 ms
50,040 KB
testcase_23 AC 96 ms
52,428 KB
testcase_24 AC 107 ms
52,620 KB
testcase_25 AC 84 ms
52,264 KB
testcase_26 AC 78 ms
51,736 KB
testcase_27 AC 96 ms
52,516 KB
testcase_28 AC 43 ms
49,176 KB
testcase_29 AC 82 ms
52,380 KB
testcase_30 AC 52 ms
51,016 KB
testcase_31 AC 57 ms
51,132 KB
testcase_32 AC 85 ms
52,100 KB
testcase_33 AC 89 ms
52,932 KB
testcase_34 AC 83 ms
51,920 KB
testcase_35 AC 55 ms
50,900 KB
testcase_36 AC 79 ms
51,944 KB
testcase_37 AC 57 ms
51,356 KB
testcase_38 AC 44 ms
49,292 KB
testcase_39 AC 79 ms
51,716 KB
testcase_40 AC 75 ms
51,984 KB
testcase_41 AC 46 ms
49,252 KB
testcase_42 AC 40 ms
49,296 KB
testcase_43 AC 41 ms
49,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        int C = Integer.parseInt(br.readLine());
        int V = Integer.parseInt(br.readLine());

        int[] S = convert(br.readLine().split(" "));//from
        int[] T = convert(br.readLine().split(" "));//to
        int[] Y = convert(br.readLine().split(" "));//費用
        int[] M = convert(br.readLine().split(" "));//時間

        int[][] min = new int[N + 1][C + 1];

        for (int i = 2; i <= N; i++) {
            Arrays.fill(min[i], Integer.MAX_VALUE);
        }

        for (int i = 1; i <= N; i++) {
            for (int j = 0; j < V; j++) {

                int tmpS = S[j];
                int tmpT = T[j];
                int tmpY = Y[j];
                int tmpM = M[j];

                for (int k = 0; k + tmpY <= C; k++) {

                    if (min[tmpS][k] != Integer.MAX_VALUE
                            && min[tmpS][k] + tmpM < min[tmpT][k + tmpY]) {

                        min[tmpT][k + tmpY] = min[tmpS][k] + tmpM;
                    }
                }
            }
        }

        int minTime = Integer.MAX_VALUE;

        for (int i = 0; i <= C; i++) {
            if (min[N][i] < minTime) {
                minTime = min[N][i];
            }
        }

        if (minTime == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(minTime);
        }
    }

    private static int[] convert(String[] source) {
        int[] dest = new int[source.length];

        for (int i = 0; i < source.length; i++) {
            dest[i] = Integer.parseInt(source[i]);
        }

        return dest;
    }
}
0