fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define pii pair <int, int>
  5. #define fi first
  6. #define se second
  7. const int MAXN= 1e3+5;
  8. int dx[] = {0,-1,1,0};
  9. int dy[] = {1,0,0,-1};
  10.  
  11. char g[MAXN][MAXN];
  12. queue <pii> q;
  13. int n, m, a1, b1, c1, d1;
  14.  
  15. void bfs(int x1, int y1){
  16. q.push({x1, y1});
  17. while(!q.empty()){
  18. pii t = q.front();
  19. q.pop();
  20. for (int i =0; i <4; i++){
  21. int a = t.first + dx[i], b = t.second +dy[i];
  22. if (a== c1 && b == d1 && g[a][b] == 'X'){
  23. cout << "YES" << endl;
  24. exit(0);
  25.  
  26. }
  27. if ( a >= 1 && a <= n && b >= 1 && b <= m && g[a][b] == '.'){
  28. g[a][b] = 'X';
  29. q.push({a, b});
  30. }
  31. }
  32. }
  33. cout << "NO" << endl;
  34. exit(0);
  35. }
  36. signed main(){
  37. cin >> n >> m;
  38. for (int i =1; i <= n; i++){
  39. for (int j =1; j <= m; j++){
  40. cin >> g[i][j];
  41. }
  42. }
  43. cin >> a1 >> b1 >> c1 >> d1;
  44. bfs(a1,b1);
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5284KB
stdin
4 7
..X.XX.
.XX..X.
X...X..
X......
2 2
1 6
stdout
YES