結果
問題 | No.340 雪の足跡 |
ユーザー | htensai |
提出日時 | 2020-05-14 14:03:25 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,801 bytes |
コンパイル時間 | 2,204 ms |
コンパイル使用メモリ | 76,144 KB |
実行使用メモリ | 82,556 KB |
最終ジャッジ日時 | 2023-10-13 08:36:21 |
合計ジャッジ時間 | 26,045 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
56,488 KB |
testcase_01 | AC | 123 ms
55,844 KB |
testcase_02 | AC | 122 ms
56,040 KB |
testcase_03 | AC | 125 ms
55,880 KB |
testcase_04 | AC | 125 ms
55,772 KB |
testcase_05 | AC | 126 ms
55,904 KB |
testcase_06 | AC | 131 ms
55,760 KB |
testcase_07 | AC | 127 ms
55,992 KB |
testcase_08 | AC | 126 ms
56,032 KB |
testcase_09 | AC | 126 ms
55,736 KB |
testcase_10 | AC | 128 ms
53,948 KB |
testcase_11 | AC | 236 ms
59,196 KB |
testcase_12 | AC | 211 ms
59,048 KB |
testcase_13 | AC | 233 ms
60,028 KB |
testcase_14 | AC | 541 ms
61,268 KB |
testcase_15 | AC | 560 ms
60,524 KB |
testcase_16 | AC | 489 ms
58,616 KB |
testcase_17 | AC | 630 ms
61,544 KB |
testcase_18 | AC | 580 ms
60,548 KB |
testcase_19 | AC | 616 ms
61,616 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 175 ms
67,724 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 682 ms
64,680 KB |
testcase_27 | AC | 391 ms
60,388 KB |
testcase_28 | AC | 678 ms
64,776 KB |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
ソースコード
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; int[][] hfield = new int[h][w]; int[][] vfield = new int[w][h]; for (int i = 0; i < n; i++) { int count = sc.nextInt(); int prev = sc.nextInt(); for (int j = 0; j < count; j++) { int current = sc.nextInt(); int left = Math.min(prev, current); int right = Math.max(prev, current); if (right - left < w) { int height = left / w; hfield[height][left % w]++; hfield[height][right % w]--; } else { int width = left % w; vfield[width][left / w]++; vfield[width][right / w]--; } prev = current; } } for (int i = 0; i < h; i++) { for (int j = 1; j < w; j++) { hfield[i][j] += hfield[i][j - 1]; } } for (int i = 0; i < w; i++) { for (int j = 1; j < h; j++) { vfield[i][j] += vfield[i][j - 1]; } } int[][] costs = new int[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(costs[i], Integer.MAX_VALUE); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.height][p.width] <= p.value) { continue; } costs[p.height][p.width] = p.value; if (p.height > 0 && vfield[p.width][p.height - 1] > 0 && costs[p.height - 1][p.width] == Integer.MAX_VALUE) { queue.add(new Path(p.height - 1, p.width, p.value + 1)); } if (p.height < h - 1 && vfield[p.width][p.height] > 0 && costs[p.height + 1][p.width] == Integer.MAX_VALUE) { queue.add(new Path(p.height + 1, p.width, p.value + 1)); } if (p.width > 0 && hfield[p.height][p.width - 1] > 0 && costs[p.height][p.width - 1] == Integer.MAX_VALUE) { queue.add(new Path(p.height, p.width - 1, p.value + 1)); } if (p.width < w - 1 && hfield[p.height][p.width] > 0 && costs[p.height][p.width + 1] == Integer.MAX_VALUE) { queue.add(new Path(p.height, p.width + 1, p.value + 1)); } } if (costs[h - 1][w - 1] == Integer.MAX_VALUE) { System.out.println("Odekakedekinai.."); } else { System.out.println(costs[h - 1][w - 1]); } } static class Path implements Comparable<Path> { int height; int width; int value; public Path(int height, int width, int value) { this.height = height; this.width = width; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }