結果
問題 | No.1 道のショートカット |
ユーザー | tenten |
提出日時 | 2021-11-10 08:30:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 255 ms / 5,000 ms |
コード長 | 2,874 bytes |
コンパイル時間 | 2,336 ms |
コンパイル使用メモリ | 79,468 KB |
実行使用メモリ | 57,316 KB |
最終ジャッジ日時 | 2024-11-20 16:26:08 |
合計ジャッジ時間 | 8,359 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,508 KB |
testcase_01 | AC | 57 ms
50,524 KB |
testcase_02 | AC | 56 ms
50,496 KB |
testcase_03 | AC | 56 ms
50,644 KB |
testcase_04 | AC | 56 ms
50,532 KB |
testcase_05 | AC | 58 ms
50,296 KB |
testcase_06 | AC | 57 ms
50,576 KB |
testcase_07 | AC | 58 ms
50,656 KB |
testcase_08 | AC | 149 ms
52,956 KB |
testcase_09 | AC | 107 ms
51,852 KB |
testcase_10 | AC | 129 ms
52,292 KB |
testcase_11 | AC | 165 ms
54,892 KB |
testcase_12 | AC | 210 ms
57,164 KB |
testcase_13 | AC | 220 ms
57,220 KB |
testcase_14 | AC | 60 ms
50,568 KB |
testcase_15 | AC | 56 ms
50,280 KB |
testcase_16 | AC | 80 ms
51,408 KB |
testcase_17 | AC | 56 ms
50,584 KB |
testcase_18 | AC | 60 ms
50,468 KB |
testcase_19 | AC | 59 ms
50,524 KB |
testcase_20 | AC | 87 ms
52,124 KB |
testcase_21 | AC | 62 ms
50,476 KB |
testcase_22 | AC | 60 ms
50,572 KB |
testcase_23 | AC | 255 ms
57,224 KB |
testcase_24 | AC | 221 ms
57,316 KB |
testcase_25 | AC | 115 ms
51,916 KB |
testcase_26 | AC | 93 ms
51,800 KB |
testcase_27 | AC | 199 ms
56,632 KB |
testcase_28 | AC | 56 ms
50,528 KB |
testcase_29 | AC | 147 ms
53,096 KB |
testcase_30 | AC | 95 ms
51,924 KB |
testcase_31 | AC | 125 ms
52,032 KB |
testcase_32 | AC | 133 ms
52,828 KB |
testcase_33 | AC | 120 ms
52,024 KB |
testcase_34 | AC | 242 ms
57,268 KB |
testcase_35 | AC | 88 ms
51,756 KB |
testcase_36 | AC | 112 ms
52,116 KB |
testcase_37 | AC | 98 ms
52,092 KB |
testcase_38 | AC | 59 ms
50,604 KB |
testcase_39 | AC | 61 ms
50,304 KB |
testcase_40 | AC | 73 ms
51,452 KB |
testcase_41 | AC | 60 ms
50,600 KB |
testcase_42 | AC | 57 ms
50,336 KB |
testcase_43 | AC | 57 ms
50,376 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int c = sc.nextInt(); int v = sc.nextInt(); ArrayList<ArrayList<Route>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } int[] ss = new int[v]; for (int i = 0; i < v; i++) { ss[i] = sc.nextInt() - 1; } int[] ts = new int[v]; for (int i = 0; i < v; i++) { ts[i] = sc.nextInt() - 1; } int[] ys = new int[v]; for (int i = 0; i < v; i++) { ys[i] = sc.nextInt(); } for (int i = 0; i < v; i++) { graph.get(ss[i]).add(new Route(ts[i], ys[i], sc.nextInt())); } PriorityQueue<Route> queue = new PriorityQueue<>(); queue.add(new Route(0, 0, 0)); int[][] costs = new int[n][c + 1]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Route r = queue.poll(); if (r.yen > c || costs[r.idx][r.yen] <= r.time) { continue; } costs[r.idx][r.yen] = r.time; for (Route x : graph.get(r.idx)) { queue.add(new Route(x.idx, r.yen + x.yen, r.time + x.time)); } } int ans = Integer.MAX_VALUE; for (int x : costs[n - 1]) { ans = Math.min(ans, x); } if (ans == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(ans); } } static class Route implements Comparable<Route> { int idx; int yen; int time; public Route(int idx, int yen, int time) { this.idx = idx; this.yen = yen; this.time = time; } public int compareTo(Route r) { return time - r.time; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }