Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int mat[1000][1000];
  6. bool mark[1000][1000];
  7. int m, n;
  8.  
  9. bool moze(int x, int y)
  10. {
  11. if(x >= 0 && x < n && y >= 0 && y < m) return true;
  12. return false;
  13. }
  14.  
  15. bool put(int x, int y)
  16. {
  17. //cout << x << " " << y << " ";
  18. mark[x][y] = true;
  19. if(x == m - 1 && y == n - 1) return true;
  20.  
  21. if(moze(x-1, y) && mat[x-1][y] == 0 && !mark[x-1][y])
  22. if(put(x-1,y) == true) return true;
  23.  
  24. if(moze(x+1, y) && mat[x+1][y] == 0 && !mark[x+1][y])
  25. if(put(x+1,y) == true) return true;
  26.  
  27. if(moze(x, y-1) && mat[x][y-1] == 0 && !mark[x][y-1])
  28. if(put(x,y-1) == true) return true;
  29.  
  30. if(moze(x, y+1) && mat[x][y+1] == 0 && !mark[x][y+1])
  31. if(put(x,y+1) == true) return true;
  32.  
  33. mark[x][y] = false;
  34. return false;
  35.  
  36.  
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42. ios_base::sync_with_stdio(false);
  43. cin.tie(NULL);
  44.  
  45.  
  46. cin >> n >> m;
  47. for(int i = 0; i < n; i ++)
  48. {
  49. string s;
  50. cin >> s;
  51. for(int j = 0; j < m; j++)
  52. {
  53. if(s[j] == '.') mat[i][j] = 0;
  54. else mat[i][j] = 1;
  55. }
  56. }
  57.  
  58. if(put(0, 0)) cout << "da";
  59. else cout << "ne";
  60.  
  61.  
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement