#include <vector> #include <string> #include <cstdlib> #include <iostream> using namespace std; void check(int h, int w, int cx, int cy, int gx, int gy, bool& possible, vector<vector<int>>& visited, vector<string>& maze) { if (cx == gx && cy == gy) { possible = true; return; } // cout << cx << " " << cy << endl; visited[cx - 1][cy - 1] = 1; if (cx < h && abs(maze[cx - 1][cy - 1] - maze[cx][cy - 1]) <= 1 && !visited[cx][cy - 1]) { check(h, w, cx + 1, cy, gx, gy, possible, visited, maze); } if (cx > 1 && abs(maze[cx - 1][cy - 1] - maze[cx - 2][cy - 1]) <= 1 && !visited[cx - 2][cy - 1]) { check(h, w, cx - 1, cy, gx, gy, possible, visited, maze); } if (cy < w && abs(maze[cx - 1][cy - 1] - maze[cx - 1][cy]) <= 1 && !visited[cx - 1][cy]) { check(h, w, cx, cy + 1, gx, gy, possible, visited, maze); } if (cy > 1 && abs(maze[cx - 1][cy - 1] - maze[cx - 1][cy - 2]) <= 1 && !visited[cx - 1][cy - 2]) { check(h, w, cx, cy - 1, gx, gy, possible, visited, maze); } if (cx < h - 1 && maze[cx - 1][cy - 1] > maze[cx][cy - 1] && maze[cx - 1][cy - 1] == maze[cx + 1][cy - 1] && !visited[cx + 1][cy - 1]) { check(h, w, cx + 2, cy, gx, gy, possible, visited, maze); } if (cx > 2 && maze[cx - 1][cy - 1] > maze[cx - 2][cy - 1] && maze[cx - 1][cy - 1] == maze[cx - 3][cy - 1] && !visited[cx - 3][cy - 1]) { check(h, w, cx - 2, cy, gx, gy, possible, visited, maze); } if (cy < w - 1 && maze[cx - 1][cy - 1] > maze[cx - 1][cy] && maze[cx - 1][cy - 1] == maze[cx - 1][cy + 1] && !visited[cx - 1][cy + 1]) { check(h, w, cx, cy + 2, gx, gy, possible, visited, maze); } if (cy > 2 && maze[cx - 1][cy - 1] > maze[cx - 1][cy - 2] && maze[cx - 1][cy - 1] == maze[cx - 1][cy - 3] && !visited[cx - 1][cy - 3]) { check(h, w, cx, cy - 2, gx, gy, possible, visited, maze); } } int main() { int h, w, sx, sy, gx, gy; cin >> h >> w >> sx >> sy >> gx >> gy; vector<vector<int>> visited (h, vector<int> (w, 0)); vector<string> maze(h); for (int i = 0; i < h; i++) { cin >> maze[i]; } bool possible = false; check(h, w, sx, sy, gx, gy, possible, visited, maze); if (possible) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }