結果

問題 No.424 立体迷路
ユーザー hermione17hermione17
提出日時 2016-09-22 22:41:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 3,376 ms
コンパイル使用メモリ 74,732 KB
実行使用メモリ 56,644 KB
最終ジャッジ日時 2023-09-18 16:45:30
合計ジャッジ時間 7,901 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,812 KB
testcase_01 AC 130 ms
55,976 KB
testcase_02 AC 128 ms
55,972 KB
testcase_03 AC 129 ms
56,052 KB
testcase_04 AC 131 ms
56,012 KB
testcase_05 AC 127 ms
55,580 KB
testcase_06 AC 128 ms
55,896 KB
testcase_07 AC 128 ms
55,872 KB
testcase_08 AC 128 ms
56,012 KB
testcase_09 AC 127 ms
56,008 KB
testcase_10 AC 129 ms
56,084 KB
testcase_11 AC 126 ms
55,996 KB
testcase_12 AC 129 ms
56,196 KB
testcase_13 AC 128 ms
55,972 KB
testcase_14 AC 129 ms
55,592 KB
testcase_15 AC 129 ms
55,832 KB
testcase_16 AC 126 ms
55,604 KB
testcase_17 AC 134 ms
55,556 KB
testcase_18 AC 136 ms
55,876 KB
testcase_19 AC 132 ms
55,852 KB
testcase_20 AC 134 ms
55,628 KB
testcase_21 AC 127 ms
55,756 KB
testcase_22 AC 129 ms
55,836 KB
testcase_23 AC 130 ms
55,812 KB
testcase_24 AC 141 ms
56,596 KB
testcase_25 AC 138 ms
56,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.Scanner;


public class Y424 {
	int h, w, sx, sy, tx, ty;
	String[] s;
	boolean[][] visited;
	
	static int[] dx = { 0, 1, 0, -1 };
	static int[] dy = { 1, 0, -1, 0 };
	
	Y424() throws Exception {
		Scanner in = new Scanner(System.in);
		PrintStream out = new PrintStream(System.out);
		
		h = in.nextInt();
		w = in.nextInt();
		sx = in.nextInt();
		sy = in.nextInt();
		tx = in.nextInt();
		ty = in.nextInt();
		s = new String[h];
		for (int i = 0; i < h; i++) {
			s[i] = in.next();
		}
		
		visited = new boolean[h][w];
		
		visited[sx-1][sy-1] = true;
		dfs(sx-1, sy-1);
		
		if (visited[tx-1][ty-1]) {
			out.println("YES");
		} else {
			out.println("NO");
		}
		
		out.flush();
	}
	
	void dfs(int x, int y) {
		for (int dir = 0; dir < 4; dir++) {
			int xx = x + dx[dir];
			int yy = y + dy[dir];
			
			if (0 <= xx && xx < h && 0 <= yy && yy < w) {
				if (Math.abs((int)s[xx].charAt(yy) - (int)s[x].charAt(y)) <= 1 && !visited[xx][yy]) {
					visited[xx][yy] = true;
					dfs(xx, yy);
				}
							
				int xxx = x + 2 * dx[dir];
				int yyy = y + 2 * dy[dir];
			
				if (0 <= xxx && xxx < h && 0 <= yyy && yyy < w) {
					if (s[x].charAt(y) == s[xxx].charAt(yyy) && (int)s[x].charAt(y) > (int)s[xx].charAt(yy)) {
						if (!visited[xxx][yyy]) {
							visited[xxx][yyy] = true;
							dfs(xxx, yyy);
						}
					}
				}
			}		
		}
	}

	public static void main(String argv[]) throws Exception {
		new Y424();
	}
}
0