結果
問題 | No.424 立体迷路 |
ユーザー | 37zigen |
提出日時 | 2016-09-22 22:49:27 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,751 bytes |
コンパイル時間 | 3,899 ms |
コンパイル使用メモリ | 78,828 KB |
実行使用メモリ | 648,592 KB |
最終ジャッジ日時 | 2024-04-28 19:50:32 |
合計ジャッジ時間 | 12,171 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
40,256 KB |
testcase_01 | AC | 132 ms
41,196 KB |
testcase_02 | AC | 121 ms
40,496 KB |
testcase_03 | AC | 137 ms
41,500 KB |
testcase_04 | AC | 140 ms
41,156 KB |
testcase_05 | AC | 132 ms
41,192 KB |
testcase_06 | AC | 122 ms
39,924 KB |
testcase_07 | AC | 134 ms
40,976 KB |
testcase_08 | AC | 123 ms
39,876 KB |
testcase_09 | AC | 137 ms
41,028 KB |
testcase_10 | AC | 136 ms
41,104 KB |
testcase_11 | AC | 134 ms
41,256 KB |
testcase_12 | AC | 137 ms
41,372 KB |
testcase_13 | AC | 121 ms
40,040 KB |
testcase_14 | AC | 123 ms
40,132 KB |
testcase_15 | AC | 124 ms
39,856 KB |
testcase_16 | AC | 140 ms
41,288 KB |
testcase_17 | AC | 142 ms
41,480 KB |
testcase_18 | AC | 142 ms
41,164 KB |
testcase_19 | AC | 129 ms
40,360 KB |
testcase_20 | AC | 144 ms
41,396 KB |
testcase_21 | AC | 122 ms
40,244 KB |
testcase_22 | AC | 138 ms
41,304 KB |
testcase_23 | AC | 138 ms
41,156 KB |
testcase_24 | MLE | - |
testcase_25 | -- | - |
ソースコード
package No400番台; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Scanner; public class B { public static void main(String[] args) { new B().run(); } void run() { solver(); } void solver() { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); int sy = sc.nextInt() - 1; int sx = sc.nextInt() - 1; int gy = sc.nextInt() - 1; int gx = sc.nextInt() - 1; char[][] tmp = new char[h][w]; for (int i = 0; i < h; i++) { tmp[i] = sc.next().toCharArray(); } int[][] table = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { table[i][j] = tmp[i][j] - '0'; } } ArrayDeque<P> que = new ArrayDeque<>(); boolean[][] arrived = new boolean[h][w]; arrived[sy][sx] = true; que.add(new P(sx, sy)); while (!que.isEmpty()) { P p = que.poll(); arrived[p.y][p.x] = true; for (int i = 0; i < 4; i++) { int nx = p.x + dx[i]; int ny = p.y + dy[i]; if (0 <= nx && nx < w && 0 <= ny && ny < h && !arrived[ny][nx]) { if (Math.abs(table[p.y][p.x] - table[ny][nx]) <= 1) { que.add(new P(nx, ny)); } } int nnx = p.x + 2 * dx[i]; int nny = p.y + 2 * dy[i]; if (0 <= nnx && nnx < w && 0 <= nny && nny < h && !arrived[nny][nnx]) { if (table[p.y][p.x] == table[nny][nnx] && table[p.y][p.x] > table[ny][nx]) { que.add(new P(nnx, nny)); } } } } if (arrived[gy][gx]) { System.out.println("YES"); } else { System.out.println("NO"); } } int[] dx = { 1, -1, 0, 0 }; int[] dy = { 0, 0, 1, -1 }; class P { int x; int y; P(int x, int y) { this.x = x; this.y = y; } } void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }