Advertisement
Falak_Ahmed_Shakib

2D GIRD (WALL)

Jun 3rd, 2020 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef pair<ll,ll>pll;
  6. typedef pair<ll,pair<ll,ll>>plll;
  7. #define F first
  8. #define S second
  9. ll const N=2e6;
  10.  
  11.  
  12. bool vis[1000][1000];
  13.  
  14. bool f,ok=false;
  15.  
  16. ll n,m,a,b,c,d,x,y;
  17. pair<ll,ll>s,e;
  18. char ara[1000][1000];
  19. void input()
  20. {
  21. char ch;
  22. ll i,j;
  23. cin>>n>>m;
  24. for(i=0; i<n; i++)
  25. {
  26. for(j=0; j<m;j++)
  27. {
  28. cin>>ara[i][j];
  29. ch=ara[i][j];
  30. if(ch=='X')
  31. vis[i][j]=true;
  32. }
  33. }
  34. cin>>a>>b>>x>>y;
  35. a--;b--,x--,y--;
  36.  
  37.  
  38.  
  39. }
  40. ll flag=false;
  41. bool check(ll i,ll j)
  42. {
  43. if(i<0 || j<0 || i==n || j==m || (vis[i][j] && flag))
  44. return true;
  45.  
  46. else return false;
  47.  
  48.  
  49. }
  50. void call(ll i,ll j)
  51. {
  52. if(i==x && j==y && vis[i][j] && flag)
  53. {
  54.  
  55. ok=true;
  56.  
  57. return;
  58. }
  59. if(check(i,j))return ;
  60.  
  61. flag=true;
  62.  
  63. vis[i][j]=true;
  64.  
  65. call(i,j-1);
  66. call(i,j+1);
  67. call(i+1,j);
  68. call(i-1,j);
  69.  
  70. }
  71. int main()
  72. {
  73. input();
  74.  
  75.  
  76.  
  77. call(a,b);
  78.  
  79.  
  80. if(ok)cout<<"YES"<<endl;
  81. else cout<<"NO"<<endl;
  82.  
  83.  
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement