Advertisement
volochai

ZOI II TOUR E

Oct 24th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #pragma GCC optimize("Ofast")
  4. #pragma GCC target("sse,sse2,sse3")
  5.  
  6. #define ll long long
  7. #define all(x) (x).begin(), (x).end()
  8. #define rall(x) (x).rbegin(), (x).rend()
  9. #define watch(x) cout << (#x) << " : " << x << '\n'
  10. #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11.  
  12. using namespace std;
  13.  
  14. int h, w, n, sr, sc;
  15.  
  16. string s, t;
  17.  
  18. void no() {
  19. cout << "No\n";
  20. exit(0);
  21. }
  22.  
  23. void solve() {
  24. cin >> h >> w >> n >> sr >> sc >> s >> t;
  25.  
  26. int l = 1, r = h;
  27. for (int i = n - 1; i >= 0; i--) {
  28. if (t[i] == 'U')
  29. r = min(r + 1, h);
  30. if (t[i] == 'D')
  31. l = max(l - 1, 1);
  32. if (s[i] == 'U')
  33. l += 1;
  34. if (s[i] == 'D')
  35. r -= 1;
  36. if (l > r)
  37. no();
  38. }
  39.  
  40. if (!(l <= sr && sr <= r))
  41. no();
  42.  
  43. l = 1, r = w;
  44. for (int i = n - 1; i >= 0; i--) {
  45. if (t[i] == 'R')
  46. l = max(l - 1, 1);
  47. if (t[i] == 'L')
  48. r = min(r + 1, w);
  49. if (s[i] == 'R')
  50. r -= 1;
  51. if (s[i] == 'L')
  52. l += 1;
  53. if (l > r)
  54. no();
  55. }
  56.  
  57. if (!(l <= sc && sc <= r))
  58. no();
  59.  
  60. cout << "Yes\n";
  61. }
  62.  
  63. main() {
  64. boost;
  65. int t = 1;
  66. // cin >> t;
  67. while (t--)
  68. solve();
  69. return 0;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement