結果

問題 No.1 道のショートカット
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-23 13:27:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 233 ms / 5,000 ms
コード長 1,841 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 74,248 KB
実行使用メモリ 60,224 KB
最終ジャッジ日時 2023-09-27 21:42:38
合計ジャッジ時間 11,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,832 KB
testcase_01 AC 127 ms
56,180 KB
testcase_02 AC 129 ms
55,868 KB
testcase_03 AC 134 ms
55,420 KB
testcase_04 AC 129 ms
55,908 KB
testcase_05 AC 127 ms
55,836 KB
testcase_06 AC 135 ms
55,724 KB
testcase_07 AC 143 ms
56,036 KB
testcase_08 AC 223 ms
59,728 KB
testcase_09 AC 211 ms
59,392 KB
testcase_10 AC 212 ms
59,784 KB
testcase_11 AC 224 ms
59,244 KB
testcase_12 AC 232 ms
59,308 KB
testcase_13 AC 233 ms
60,088 KB
testcase_14 AC 184 ms
56,192 KB
testcase_15 AC 129 ms
55,764 KB
testcase_16 AC 193 ms
56,716 KB
testcase_17 AC 130 ms
55,504 KB
testcase_18 AC 174 ms
56,152 KB
testcase_19 AC 157 ms
56,336 KB
testcase_20 AC 191 ms
58,268 KB
testcase_21 AC 190 ms
55,992 KB
testcase_22 AC 156 ms
56,132 KB
testcase_23 AC 232 ms
59,592 KB
testcase_24 AC 221 ms
59,228 KB
testcase_25 AC 199 ms
57,308 KB
testcase_26 AC 189 ms
56,208 KB
testcase_27 AC 215 ms
59,324 KB
testcase_28 AC 133 ms
55,816 KB
testcase_29 AC 226 ms
59,740 KB
testcase_30 AC 193 ms
58,852 KB
testcase_31 AC 205 ms
58,312 KB
testcase_32 AC 209 ms
58,776 KB
testcase_33 AC 207 ms
58,788 KB
testcase_34 AC 226 ms
60,224 KB
testcase_35 AC 207 ms
59,172 KB
testcase_36 AC 214 ms
59,524 KB
testcase_37 AC 205 ms
56,372 KB
testcase_38 AC 151 ms
55,836 KB
testcase_39 AC 184 ms
55,988 KB
testcase_40 AC 200 ms
58,804 KB
testcase_41 AC 182 ms
55,952 KB
testcase_42 AC 127 ms
55,708 KB
testcase_43 AC 127 ms
56,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        int c = koko.nextInt();
        int v = koko.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]=koko.nextInt();
        }
        for(int i=0; i<v; i++){
            t[i]=koko.nextInt();
        }
        for(int i=0; i<v; i++){
            y[i]=koko.nextInt();
        }
        for(int i=0; i<v; i++){
            m[i]=koko.nextInt();
        }
        boolean[][] stop = new boolean[n+1][c+1];
        int[][] stoptime = new int[n+1][c+1];
        stop[1][0]=true;
        stoptime[1][0]=0;
        for(int i=2; i<n+1; i++){
            for(int j=0; j<v; j++){
                if(i==t[j]){
                    for(int cost=0; cost<c+1-y[j]; cost++){
                        if(stop[s[j]][cost]){
                            if(stop[i][cost+y[j]]){
                                stoptime[i][cost+y[j]]=Math.min(stoptime[i][cost+y[j]], stoptime[s[j]][cost]+m[j]);
                            }else{
                                stop[i][cost+y[j]]=true;
                                stoptime[i][cost+y[j]]=stoptime[s[j]][cost]+m[j];
                            }
                        }
                    }
                }
            }
        }
        boolean flag = false;
        int min = n*1000;
        for(int cost=0; cost<c+1; cost++){
            if(stop[n][cost]){
                flag = true;
                min=Math.min(min, stoptime[n][cost]);
            }
        }
        if(flag){
            System.out.println(min);
        }else{
            System.out.println(-1);
        }
    }
}
0