結果

問題 No.1 道のショートカット
ユーザー actu3actu3
提出日時 2015-06-21 15:46:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,889 bytes
コンパイル時間 3,811 ms
コンパイル使用メモリ 80,692 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2024-07-08 04:07:59
合計ジャッジ時間 8,240 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
37,136 KB
testcase_01 AC 55 ms
37,352 KB
testcase_02 AC 54 ms
37,072 KB
testcase_03 AC 55 ms
37,108 KB
testcase_04 AC 54 ms
36,796 KB
testcase_05 AC 56 ms
36,792 KB
testcase_06 AC 55 ms
37,308 KB
testcase_07 AC 55 ms
37,280 KB
testcase_08 AC 105 ms
39,436 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 106 ms
39,916 KB
testcase_24 AC 95 ms
38,760 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 93 ms
38,344 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 93 ms
38,692 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