• 欢迎光临~

# AtCoder AGC033B LRUD Game

AtCoder 传送门

## 代码

code
``````/*

p_b_p_b txdy
AThousandSuns txdy
Wu_Ren txdy
Appleblue17 txdy

*/

#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 200100;

int n, m, K, sx, sy;
char s[maxn], t[maxn];

void solve() {
scanf("%d%d%d%d%d%s%s", &n, &m, &K, &sx, &sy, s + 1, t + 1);
int up = sx, dw = sx, lf = sy, rg = sy;
for (int i = 1; i <= K; ++i) {
if (s[i] == 'U') {
--up;
} else if (s[i] == 'D') {
++dw;
} else if (s[i] == 'L') {
--lf;
} else if (s[i] == 'R') {
++rg;
}
if (up < 1 || dw > n || lf < 1 || rg > m) {
puts("NO");
return;
}
if (t[i] == 'U') {
dw = max(dw - 1, 1);
} else if (t[i] == 'D') {
up = min(up + 1, n);
} else if (t[i] == 'L') {
rg = max(rg - 1, 1);
} else if (t[i] == 'R') {
lf = min(lf + 1, m);
}
}
puts("YES");
}

int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}

``````