結果
問題 | No.1 道のショートカット |
ユーザー | tenten |
提出日時 | 2023-01-25 17:45:19 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,529 bytes |
コンパイル時間 | 2,648 ms |
コンパイル使用メモリ | 87,340 KB |
実行使用メモリ | 52,224 KB |
最終ジャッジ日時 | 2024-06-26 21:08:13 |
合計ジャッジ時間 | 7,727 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
50,496 KB |
testcase_01 | AC | 52 ms
50,620 KB |
testcase_02 | AC | 53 ms
50,588 KB |
testcase_03 | AC | 54 ms
50,520 KB |
testcase_04 | AC | 54 ms
50,508 KB |
testcase_05 | AC | 53 ms
50,472 KB |
testcase_06 | AC | 53 ms
50,652 KB |
testcase_07 | AC | 53 ms
50,320 KB |
testcase_08 | AC | 112 ms
51,920 KB |
testcase_09 | AC | 94 ms
51,692 KB |
testcase_10 | AC | 114 ms
52,040 KB |
testcase_11 | AC | 123 ms
52,020 KB |
testcase_12 | AC | 126 ms
51,936 KB |
testcase_13 | AC | 122 ms
52,036 KB |
testcase_14 | AC | 57 ms
50,464 KB |
testcase_15 | AC | 53 ms
50,528 KB |
testcase_16 | WA | - |
testcase_17 | AC | 54 ms
50,636 KB |
testcase_18 | AC | 58 ms
50,544 KB |
testcase_19 | AC | 57 ms
50,620 KB |
testcase_20 | AC | 80 ms
51,608 KB |
testcase_21 | WA | - |
testcase_22 | AC | 58 ms
50,328 KB |
testcase_23 | AC | 126 ms
52,104 KB |
testcase_24 | AC | 118 ms
52,112 KB |
testcase_25 | AC | 83 ms
51,920 KB |
testcase_26 | AC | 76 ms
50,932 KB |
testcase_27 | AC | 112 ms
52,060 KB |
testcase_28 | AC | 55 ms
50,484 KB |
testcase_29 | AC | 122 ms
52,224 KB |
testcase_30 | AC | 77 ms
51,748 KB |
testcase_31 | AC | 97 ms
51,520 KB |
testcase_32 | AC | 109 ms
52,176 KB |
testcase_33 | AC | 91 ms
52,088 KB |
testcase_34 | AC | 115 ms
52,024 KB |
testcase_35 | AC | 95 ms
51,760 KB |
testcase_36 | AC | 110 ms
51,988 KB |
testcase_37 | WA | - |
testcase_38 | AC | 57 ms
50,264 KB |
testcase_39 | WA | - |
testcase_40 | AC | 74 ms
51,408 KB |
testcase_41 | AC | 58 ms
50,636 KB |
testcase_42 | AC | 53 ms
50,144 KB |
testcase_43 | AC | 53 ms
50,316 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; 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(); int[] starts = new int[v]; for (int i = 0; i < v; i++) { starts[i] = sc.nextInt() - 1; } int[] goals = new int[v]; for (int i = 0; i < v; i++) { goals[i] = sc.nextInt() - 1; } int[] costs = new int[v]; for (int i = 0; i < v; i++) { costs[i] = sc.nextInt(); } ArrayList<ArrayList<Path>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < v; i++) { int x = sc.nextInt(); graph.get(starts[i]).add(new Path(goals[i], costs[i], x)); graph.get(goals[i]).add(new Path(starts[i], costs[i], x)); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, c, 0)); int[][] values = new int[n][c + 1]; for (int[] arr : values) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (values[p.idx][p.cost] <= p.time) { continue; } for (int i = p.cost; i >= 0 && values[p.idx][i] > p.time; i--) { values[p.idx][i] = p.time; } for (Path x : graph.get(p.idx)) { if (x.cost <= p.cost) { queue.add(new Path(x.idx, p.cost - x.cost, p.time + x.time)); } } } if (values[n - 1][0] == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(values[n - 1][0]); } } static class Path implements Comparable<Path> { int idx; int cost; int time; public Path(int idx, int cost, int time) { this.idx = idx; this.cost = cost; this.time = time; } public int compareTo(Path another) { return time - another.time; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }