#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr ll LINF = 1e18; constexpr int MOD = 1000000007; vector dx = {0,0,1,-1,0,0,2,-2}; vector dy = {1,-1,0,0,2,-2,0,0}; int main(){ int h,w; cin >> h >> w; int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy; --sx;--sy;--gx;--gy; vector maze(h); rep(i,h) cin >> maze[i]; vector> seen(h,vector(w,false)); queue

q; q.push(P(sx,sy)); while(!q.empty()){ int x,y; tie(x,y) = q.front(); q.pop(); if(seen[x][y]) continue; seen[x][y] = true; rep(i,4){ int new_x = x + dx[i]; int new_y = y + dy[i]; if(0 <= new_x && new_x < h && 0 <= new_y && new_y < w){ if(abs(maze[x][y]-maze[new_x][new_y]) <= 1 && !seen[new_x][new_y]){ q.push(P(new_x,new_y)); } } } for(int i=4;i<8;i++){ int new_x = x + dx[i]; int new_y = y + dy[i]; if(0 <= new_x && new_x < h && 0 <= new_y && new_y < w){ if(maze[x][y] == maze[new_x][new_y] && maze[(x+new_x)/2][(y+new_y)/2] < maze[x][y] && !seen[new_x][new_y]){ q.push(P(new_x,new_y)); } } } } cout << (seen[gx][gy] ? "YES" : "NO") << endl; return 0; }