結果
問題 | No.340 雪の足跡 |
ユーザー | tenten |
提出日時 | 2020-10-03 14:57:10 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,387 bytes |
コンパイル時間 | 3,182 ms |
コンパイル使用メモリ | 81,396 KB |
実行使用メモリ | 113,316 KB |
最終ジャッジ日時 | 2023-09-25 05:14:28 |
合計ジャッジ時間 | 10,623 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
62,820 KB |
testcase_01 | AC | 120 ms
56,112 KB |
testcase_02 | AC | 121 ms
56,292 KB |
testcase_03 | AC | 122 ms
56,172 KB |
testcase_04 | AC | 123 ms
55,488 KB |
testcase_05 | AC | 121 ms
56,548 KB |
testcase_06 | AC | 126 ms
55,864 KB |
testcase_07 | AC | 121 ms
56,048 KB |
testcase_08 | AC | 123 ms
55,808 KB |
testcase_09 | AC | 124 ms
55,892 KB |
testcase_10 | AC | 125 ms
56,036 KB |
testcase_11 | AC | 282 ms
61,704 KB |
testcase_12 | AC | 267 ms
61,180 KB |
testcase_13 | AC | 298 ms
61,424 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int h = sc.nextInt(); int n = sc.nextInt(); int size = w * h; ArrayList<HashSet<Integer>> graph = new ArrayList<>(); for (int i = 0; i < size; i++) { graph.add(new HashSet<>()); } for (int i = 0; i < n; i++) { int m = sc.nextInt(); int prev = sc.nextInt(); for (int j = 0; j < m; j++) { int next = sc.nextInt(); if (prev / w == next / w) { if (prev < next) { while (prev < next) { graph.get(prev).add(prev + 1); graph.get(prev + 1).add(prev); prev++; } } else { while (prev > next) { graph.get(prev).add(prev - 1); graph.get(prev - 1).add(prev); prev--; } } } else { if (prev < next) { while (prev < next) { graph.get(prev).add(prev + w); graph.get(prev + w).add(prev); prev += w; } } else { while (prev > next) { graph.get(prev).add(prev - w); graph.get(prev - w).add(prev); prev -= w; } } } prev = next; } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); int[] costs = new int[size]; 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)) { queue.add(new Path(x, p.value + 1)); } } if (costs[size - 1] == Integer.MAX_VALUE) { System.out.println("Odekakedekinai.."); } else { System.out.println(costs[size - 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; } } }