Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(long long i = 0;i<n;i++)
const long long MOD = 1000000007LL;
int main(){
    long long h,w,n;
    cin >> h >> w >> n;
    long long sr,sc;
    cin >> sr >> sc;
    string s,t;
    cin >> s >> t;
    long long l1[n+1],r1[n+1],l2[n+1],r2[n+1],u1[n+1],u2[n+1],d1[n+1],d2[n+1];
    bool fl = true;
    l1[n] = r1[n] = l2[n] = r2[n] = d1[n] = d2[n] = u1[n] = u2[n] = 0;
    long long llc[n+1],rrc[n+1],uuc[n+1],ddc[n+1];
    llc[n] = rrc[n] = uuc[n] = ddc[n] = 0;
    rep(i,n){
        if(t[n-1-i] == 'L'){
            l2[n-1-i] = l2[n-i]+1;
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i];
            rrc[n-1-i] = rrc[n-i];
            llc[n-1-i] = llc[n-i-i]-1;
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = ddc[n-i];
        }
        else if(t[n-1-i] == 'R'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i]+1;
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i];
            rrc[n-1-i] = rrc[n-i]-1;
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = ddc[n-i];
        }
        else if(t[n-1-i] == 'U'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i]+1;
            d2[n-i-1] = d2[n-i];
            rrc[n-1-i] = rrc[n-i];
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = uuc[n-i]-1;
            ddc[n-1-i] = ddc[n-i];
        }
        else if(t[n-1-i] == 'D'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i]+1;
            rrc[n-1-i] = rrc[n-i];
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = ddc[n-i]-1;
        }
        if(s[n-1-i] == 'L'){
            l1[n-1-i] = l1[n-i] + 1;
            r1[n-1-i] = r1[n-i];
            u1[n-1-i] = u1[n-i];
            d1[n-i-1] = d1[n-i];
            rrc[n-1-i] = max(0,rrc[n-i])+1;
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = ddc[n-i];
        }
        else if(s[n-1-i] == 'R'){
            l1[n-1-i] = l1[n-i];
            r1[n-1-i] = r1[n-i]+1;
            u1[n-1-i] = u1[n-i];
            d1[n-i-1] = d1[n-i];
            llc[n-1-i] = max(0,llc[n-i]) + 1;
            rrc[n-1-i] = rrc[n-i];
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = ddc[n-i];
        }
        else if(s[n-1-i] == 'U'){
            l1[n-1-i] = l1[n-i];
            r1[n-1-i] = r1[n-i];
            u1[n-1-i] = u1[n-i]+1;
            d1[n-i-1] = d1[n-i];
            rrc[n-1-i] = rrc[n-i];
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = uuc[n-i];
            ddc[n-1-i] = max(0,ddc[n-i])+1;
        }
        else if(s[n-1-i] == 'D'){
            l1[n-1-i] = l1[n-i];
            r1[n-1-i] = r1[n-i];
            u1[n-1-i] = u1[n-i];
            d1[n-i-1] = d1[n-i]+1;
            rrc[n-1-i] = rrc[n-i];
            llc[n-1-i] = llc[n-i];
            uuc[n-1-i] = max(uuc[n-i],0)+1;
            ddc[n-1-i] = ddc[n-i];
        }
        if(t[n-1-i] == 'L'){
            l2[n-1-i] = l2[n-i]+1;
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i];
        }
        else if(t[n-1-i] == 'R'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i]+1;
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i];
        }
        else if(t[n-1-i] == 'U'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i]+1;
            d2[n-i-1] = d2[n-i];
        }
        else if(t[n-1-i] == 'D'){
            l2[n-1-i] = l2[n-i];
            r2[n-1-i] = r2[n-i];
            u2[n-1-i] = u2[n-i];
            d2[n-i-1] = d2[n-i]+1;
        }
    }
    long long lc,rc,uc,dc;
    long long llcc,rrcc,uucc,ddcc;
    rep(i,n){
        rc = max((r2[0] - r2[i])-(l1[0] - l1[i]),0) + sc;
        lc = sc - max((l2[0] - l2[i])-(r1[0] - r1[i]),0);
        llcc = w+1-llc[i+1];
        rrcc = rrc[i+1];
        if(llcc <= lc || rc <= rrcc || llcc <= rrcc || llcc <= 1 || rrcc >= w){
            fl = false;
            break;
        }
        dc = max((d2[0] - d2[i])-(u1[0] - u1[i]),0) + sr;
        uc = sr - max((u2[0] - u2[i])-(d1[0] - d1[i]),0);
        uucc = h+1-uuc[i+1];
        ddcc = ddc[i+1];
        if(uucc <= lc || dc <= ddcc || uucc <= ddcc || uucc <= 1 || ddcc >= h){
            fl = false;
            break;
        }
    }
    if(fl){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:29: error: no matching function for call to 'max(int, long long int&)'
   70 |             rrc[n-1-i] = max(0,rrc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:70:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   70 |             rrc[n-1-i] = max(0,rrc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:70:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   70 |             rrc[n-1-i] = max(0,rrc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
a.cc:80:29: error: no matching function for call to 'max(int, long long int&)'
   80 |             llc[n-1-i] = max(0,llc[n-i]) + 1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:80:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   80 |             llc[n-1-i] = max(0,llc[n-i]) + 1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:80:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   80 |             llc[n-1-i] = max(0,llc[n-i]) + 1;
      |                          ~~~^~~~~~~~~~~~
a.cc:93:29: error: no matching function for call to 'max(int, long long int&)'
   93 |             ddc[n-1-i] = max(0,ddc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:93:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   93 |             ddc[n-1-i] = max(0,ddc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:93:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   93 |             ddc[n-1-i] = max(0,ddc[n-i])+1;
      |                          ~~~^~~~~~~~~~~~
a.cc:102:29: error: no matching function for call to 'max(long long int&, int)'
  102 |             uuc[n-1-i] = max(uuc[n-i],0)+1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:102:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  102 |             uuc[n-1-i] = max(uuc[n-i],0)+1;
      |                          ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:102:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  102 |             uuc[n-1-i] = max(uuc[n-i],0)+1;
      |                          ~~~^~~~~~~~~~~~
a.cc:133:17: error: no matching function for call to 'max(long long int, int)'
  133 |         rc = max((r2[0] - r2[i])-(l1[0] - l1[i]),0) + sc;
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:133:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  133 |         rc = max((r2[0] - r2[i])-(l1[0] - l1[i]),0) + sc;
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:133:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  133 |         rc = max((r2[0] - r2[i])-(l1[0] - l1[i]),0) + sc;
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:134:22: error: no matching function for call to 'max(long long int, int)'
  134 |         lc = sc - max((l2[0] - l2[i])-(r1[0] - r1[i]),0);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:134:22: