結果
問題 | No.340 雪の足跡 |
ユーザー | tenten |
提出日時 | 2020-12-29 02:39:33 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,646 bytes |
コンパイル時間 | 2,772 ms |
コンパイル使用メモリ | 78,688 KB |
実行使用メモリ | 77,040 KB |
最終ジャッジ日時 | 2024-04-15 02:08:41 |
合計ジャッジ時間 | 23,763 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,164 KB |
testcase_01 | AC | 52 ms
50,504 KB |
testcase_02 | AC | 51 ms
50,472 KB |
testcase_03 | AC | 51 ms
50,420 KB |
testcase_04 | AC | 51 ms
50,516 KB |
testcase_05 | AC | 52 ms
50,364 KB |
testcase_06 | AC | 51 ms
50,472 KB |
testcase_07 | AC | 51 ms
50,292 KB |
testcase_08 | AC | 52 ms
50,664 KB |
testcase_09 | AC | 52 ms
50,152 KB |
testcase_10 | AC | 52 ms
50,504 KB |
testcase_11 | AC | 98 ms
51,784 KB |
testcase_12 | AC | 96 ms
51,920 KB |
testcase_13 | AC | 109 ms
52,084 KB |
testcase_14 | AC | 309 ms
57,028 KB |
testcase_15 | AC | 321 ms
58,040 KB |
testcase_16 | AC | 252 ms
57,244 KB |
testcase_17 | AC | 375 ms
57,808 KB |
testcase_18 | AC | 350 ms
57,108 KB |
testcase_19 | AC | 380 ms
57,956 KB |
testcase_20 | AC | 866 ms
75,516 KB |
testcase_21 | AC | 498 ms
58,896 KB |
testcase_22 | AC | 108 ms
64,560 KB |
testcase_23 | TLE | - |
testcase_24 | AC | 649 ms
68,812 KB |
testcase_25 | AC | 913 ms
74,448 KB |
testcase_26 | AC | 268 ms
57,020 KB |
testcase_27 | AC | 128 ms
54,264 KB |
testcase_28 | AC | 318 ms
57,360 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.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); int w = Integer.parseInt(first[0]); int h = Integer.parseInt(first[1]); int[][] ver = new int[h + 1][w + 1]; int[][] hor = new int[h + 1][w + 1]; int n = Integer.parseInt(first[2]); for (int i = 0; i < n; i++) { int m = Integer.parseInt(br.readLine()); String[] line = br.readLine().split(" ", m + 1); int prev = Integer.parseInt(line[0]); for (int j = 0; j < m; j++) { int x = Integer.parseInt(line[j + 1]); int min = Math.min(prev, x); int max = Math.max(prev, x); if (max - min >= w) { ver[min / w][min % w]++; ver[max / w + 1][max % w]--; } else { hor[min / w][min % w]++; hor[max / w][max % w + 1]--; } prev = x; } } for (int i = 0; i < h; i++) { for (int j = 1; j < w; j++) { hor[i][j] += hor[i][j - 1]; } } for (int i = 0; i < w; i++) { for (int j = 1; j < h; j++) { ver[j][i] += ver[j - 1][i]; } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); int[][] costs = new int[h][w]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.r][p.c] <= p.value) { continue; } costs[p.r][p.c] = p.value; if (p.r > 0 && ver[p.r][p.c] > 0 && ver[p.r - 1][p.c] > 0) { queue.add(new Path(p.r - 1, p.c, p.value + 1)); } if (p.r < h - 1 && ver[p.r][p.c] > 0 && ver[p.r + 1][p.c] > 0) { queue.add(new Path(p.r + 1, p.c, p.value + 1)); } if (p.c > 0 && hor[p.r][p.c] > 0 && hor[p.r][p.c - 1] > 0) { queue.add(new Path(p.r, p.c - 1, p.value + 1)); } if (p.c < w - 1 && hor[p.r][p.c] > 0 && hor[p.r][p.c + 1] > 0) { queue.add(new Path(p.r, p.c + 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 r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }