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
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)); arrived[ny][nx] = true; } } 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)); arrived[nny][nnx] = true; } } } } 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)); } }