#include #include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template auto vectors(T a, X x) { return vector(x, a); } template auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector(x, cont); } const int dy[] = { -1, 1, 0, 0 }; const int dx[] = { 0, 0, 1, -1 }; int main() { // input int h, w; cin >> h >> w; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; -- sy; -- sx; -- gy; -- gx; vector > f = vectors(int(), h, w); repeat (y,h) repeat (x,w) { char c; scanf(" %c", &c); f[y][x] = c-'0'; } // compute auto is_on_field = [&](int y, int x) { return 0 <= y and y < h and 0 <= x and x < w; }; vector > dp = vectors(false, h, w); queue > que; auto push = [&](int y, int x) { if (dp[y][x]) return; dp[y][x] = true; que.emplace(y, x); }; push(sy, sx); while (not que.empty()) { int y, x; tie(y, x) = que.front(); que.pop(); repeat (i,4) { int ny = y + dy[i]; int nx = x + dx[i]; if (not is_on_field(ny, nx)) continue; if (abs(f[ny][nx] - f[y][x]) <= 1) { push(ny, nx); } } repeat (i,4) { int ny = y + 2*dy[i]; int nx = x + 2*dx[i]; if (not is_on_field(ny, nx)) continue; if (f[ny][nx] == f[y][x] and f[y + dy[i]][x + dx[i]] < f[y][x]) { push(ny, nx); } } } // output cout << (dp[gy][gx] ? "YES" : "NO") << endl; return 0; }