結果
問題 | No.340 雪の足跡 |
ユーザー | htensai |
提出日時 | 2020-05-14 14:00:29 |
言語 | Java19 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,589 bytes |
コンパイル時間 | 3,157 ms |
コンパイル使用メモリ | 74,440 KB |
実行使用メモリ | 81,304 KB |
最終ジャッジ日時 | 2023-10-13 08:25:05 |
合計ジャッジ時間 | 26,812 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 105 ms
39,068 KB |
testcase_01 | AC | 108 ms
39,592 KB |
testcase_02 | AC | 111 ms
39,508 KB |
testcase_03 | AC | 114 ms
39,552 KB |
testcase_04 | AC | 118 ms
39,676 KB |
testcase_05 | AC | 123 ms
39,768 KB |
testcase_06 | AC | 126 ms
39,524 KB |
testcase_07 | AC | 114 ms
39,364 KB |
testcase_08 | AC | 114 ms
39,232 KB |
testcase_09 | AC | 104 ms
39,584 KB |
testcase_10 | AC | 110 ms
39,004 KB |
testcase_11 | AC | 222 ms
44,560 KB |
testcase_12 | AC | 200 ms
42,764 KB |
testcase_13 | AC | 209 ms
43,800 KB |
testcase_14 | AC | 527 ms
47,232 KB |
testcase_15 | AC | 543 ms
47,000 KB |
testcase_16 | AC | 475 ms
46,100 KB |
testcase_17 | AC | 623 ms
47,808 KB |
testcase_18 | AC | 557 ms
48,192 KB |
testcase_19 | AC | 672 ms
50,460 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 161 ms
68,076 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 621 ms
49,584 KB |
testcase_27 | AC | 363 ms
60,436 KB |
testcase_28 | AC | 685 ms
64,756 KB |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
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; 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) { queue.add(new Path(p.height - 1, p.width, p.value + 1)); } if (p.height < h - 1 && vfield[p.width][p.height] > 0) { queue.add(new Path(p.height + 1, p.width, p.value + 1)); } if (p.width > 0 && hfield[p.height][p.width - 1] > 0) { queue.add(new Path(p.height, p.width - 1, p.value + 1)); } if (p.width < w - 1 && hfield[p.height][p.width] > 0) { 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; } } }