#include #include #include using namespace std; using P = pair; const int MAX_H = 60; const int MAX_W = 60; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; string b[MAX_H]; bool visited[MAX_H][MAX_W]; int h, w, sx, sy, gx, gy; bool inside(int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; } int main() { cin >> h >> w; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; for (int i = 0; i < h; i++) { cin >> b[i]; } queue

que; que.push(P(sx, sy)); visited[sx][sy] = true; while (!que.empty()) { P p = que.front(); que.pop(); if (p.first == gx && p.second == gy) { cout << "YES" << endl; return 0; } int x = p.first, y = p.second; for (int i = 0; i < 4; i++) { for (int d = 1; d <= 2; d++) { int nx = x + dx[i] * d, ny = y + dy[i] * d; if (!inside(nx, ny) || visited[nx][ny]) continue; if (d == 1 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) <= 1) { que.push(P(nx, ny)); visited[nx][ny] = true; } if (d == 2 && abs((b[x][y] - '0') - (b[nx][ny] - '0')) == 0 && b[x][y] - '0' > b[x + dx[i]][y + dy[i]] - '0') { que.push(P(nx, ny)); visited[nx][ny] = true; } } } } cout << "NO" << endl; return 0; }