結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
atkrym
|
| 提出日時 | 2016-10-19 15:39:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,908 bytes |
| コンパイル時間 | 2,233 ms |
| コンパイル使用メモリ | 77,572 KB |
| 実行使用メモリ | 41,624 KB |
| 最終ジャッジ日時 | 2024-11-22 16:40:30 |
| 合計ジャッジ時間 | 6,290 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
ソースコード
import java.util.*;
public class Main {
private static Scanner sc = new Scanner(System.in);
private static int h;
private static int w;
private static int sx;
private static int sy;
private static int ex;
private static int ey;
private static int[][] ary;
private static boolean[][] is;
public static void main(String[] args) throws Exception {
h = sc.nextInt();
w = sc.nextInt();
sx = sc.nextInt()-1;
sy = sc.nextInt()-1;
ex = sc.nextInt()-1;
ey = sc.nextInt()-1;
ary = new int[h][w];
is = new boolean[h][w];
for (int i = 0;i < h;i++) {
String s = sc.next();
for (int j = 0;j < w;j++) {
ary[i][j] = Integer.parseInt(s.substring(j, j+1));
}
}
if (move(sx, sy)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
private static boolean move(int x, int y) {
if (x == ex && y == ey) return true;
int[] dx = {-1, 0, 1, 0, -2, 0, 2, 0};
int[] dy = {0, 1, 0, -1, 0, 2, 0, -2};
int height = ary[x][y];
is[x][y] = true;
for (int i = 0;i < 8;i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < w && !is[nx][ny]) {
int nheight = ary[nx][ny];
boolean m = false;
if (i < 4) {
m = (height-1 <= nheight && nheight <= height+1);
} else {
m = (height == nheight);
}
if (m) {
if (move(nx, ny)) {
return true;
}
}
}
}
return false;
}
}
atkrym