Language: C++

#include <iostream>
#include <queue>
#include <set>
#define N 50
#define y1 first.first
#define x1 first.second
#define y2 second.first
#define x2 second.second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> P1;

void bfs();

int w,h,sy1,sx1,sy2,sx2,gy1,gx1,gy2,gx2,ans;
string r1[N],r2[N];
set<P1> visited;

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h) break;
    for(int i=0;i<h;i++) cin>>r1[i]>>r2[i];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(r1[i][j]=='L') sy1=i,sx1=j;
	if(r1[i][j]=='%') gy1=i,gx1=j;
	if(r2[i][j]=='R') sy2=i,sx2=j;
	if(r2[i][j]=='%') gy2=i,gx2=j;
      }
    ans=0;
    bfs();
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

void bfs(){
  int dy[4]={0,-1,0,1},dx[4]={-1,0,1,0};
  queue<P1> q;
  P1 k=(P1){sy1,sx1,sy2,sx2};
  q.push(k);
  visited.insert(k);
  while(!q.empty()){
    P1 t=q.front(); q.pop();
    for(int i=0;i<4;i++){
      int ny1=t.y1+dy[i],nx1=t.x1+dx[i];
      int ny2=t.y2-dy[i],nx2=t.y2-dx[i];
      if(ny1<0) ny1=0;
      if(nx1<0) nx1=0;
      if(h<=ny1) ny1=h;
      if(w<=nx1) nx1=w;
      if(ny2<0) ny2=0;
      if(nx2<0) nx2=0;
      if(h<=ny2) ny2=h;
      if(w<=nx2) nx2=w;
      if(r1[ny1][nx1]=='#') ny1=t.y1,nx1=t.x1;
      if(r2[ny2][nx2]=='#') ny2=t.y2,nx2=t.x2;
      P1 u=(P1){ny1,nx1,ny2,nx2};
      if(visited.find(u)!=visited.end()) continue;
      visited.insert(u);
      if(ny1==gy1&&nx1==gx1&&ny2==gy2&&nx2==gx2){
	ans=1;
	break;
      }
    }
    if(ans) break;
  }
}

Compiler output:
a.cc: In function 'void bfs()':
a.cc:42:28: error: no matching function for call to 'std::pair<std::pair<int, int>, std::pair<int, int> >::pair(<brace-enclosed initializer list>)'
   42 |   P1 k=(P1){sy1,sx1,sy2,sx2};
      |                            ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 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_pair.h:913:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  913 |         explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:913:28: note:   candidate expects 1 argument, 4 provided
/usr/include/c++/14/bits/stl_pair.h:902:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  902 |         constexpr pair(pair<_U1, _U2>&& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note:   candidate expects 1 argument, 4 provided
/usr/include/c++/14/bits/stl_pair.h:891:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && (! _ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  891 |         explicit constexpr pair(_U1&& __x, _U2&& __y)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:891:28: note:   candidate expects 2 arguments, 4 provided
/usr/include/c++/14/bits/stl_pair.h:881:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && _ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  881 |         constexpr pair(_U1&& __x, _U2&& __y)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:881:19: note:   candidate expects 2 arguments, 4 provided
/usr/include/c++/14/bits/stl_pair.h:869:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<std::pair<int, int> >, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::__not_<std::is_convertible<_Iter, std::pair<int, int> > > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_U2, _T2> > >::value, bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  869 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:869:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:866:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  866 |                              bool> = false>
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<std::pair<int, int> >, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::is_convertible<_Iter, std::pair<int, int> > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::is_convertible<_U2, _T2> >::value, bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  856 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:853:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  853 |                              bool> = true>
      |                                      ^~~~
/usr/include/c++/14/bits/stl_pair.h:843:9: note: candidate: 'template<class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_Tp> >, std::is_pointer<std::pair<int, int> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::__not_<std::is_convertible<_Iter, std::pair<int, int> > > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, __zero_as_null_pointer_constant, ...) [with typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U1> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_Iter, _Iterator> > >::value, bool>::type <anonymous> = _U1; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  843 |         pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:843:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:840:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  840 |                              bool> = false>
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:830:9: note: candidate: 'template<class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_Tp> >, std::is_pointer<std::pair<int, int> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::is_convertible<_Iter, std::pair<int, int> > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, __zero_as_null_pointer_constant, ...) [with typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U1> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::is_convertible<_Iter, _Iterator> >::value, bool>::type <anonymous> = _U1; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  830 |         pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:830:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:827:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  827 |                              bool> = true>
      |                                      ^~~~
/usr/include/c++/14/bits/stl_pair.h:789:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ImplicitlyConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::v