Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <queue>
- #include <map>
- #include <set>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define ll long long
- #define nl endl
- #define cy cout << "YES\n"
- #define cn cout << "NO\n"
- #define sz s.size()
- #define allv v.begin(), v.end()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll n, m;
- int x1, x2;
- int y1, y2;
- vector<vector<char>> v;
- bool valid(int h, int k)
- {
- if (h >= n || k >= m)
- return 0;
- else if (h == x2 && k == y2)
- return 1;
- else
- {
- if (v[h + 1][k] == '.' && v[h][k + 1] == '.')
- {
- return valid(h + 1, k) || valid(h, k + 1);
- }
- else if (v[h + 1][k] == '.')
- return v[h + 1][k];
- else if (v[h][k + 1] == '.')
- return valid(h, k + 1);
- else
- return 0;
- }
- }
- void solve()
- {
- cin >> n >> m;
- vector<char> c(m);
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cin >> c[i];
- if (c[i] == 'S')
- {
- x1 = i;
- y1 = j;
- }
- else if (c[i] == 'E')
- {
- x2 = i;
- y2 = j;
- }
- }
- v.push_back(c);
- c.clear();
- }
- if (valid(x1, y1))
- cy;
- else
- cn;
- }
- int main()
- {
- sherry();
- ll t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement