Language: C++

//
// Created by Tetsuya Shiota on 2019-04-13.
//

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cerr << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x)                                                                \
  cerr << __LINE__ << ' ' << #x << " : ";                                      \
  FOR(e, x) cerr << e << ' ';                                                  \
  cerr << endl;
#else
#define pp(x)
#define dump(x)
#endif

using namespace std;

using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;

template <typename T> void reverse(vector<T> &v) {
  reverse(v.begin(), v.end());
}
template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }
template <typename T> T sum(const vector<T> &v) {
  return accumulate(v.begin(), v.end(), T(0));
}
template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> void update_min(T &a, const T &b) { a = min(a, b); }
vector<pair<char, Int>> merge_cont_char(const string &s) {
  vector<pair<char, Int>> ret;
  if (s.empty())
    return ret;
  ret.push_back(make_pair(s[0], 0));
  FOR(c, s) {
    if (ret.back().first == c)
      ret.back().second++;
    else
      ret.push_back(make_pair(c, 1));
  }
  return ret;
}

class Shakutori {
public:
  // 全体の範囲
  // [0, end)
  // 注目している範囲
  // [tail, head)
  Int head, tail, end = 0;
  bool moveHead() {
    if (head == end) {
      return false;
    }
    head++;
    return true;
  }
  void moveTail() { tail++; }
  bool valid() {
    if (head == tail)
      return true;
    // [tail, head)
    // が解として適当か検証する
    return true;
  }
  void solve() {
    head = tail = 0;
    Int ans = 0;
    while (moveHead()) {
      while (!valid()) {
        moveTail();
      }
      // ここで解を更新する
    }
  }
};

class Solver {
public:
    Int H, W, N, sy, sx;
    string T, A, ans;
  Solver() {}
  void input() {
      cin >> H >> W >> N;
      cin >> sy >> sx;
      sy--;sx--;
      cin >> T >> A;
  }

  bool maxU(Int x, Int now, Int who) {
    if (x < 0 || x >= H){
      pp(now);
      pp(who);
      pp(x);
      return true;
  }
    if(now == N)return false;

    // Takahasi
    if(who == 0) {
      if(T[now] == 'U'){
        return maxU(x-1, now, 1);
      }
      else{
        return maxU(x, now, 1);
      }
    }
    // Aoki
    if(who == 1) {
      if(x+1 < H && A[now] == 'D'){
        return maxU(x+1, now+1, 0);
      }
      else{
        return maxU(x, now+1, 0);
      }
    }
    assert(false);
  }

  bool maxD(Int x, Int now, Int who){
    if(x <0 || x >= H){
      pp(x);
      pp(now);
      pp(who);
      return true;
    }
    if(now == N)return false;

    // Takahasi
    if(who == 0) {
      if(T[now] == 'D'){
        return maxD(x+1, now, 1);
      }
      else{
        return maxD(x, now, 1);
      }
    }
    // Aoki
    if(who == 1) {
      if(x-1 > 0 && A[now] == 'U'){
        return maxD(x-1, now+1, 0);
      }
      else{
        return maxD(x, now+1, 0);
      }
    }
    assert(false);
  }

  bool maxR(Int x, Int now, Int who){
    if(x <0 || x >= W){
      pp(x);
      pp(now);
      pp(who);
      return true;
    }
    if(now == N)return false;

    // Takahasi
    if(who == 0) {
      if(T[now] == 'R'){
        return maxR(x+1, now, 1);
      }
      else{
        return maxR(x, now, 1);
      }
    }
    // Aoki
    if(who == 1) {
      if(x -1 >= 0 && A[now] == 'L'){
        return maxR(x-1, now+1, 0);
      }
      else{
        return maxR(x, now+1, 0);
      }
    }
    assert(false);
  }

  bool maxL(Int x, Int now, Int who){
    if(x <0 || x >= W){
      pp(x);
      pp(now);
      pp(who);
      return true;
    }
    if(now == N)return false;

    // Takahasi
    if(who == 0) {
      if(T[now] == 'L'){
        return maxL(x-1, now, 1);
      }
      else{
        return maxL(x, now, 1);
      }
    }
    // Aoki
    if(who == 1) {
      if(x+1 < W && A[now] == 'R'){
        return maxL(x+1, now+1, 0);
      }
      else{
        return maxL(x, now+1, 0);
      }
    }
    assert(false);
  }

  void solve() {
    if(maxU(sy, 0, 0) || maxD(sy, 0, 0) || maxL(sx, 0, 0) || maxR(sx, 0, 0)) {
    ans = "NO";
    }else{
      ans = "YES";
    }
    return;
/*
    map<char, Int> numT, numA;
    ans = "YES";
    Int gL, gR, gU, gD;
    gL = sx+1;
    gR = W - sx;
    gD =H - sy;
    gU = sy+1;
    rep(turn, N) {
      numT[T[turn]]++;
      numA[A[turn]]++;

      Int mustMove = 0;
      // UP
      {
        Int up = numT['U'] - numA['D'];
        if (up >= gU)
          ans = "NO";
      }

      // DOWN
      {
        Int down = numT['D'] - numA['U'];
        if (down >= gD)
          ans = "NO";
      }

      // LEFT
      {
        Int left = numT['L'] - numA['R'];
        if (left >= gL)
          ans = "NO";
      }

      // DOWN
      {
        Int right = numT['R'] - numA['L'];
        if (right >= gR)
          ans = "NO";
      }
    }
    */
  }
  void output() {
      cout << ans <<endl;
  }
};

void initilization() {
  struct BoolName : numpunct<char> {
    string t, f;
    BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
    string do_truename() const { return t; }
    string do_falsename() const { return f; }
  };
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(15) << boolalpha;
  cout.imbue(locale(cout.getloc(), new BoolName));
}

int main() {
#ifdef LOCAL
  while (1) {
    Solver s;
    s.input();
    if (cin.eof())
      break;
    s.solve();
    s.output();
  }
#else
  Solver s;
  s.input();
  s.solve();
  s.output();
#endif
}

Compiler output:
a.cc: In member function 'bool Solver::maxU(Int, Int, Int)':
a.cc:140:5: error: 'assert' was not declared in this scope
  140 |     assert(false);
      |     ^~~~~~
a.cc:20:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   19 | #include <unordered_set>
  +++ |+#include <cassert>
   20 | #include <vector>
a.cc: In member function 'bool Solver::maxD(Int, Int, Int)':
a.cc:170:5: error: 'assert' was not declared in this scope
  170 |     assert(false);
      |     ^~~~~~
a.cc:170:5: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: In member function 'bool Solver::maxR(Int, Int, Int)':
a.cc:200:5: error: 'assert' was not declared in this scope
  200 |     assert(false);
      |     ^~~~~~
a.cc:200:5: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: In member function 'bool Solver::maxL(Int, Int, Int)':
a.cc:230:5: error: 'assert' was not declared in this scope
  230 |     assert(false);
      |     ^~~~~~
a.cc:230:5: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: In member function 'bool Solver::maxU(Int, Int, Int)':
a.cc:141:3: warning: control reaches end of non-void function [-Wreturn-type]
  141 |   }
      |   ^
a.cc: In member function 'bool Solver::maxD(Int, Int, Int)':
a.cc:171:3: warning: control reaches end of non-void function [-Wreturn-type]
  171 |   }
      |   ^
a.cc: In member function 'bool Solver::maxL(Int, Int, Int)':
a.cc:231:3: warning: control reaches end of non-void function [-Wreturn-type]
  231 |   }
      |   ^
a.cc: In member function 'bool Solver::maxR(Int, Int, Int)':
a.cc:201:3: warning: control reaches end of non-void function [-Wreturn-type]
  201 |   }
      |   ^