結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | tenten |
提出日時 | 2021-04-13 13:38:03 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,110 bytes |
コンパイル時間 | 2,473 ms |
コンパイル使用メモリ | 81,828 KB |
実行使用メモリ | 118,692 KB |
最終ジャッジ日時 | 2024-06-29 14:10:07 |
合計ジャッジ時間 | 18,200 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
38,592 KB |
testcase_01 | AC | 65 ms
37,832 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1,348 ms
104,984 KB |
testcase_04 | AC | 1,527 ms
79,312 KB |
testcase_05 | AC | 676 ms
54,588 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1,693 ms
95,124 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 1,793 ms
101,068 KB |
testcase_10 | AC | 756 ms
60,364 KB |
testcase_11 | AC | 665 ms
57,140 KB |
testcase_12 | AC | 745 ms
65,080 KB |
testcase_13 | AC | 306 ms
47,340 KB |
testcase_14 | AC | 264 ms
45,284 KB |
testcase_15 | WA | - |
testcase_16 | AC | 707 ms
68,588 KB |
testcase_17 | AC | 219 ms
47,340 KB |
testcase_18 | WA | - |
testcase_19 | AC | 863 ms
66,008 KB |
testcase_20 | AC | 1,045 ms
80,956 KB |
testcase_21 | AC | 1,225 ms
78,152 KB |
testcase_22 | AC | 884 ms
80,484 KB |
testcase_23 | AC | 801 ms
72,896 KB |
testcase_24 | AC | 875 ms
70,128 KB |
testcase_25 | AC | 1,763 ms
81,796 KB |
testcase_26 | AC | 1,865 ms
84,096 KB |
testcase_27 | AC | 900 ms
62,620 KB |
testcase_28 | TLE | - |
testcase_29 | AC | 1,396 ms
80,408 KB |
testcase_30 | WA | - |
testcase_31 | AC | 1,576 ms
91,432 KB |
testcase_32 | AC | 1,474 ms
100,620 KB |
testcase_33 | WA | - |
testcase_34 | AC | 944 ms
65,384 KB |
testcase_35 | AC | 821 ms
63,176 KB |
testcase_36 | AC | 1,410 ms
76,576 KB |
testcase_37 | AC | 1,331 ms
78,332 KB |
testcase_38 | AC | 493 ms
53,196 KB |
testcase_39 | AC | 707 ms
68,380 KB |
testcase_40 | WA | - |
testcase_41 | AC | 308 ms
47,372 KB |
testcase_42 | AC | 304 ms
47,732 KB |
testcase_43 | AC | 1,012 ms
81,180 KB |
testcase_44 | AC | 1,024 ms
81,232 KB |
testcase_45 | AC | 1,054 ms
81,300 KB |
testcase_46 | AC | 779 ms
71,084 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
ソースコード
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; for (int i = 1; i < n; i++) { if (costs[i] != Integer.MAX_VALUE) { queue.add(new Path(i, 0)); } } } 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(); } }