結果

問題 No.1 道のショートカット
ユーザー actu3actu3
提出日時 2015-06-21 15:46:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,889 bytes
コンパイル時間 3,816 ms
コンパイル使用メモリ 77,484 KB
実行使用メモリ 53,324 KB
最終ジャッジ日時 2023-09-22 12:22:17
合計ジャッジ時間 8,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,884 KB
testcase_01 AC 44 ms
49,568 KB
testcase_02 AC 44 ms
49,332 KB
testcase_03 AC 46 ms
49,332 KB
testcase_04 AC 45 ms
49,348 KB
testcase_05 AC 45 ms
49,344 KB
testcase_06 AC 46 ms
49,324 KB
testcase_07 AC 45 ms
49,640 KB
testcase_08 AC 89 ms
51,020 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 93 ms
52,140 KB
testcase_24 AC 79 ms
50,760 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 72 ms
50,400 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 78 ms
50,664 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

public class Yuki1 {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver();
		solver.solve(1, in, out);
		out.close();
	}
	
static class Solver {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
    	int n = in.nextInt();
    	int c = in.nextInt();
    	int v = in.nextInt();
    	int[] s = new int[v];
    	int[] t = new int[v];
    	int[] y = new int[v]; //cost
    	int[] m = new int[v]; //time
    	for (int i = 0; i < v; i++) {
			s[i] = in.nextInt()-1;
		}
    	for (int i = 0; i < v; i++) {
			t[i] = in.nextInt()-1;
		}
    	for (int i = 0; i < v; i++) {
			y[i] = in.nextInt();
		}
    	for (int i = 0; i < v; i++) {
			m[i] = in.nextInt();
		}
    	HashMap<Integer, List<Road>> map = new HashMap<>();
    	for (int i = 0; i < n; i++) {
			map.put(i, new ArrayList<>());
		}
    	for (int i = 0; i < v; i++) {
			List<Road> list = map.get(s[i]);
			list.add(new Road(t[i], y[i], m[i]));
			map.put(s[i], list);
		}
    	
    	final int INF = Integer.MAX_VALUE;
    	int[][] dp = new int[n][c+1];
    	for (int i = 0; i < n; i++) {
    		Arrays.fill(dp[i], INF);
		}
    	dp[0][c] = 0;
    	
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j <= c; j++) {
				if (dp[i][j] == INF) continue;
				List<Road> list = map.get(s[i]);
				for (Road r : list) {
					int ncost = j - r.cost;
					if (ncost < 0) continue;
					int ntime = dp[i][j] + r.time;
					dp[r.to][ncost] = Math.min(dp[r.to][ncost], ntime);
				}
			}
		}
    	
    	int ans = INF;
    	for (int i = 0; i <= c; i++) {
			ans = Math.min(ans, dp[n-1][i]);
		}
    	if (ans == INF) ans = -1;
    	System.out.println(ans);
    	
    }
    
    static class Road {
    	int to;
    	int cost;
    	int time;
    	Road(int to, int cost, int time) {
    		this.to = to; this.cost = cost; this.time = time;
    	}
    }
    
}

static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}
}
0