結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-22 22:49:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,751 bytes |
| コンパイル時間 | 4,107 ms |
| コンパイル使用メモリ | 78,716 KB |
| 実行使用メモリ | 684,824 KB |
| 最終ジャッジ日時 | 2024-11-17 15:00:56 |
| 合計ジャッジ時間 | 16,617 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 MLE * 1 |
| other | AC * 19 TLE * 2 |
ソースコード
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));
}
}