結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | tenten |
提出日時 | 2021-04-13 13:29:00 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,916 bytes |
コンパイル時間 | 2,169 ms |
コンパイル使用メモリ | 81,228 KB |
実行使用メモリ | 97,016 KB |
最終ジャッジ日時 | 2024-06-29 14:05:17 |
合計ジャッジ時間 | 19,020 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
37,932 KB |
testcase_01 | AC | 80 ms
38,536 KB |
testcase_02 | AC | 1,903 ms
97,016 KB |
testcase_03 | AC | 1,070 ms
81,164 KB |
testcase_04 | AC | 1,267 ms
67,104 KB |
testcase_05 | AC | 705 ms
53,884 KB |
testcase_06 | AC | 1,549 ms
82,824 KB |
testcase_07 | AC | 1,496 ms
87,692 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 1,430 ms
86,340 KB |
testcase_10 | AC | 805 ms
62,436 KB |
testcase_11 | AC | 694 ms
56,784 KB |
testcase_12 | AC | 771 ms
65,116 KB |
testcase_13 | AC | 316 ms
48,144 KB |
testcase_14 | AC | 263 ms
45,432 KB |
testcase_15 | AC | 328 ms
47,372 KB |
testcase_16 | AC | 732 ms
68,984 KB |
testcase_17 | AC | 232 ms
46,960 KB |
testcase_18 | AC | 271 ms
48,960 KB |
testcase_19 | AC | 790 ms
65,116 KB |
testcase_20 | AC | 893 ms
78,032 KB |
testcase_21 | AC | 1,149 ms
74,572 KB |
testcase_22 | AC | 1,058 ms
89,800 KB |
testcase_23 | AC | 757 ms
71,672 KB |
testcase_24 | AC | 817 ms
69,736 KB |
testcase_25 | AC | 1,774 ms
90,240 KB |
testcase_26 | AC | 1,806 ms
83,184 KB |
testcase_27 | AC | 714 ms
61,196 KB |
testcase_28 | TLE | - |
testcase_29 | AC | 1,253 ms
79,452 KB |
testcase_30 | AC | 1,770 ms
83,072 KB |
testcase_31 | AC | 1,396 ms
86,692 KB |
testcase_32 | AC | 1,515 ms
96,568 KB |
testcase_33 | AC | 1,086 ms
77,296 KB |
testcase_34 | AC | 817 ms
63,324 KB |
testcase_35 | AC | 683 ms
61,676 KB |
testcase_36 | AC | 1,239 ms
75,500 KB |
testcase_37 | AC | 1,350 ms
77,980 KB |
testcase_38 | AC | 522 ms
53,328 KB |
testcase_39 | AC | 675 ms
67,480 KB |
testcase_40 | AC | 694 ms
68,912 KB |
testcase_41 | AC | 316 ms
48,908 KB |
testcase_42 | AC | 307 ms
47,336 KB |
testcase_43 | AC | 1,034 ms
81,432 KB |
testcase_44 | AC | 950 ms
81,324 KB |
testcase_45 | AC | 949 ms
80,996 KB |
testcase_46 | AC | 730 ms
69,676 KB |
testcase_47 | AC | 1,108 ms
84,544 KB |
testcase_48 | AC | 859 ms
78,244 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int mm = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < mm; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int d = sc.nextInt(); if (!graph.get(a).containsKey(b) || graph.get(a).get(b) < d) { graph.get(a).put(b, d); } if (!graph.get(b).containsKey(a) || graph.get(b).get(a) < d) { graph.get(b).put(a, d); } } int left = 0; int right = Integer.MAX_VALUE / 2; PriorityQueue<Path> queue = new PriorityQueue<>(); int[] costs = new int[n]; while (right - left > 1) { int m = (left + right) / 2; queue.add(new Path(0, 0)); check(m, costs, queue); if (costs[n - 1] == Integer.MAX_VALUE) { right = m; } else { left = m; } } queue.add(new Path(0, 0)); check(left, costs, queue); System.out.println(left + " " + costs[n - 1]); } static void check(int size, int[] costs, PriorityQueue<Path> queue) { Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx).keySet()) { if (graph.get(p.idx).get(x) < size) { continue; } queue.add(new Path(x, p.value + 1)); } } } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }