Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #pragma GCC optimize("Ofast")
- #pragma GCC target("sse,sse2,sse3")
- #define ll long long
- #define all(x) (x).begin(), (x).end()
- #define rall(x) (x).rbegin(), (x).rend()
- #define watch(x) cout << (#x) << " : " << x << '\n'
- #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- using namespace std;
- int h, w, n, sr, sc;
- string s, t;
- void no() {
- cout << "No\n";
- exit(0);
- }
- void solve() {
- cin >> h >> w >> n >> sr >> sc >> s >> t;
- int l = 1, r = h;
- for (int i = n - 1; i >= 0; i--) {
- if (t[i] == 'U')
- r = min(r + 1, h);
- if (t[i] == 'D')
- l = max(l - 1, 1);
- if (s[i] == 'U')
- l += 1;
- if (s[i] == 'D')
- r -= 1;
- if (l > r)
- no();
- }
- if (!(l <= sr && sr <= r))
- no();
- l = 1, r = w;
- for (int i = n - 1; i >= 0; i--) {
- if (t[i] == 'R')
- l = max(l - 1, 1);
- if (t[i] == 'L')
- r = min(r + 1, w);
- if (s[i] == 'R')
- r -= 1;
- if (s[i] == 'L')
- l += 1;
- if (l > r)
- no();
- }
- if (!(l <= sc && sc <= r))
- no();
- cout << "Yes\n";
- }
- main() {
- boost;
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement