Language: C++

include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#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;
set<pair<pair<int,int>,pair<int,int> > >s;
bool dfs(int x1,int y1,int x2,int y2){
  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;
  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(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
          s.insert(mk(mk(x3,y3),mk(x4,y4)));
          if(dfs(x3,y3,x4,y4))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))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<bits/stdc++.h>
      | ^~~~~~~
a.cc:5:1: error: 'string' does not name a type
    5 | string s1[50],s2[50];
      | ^~~~~~
a.cc:9:1: error: 'set' does not name a type
    9 | set<pair<pair<int,int>,pair<int,int> > >s;
      | ^~~
a.cc: In function 'bool dfs(int, int, int, int)':
a.cc:19:12: error: 's1' was not declared in this scope; did you mean 'x1'?
   19 |         if(s1[y3][x3]=='#')y3=y1,x3=x1;
      |            ^~
      |            x1
a.cc:20:12: error: 's2' was not declared in this scope; did you mean 'x2'?
   20 |         if(s2[y4][x4]=='#')y4=y2,x4=x2;
      |            ^~
      |            x2
a.cc:21:13: error: 's' was not declared in this scope
   21 |         if(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
      |             ^
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define mk make_pair
      |            ^~~~~~~~~
a.cc:21:24: note: in expansion of macro 'mk'
   21 |         if(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
      |                        ^~
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define mk make_pair
      |            ^~~~~~~~~
a.cc:21:21: note: in expansion of macro 'mk'
   21 |         if(!s.count(mk(mk(x3,y3),mk(x4,y4)))){
      |                     ^~
a.cc: In function 'int main()':
a.cc:31:9: error: 'cin' was not declared in this scope
   31 |   while(cin>>w>>h,w){
      |         ^~~
a.cc:32:5: error: 's' was not declared in this scope
   32 |     s.clear();
      |     ^
a.cc:33:16: error: 's1' was not declared in this scope; did you mean 'y1'?
   33 |     r(i,h)cin>>s1[i]>>s2[i];
      |                ^~
      |                y1
a.cc:33:23: error: 's2' was not declared in this scope; did you mean 'y2'?
   33 |     r(i,h)cin>>s1[i]>>s2[i];
      |                       ^~
      |                       y2
a.cc:35:10: error: 's1' was not declared in this scope; did you mean 'y1'?
   35 |       if(s1[i][j]=='L')x1=j,y1=i;
      |          ^~
      |          y1
a.cc:36:10: error: 's2' was not declared in this scope; did you mean 'y2'?
   36 |       if(s2[i][j]=='R')x2=j,y2=i;
      |          ^~
      |          y2
a.cc:37:10: error: 's1' was not declared in this scope; did you mean 'y1'?
   37 |       if(s1[i][j]=='%')gx1=j,gy1=i;
      |          ^~
      |          y1
a.cc:38:10: error: 's2' was not declared in this scope; did you mean 'y2'?
   38 |       if(s2[i][j]=='%')gx2=j,gy2=i;
      |          ^~
      |          y2
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define mk make_pair
      |            ^~~~~~~~~
a.cc:40:17: note: in expansion of macro 'mk'
   40 |     s.insert(mk(mk(x1,y1),mk(x2,y2)));
      |                 ^~
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define mk make_pair
      |            ^~~~~~~~~
a.cc:40:14: note: in expansion of macro 'mk'
   40 |     s.insert(mk(mk(x1,y1),mk(x2,y2)));
      |              ^~
a.cc:41:25: error: 'cout' was not declared in this scope
   41 |     if(dfs(x1,y1,x2,y2))cout<<"Yes"<<endl;
      |                         ^~~~
a.cc:41:38: error: 'endl' was not declared in this scope
   41 |     if(dfs(x1,y1,x2,y2))cout<<"Yes"<<endl;
      |                                      ^~~~
a.cc:42:10: error: 'cout' was not declared in this scope
   42 |     else cout<<"No"<<endl;
      |          ^~~~
a.cc:42:22: error: 'endl' was not declared in this scope
   42 |     else cout<<"No"<<endl;
      |                      ^~~~