#include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair P; #define EACH(i,a) for (auto& i : a) #define FOR(i,a,b) for (ll i=(a);i<(b);i++) #define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--) #define REP(i,n) for (ll i=0;i<(n);i++) #define RREP(i,n) for (ll i=(n)-1;i>=0;i--) #define debug(x) cout<<#x<<": "< istream& operator>>(istream& is, vector& vec) { EACH(x,vec) is >> x; return is; } template ostream& operator<<(ostream& os, vector& vec) { REP(i,vec.size()) { if (i) os << " "; os << vec[i]; } return os; } template ostream& operator<<(ostream& os, vector< vector >& vec) { REP(i,vec.size()) { if (i) os << endl; os << vec[i]; } return os; } int H, W; const int dx[] = {0, 1, 0, -1}; const int dy[] = {-1, 0, 1, 0}; bool inRange(int x, int y) { return 0 <= x && x < W && 0 <= y && y < H; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> H >> W; int sx, sy, gx, gy; cin >> sy >> sx >> gy >> gx; --sx, --sy, --gx, --gy; vector< vector > h(H, vector(W)); REP(y, H) { string s; cin >> s; REP(x, W) { h[y][x] = s[x]-'0'; } } vector< vector > dist(H, vector(W, inf)); dist[sy][sx] = 0; queue

Q; Q.push({sx, sy}); while ( !Q.empty() ) { P p = Q.front(); Q.pop(); int x, y; tie(x, y) = p; vector

nxt; REP(d, 4) { int nx = x + dx[d], ny = y + dy[d]; if ( inRange(nx, ny) && abs(h[y][x] - h[ny][nx]) <= 1 ) { nxt.pb({nx, ny}); } } REP(d, 4) { int nx = x + dx[d]*2, ny = y + dy[d]*2; if ( inRange(nx, ny) && h[y][x] == h[ny][nx] && h[y+dy[d]][x+dx[d]] <= h[y][x] ) { nxt.pb({nx, ny}); } } EACH(np, nxt) { int nx, ny; tie(nx, ny) = np; if ( dist[y][x]+1 < dist[ny][nx] ) { dist[ny][nx] = dist[y][x]+1; Q.push({nx, ny}); } } } cout << (dist[gy][gx] == inf ? "NO" : "YES") << endl; }