Language: C++

#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
#define mk make_pair
using namespace std;
string s1[50],s2[50];
int dx1[]={1,-1,0,0,},dy1[]={0,0,1,-1};
int dx2[]={-1,1,0,0,},dy2[]={0,0,1,-1};
int w,h,gx1,gx2,gy1,gy2;
unordered_set<pair<pair<int,int>,pair<int,int> > >s;
queue<pair<pair<int,int>,pair<int,int> > >q;
bool bfs(int x1,int y1,int x2,int y2){
  queue<int>q;
  q.push(x1+y1*100+x2*10000+y2*1000000);
  while(!q.empty()){
    int p=q.front();q.pop();
    x1=p%100;y1=p%10000/100;
    x2=p%1000000/10000;y2=p/1000000;
    for(int i=0;i<4;i++){
      int x3=x1+dx1[i],y3=y1+dy1[i];
      int x4=x2+dx2[i],y4=y2+dy2[i];
      if(x3>=0&&x4>=0&&y3>=0&&y4>=0)
        if(x3<w&&x4<w&&y3<h&&y4<h){
          if(s1[y3][x3]=='#')y3=y1,x3=x1;
          if(s2[y4][x4]=='#')y4=y2,x4=x2;
          if(x1==gx1&&y1==gy1&&x2==gx2&&y2==gy2)return 1;
          if(!(x3==gx1&&y3==gy1&&(x4!=gx2||y4!=gy2)))
          if(!((x3!=gx1||y3!=gy1)&&x4==gx2&&y4==gy2))
          if(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
            s.insert(mk(mk(x3,y3),mk(x4,y4)));
            q.push(x3+y3*100+x4*10000+y4*1000000);
          }
        }
      }
    }
    return 0;
}
bool dfs(int x1,int y1,int x2,int y2,int d){
  //cout<<d<<endl;cout<<1;
    if(x1==gx1&&y1==gy1&&(x2!=gx2||y2!=gy2))return 0;
    if((x1!=gx1||y1!=gy1)&&x2==gx2&&y2==gy2)return 0;
    if(x1==gx1&&y1==gy1&&x2==gx2&&y2==gy2)return 1;
    if(d<8000)for(int i=0;i<4;i++){
    int x3=x1+dx1[i],y3=y1+dy1[i];
    int x4=x2+dx2[i],y4=y2+dy2[i];
    if(x3<0)x3=x1;if(x4<0)x4=x2;
    if(y3<0)y3=y1;if(y4<0)y4=y2;
    if(x3>=w)x3=x1;if(x4>=w)x4=x2;
    if(y3>=h)y3=y1;if(y4>=h)y4=y2;
        if(s1[y3][x3]=='#')y3=y1,x3=x1;
        if(s2[y4][x4]=='#')y4=y2,x4=x2;
        if(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
          s.insert(mk(mk(x3,y3),mk(x4,y4)));
          if(dfs(x3,y3,x4,y4,d+1))return 1;
        }
    }
    else q.push(mk(mk(x1,y1),mk(x2,y2)));
    if(q.size()){
        pair<pair<int,int>,pair<int,int> >pp=q.front();q.pop();
        if(bfs(pp.fi.fi,pp.fi.se,pp.se.fi,pp.se.se))return 1;
    }
    return 0;
}
int main(){
  int x1,y1,x2,y2;
  while(cin>>w>>h,w){
    s.clear();
    r(i,h)cin>>s1[i]>>s2[i];
    r(i,h)r(j,w){
      if(s1[i][j]=='L')x1=j,y1=i;
      if(s2[i][j]=='R')x2=j,y2=i;
      if(s1[i][j]=='%')gx1=j,gy1=i;
      if(s2[i][j]=='%')gx2=j,gy2=i;
    }
    s.insert(mk(mk(x1,y1),mk(x2,y2)));
    if(dfs(x1,y1,x2,y2,0))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    while(!q.empty())q.pop();
  }
}

Compiler output:
a.cc:11:51: error: use of deleted function 'std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Pred = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]'
   11 | unordered_set<pair<pair<int,int>,pair<int,int> > >s;
      |                                                   ^
In file included from /usr/include/c++/14/unordered_set:41,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:189,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_set.h:142:7: note: 'std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Pred = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]' is implicitly deleted because the default definition would be ill-formed:
  142 |       unordered_set() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_set.h:142:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, true>]'
In file included from /usr/include/c++/14/bits/unordered_map.h:33,
                 from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, true>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, true>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, true>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::pair<std::pair<int, int>, std::pair<int, int> >, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<std::pair<int, int>, std::pair<int, int> >; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::pair<std::pair<int, int>, std::pair<int, int> > >::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >; bool <anonymous> = false]' is private within this context
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1731 |       _Hashtable_base() = default;
      |       ^