Advertisement
sherry_ahmos

Untitled

Oct 14th, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <unordered_map>
  12. #include <unordered_set>
  13. using namespace std;
  14.  
  15. #define ll long long
  16. #define nl endl
  17. #define cy cout << "YES\n"
  18. #define cn cout << "NO\n"
  19. #define sz s.size()
  20. #define allv v.begin(), v.end()
  21. void sherry()
  22. {
  23.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  24. #ifndef ONLINE_JUDGE
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28. ll n, m;
  29. int x1, n1;
  30. vector<vector<char>> v;
  31. vector<vector<bool>> vis;
  32. bool rec(ll h, ll k)
  33. {
  34.     return h >= n && k >= m && h < 0 && k < 0;
  35. }
  36. bool valid(ll h, ll k)
  37. {
  38.     if (rec(h, k) || v[h][k] == '*' || vis[h][k] == 1)
  39.         return false;
  40.     vis[h][k] = 1;
  41.     if (v[h][k] == 'E')
  42.         return true;
  43.     if (valid(h, k + 1))
  44.         return true;
  45.     if (valid(h + 1, k))
  46.         return true;
  47.     if (valid(h, k - 1))
  48.         return true;
  49.     if (valid(h - 1, k))
  50.         return true;
  51.     // vis[h][k] = 0;
  52.     return false;
  53. }
  54. void solve()
  55. {
  56.     cin >> n >> m;
  57.     v.resize(n, vector<char>(m));
  58.     vis.resize(n, vector<bool>(m));
  59.     for (int i = 0; i < n; i++)
  60.     {
  61.         for (int j = 0; j < m; j++)
  62.         {
  63.             cin >> v[i][j];
  64.             if (v[i][j] == 'S')
  65.             {
  66.                 x1 = i;
  67.                 n1 = j;
  68.             }
  69.         }
  70.     }
  71.     if (valid(x1, n1))
  72.         cy;
  73.     else
  74.         cn;
  75. }
  76. int main()
  77. {
  78.     sherry();
  79.     ll t = 1;
  80.     // cin >> t;
  81.     while (t--)
  82.     {
  83.         solve();
  84.     }
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement