Advertisement
Saleh127

Spoj Spikey mazes

Feb 24th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. char a[100][100];
  6. bool v[100][100];
  7. ll ans=1e9,z=0,n,m,c=-1,d=-1;
  8. void dfs(ll x,ll y)
  9. {
  10. if(v[x][y]) return ;
  11.  
  12. if(v[x][y]==0 && a[x][y]!='#' && x>=0 && x<n && y>=0 && y<m)
  13. {
  14. v[x][y]=1;
  15. if(a[x][y]=='s') z++;
  16. if(a[x][y]=='x')
  17. {
  18. c=x;
  19. d=y;
  20. return;
  21. }
  22. dfs(x+1,y);
  23. dfs(x-1,y);
  24. dfs(x,y+1);
  25. dfs(x,y-1);
  26. }
  27.  
  28.  
  29. }
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. cout.tie(0);
  36.  
  37. ll b,x,y,i,j,k,l;
  38. cin>>n>>m>>b;
  39. for(i=0; i<n; i++)
  40. {
  41. for(j=0; j<m; j++)
  42. {
  43. cin>>a[i][j];
  44. if(a[i][j]=='@')
  45. {
  46. x=i;
  47. y=j;
  48. }
  49. }
  50. }
  51.  
  52. dfs(x,y);
  53.  
  54. if(z*2<=b && c!=-1 && d!=-1) cout<<"SUCCESS"<<endl;
  55. else cout<<"IMPOSSIBLE"<<endl;
  56. return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement