#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 int H, W; int level[59][59]; bool isfound[59][59]; int dx[4] = { 1,0,-1,0 }; int dy[4] = { 0,1,0,-1 }; bool isrange(int x, int y) { bool flag = true; if (x <= 0 || x > H) flag = false; if (y <= 0 || y > W) flag = false; return flag; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; P start, goal; cin >> start.first >> start.second >> goal.first >> goal.second; for (int i = 0; i < H; i++) { string S; cin >> S; for (int j = 0; j < W; j++) { level[i + 1][j + 1] = (S[j] - '0'); } } queue

Q; isfound[start.first][start.second] = true; Q.push(start); while (!Q.empty()) { P cur = Q.front(); Q.pop(); int cx = cur.first; int cy = cur.second; for (int i = 0; i < 4; i++) { int nx = cx + dx[i]; int ny = cy + dy[i]; if (isrange(nx, ny)) { if (!isfound[nx][ny] && abs(level[cx][cy] - level[nx][ny]) <= 1) { isfound[nx][ny] = true; Q.push(P(nx,ny)); } } } for (int i = 0; i < 4; i++) { int nx = cx + 2*dx[i]; int ny = cy + 2*dy[i]; if (isrange(nx, ny)) { if (!isfound[nx][ny] && level[cx][cy] == level[nx][ny] && level[cx][cy] > level[cx+dx[i]][cy+dy[i]]) { isfound[nx][ny] = true; Q.push(P(nx, ny)); } } } } if (isfound[goal.first][goal.second]) cout << "YES" << endl; else cout << "NO" << endl; return 0; }