#include #include #include #include #include #include #include #include using namespace std; using ll = long long int; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define YES(n) std::cout << ((n) ? "YES" : "NO" ) << "\n"; #define Yes(n) std::cout << ((n) ? "Yes" : "No" ) << "\n"; #define ALL_INCLUDED_ENVIRONMENT template class C> std::ostream& operator<<(std::ostream& o, const C& v) { o << "{"; bool init = 1; for (auto e : v) { if (init) { init = 0; } else { o << ", "; } o << e; } o << "}"; return o; } template std::ostream& operator<<(std::ostream& o, const std::pair& p) { o << "(" << p.first << ", " << p.second << ")"; return o; } ll h, w, sx, sy, gx, gy; vector > bs; queue> que; vector > visited; void step(ll x, ll y, ll newx, ll newy) { if (newx >= 0 && newx < h && newy >= 0 && newy < w && abs(bs[x][y] - bs[newx][newy]) <= 1 && visited[newx][newy] == 0) { visited[newx][newy] = 1; que.push(make_pair(newx, newy)); } } void jump(ll x, ll y, ll newx, ll newy) { ll midx = (x + newx)/2; ll midy = (y + newy)/2; if (newx >= 0 && newx < h && newy >= 0 && newy < w && bs[x][y] == bs[newx][newy] && bs[midx][midy] < bs[x][y] && visited[newx][newy] == 0) { visited[newx][newy] = 1; que.push(make_pair(newx, newy)); } } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cin >> h >> w >> sx >> sy >> gx >> gy; cin.ignore(); sx--; sy--; gx--; gy--; bs = vector >(h, vector(w, 0)); visited = vector >(h, vector(w, 0)); visited[sx][sy] = 1; que.push(make_pair(sx, sy)); string line; REP (i, h) { getline(cin, line); REP (j, w) { assert('0' <= line[j] && line[j] <= '9'); bs[i][j] = line[j]-'0'; } } while (!que.empty()) { pair node = que.front(); ll x = node.first; ll y = node.second; que.pop(); step(x, y, x-1, y); step(x, y, x+1, y); step(x, y, x, y-1); step(x, y, x, y+1); jump(x, y, x-2, y); jump(x, y, x+2, y); jump(x, y, x, y-2); jump(x, y, x, y+2); } YES(visited[gx][gy]); return 0; }