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;

void bfs();
pair<int,int> P;
pair<P,P> P1;

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){(P){sy1,sx1},(P){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){(P){ny1,nx1},(P){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:13:9: error: type/value mismatch at argument 1 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
   13 | pair<P,P> P1;
      |         ^
a.cc:13:9: note:   expected a type, got 'P'
a.cc:13:9: error: type/value mismatch at argument 2 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
a.cc:13:9: note:   expected a type, got 'P'
a.cc:17:7: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Key, class _Compare, class _Alloc> class std::set'
   17 | set<P1> visited;
      |       ^
a.cc:17:7: note:   expected a type, got 'P1'
a.cc:17:7: error: template argument 2 is invalid
a.cc:17:7: error: template argument 3 is invalid
a.cc: In function 'void bfs()':
a.cc:41:11: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Sequence> class std::queue'
   41 |   queue<P1> q;
      |           ^
a.cc:41:11: note:   expected a type, got 'P1'
a.cc:41:11: error: template argument 2 is invalid
a.cc:42:5: error: expected ';' before 'k'
   42 |   P1 k=(P1){(P){sy1,sx1},(P){sy2,sx2}};
      |     ^~
      |     ;
a.cc:43:5: error: request for member 'push' in 'q', which is of non-class type 'int'
   43 |   q.push(k);
      |     ^~~~
a.cc:43:10: error: 'k' was not declared in this scope
   43 |   q.push(k);
      |          ^
a.cc:44:11: error: request for member 'insert' in 'visited', which is of non-class type 'int'
   44 |   visited.insert(k);
      |           ^~~~~~
a.cc:45:12: error: request for member 'empty' in 'q', which is of non-class type 'int'
   45 |   while(!q.empty()){
      |            ^~~~~
a.cc:46:7: error: expected ';' before 't'
   46 |     P1 t=q.front(); q.pop();
      |       ^~
      |       ;
a.cc:46:23: error: request for member 'pop' in 'q', which is of non-class type 'int'
   46 |     P1 t=q.front(); q.pop();
      |                       ^~~
a.cc:48:15: error: 't' was not declared in this scope
   48 |       int ny1=t.y1+dy[i],nx1=t.x1+dx[i];
      |               ^
a.cc:51:10: error: 'nx1' was not declared in this scope; did you mean 'ny1'?
   51 |       if(nx1<0) nx1=0;
      |          ^~~
      |          ny1
a.cc:53:13: error: 'nx1' was not declared in this scope; did you mean 'ny1'?
   53 |       if(w<=nx1) nx1=w;
      |             ^~~
      |             ny1
a.cc:55:10: error: 'nx2' was not declared in this scope; did you mean 'ny2'?
   55 |       if(nx2<0) nx2=0;
      |          ^~~
      |          ny2
a.cc:57:13: error: 'nx2' was not declared in this scope; did you mean 'ny2'?
   57 |       if(w<=nx2) nx2=w;
      |             ^~~
      |             ny2
a.cc:58:18: error: 'nx1' was not declared in this scope; did you mean 'ny1'?
   58 |       if(r1[ny1][nx1]=='#') ny1=t.y1,nx1=t.x1;
      |                  ^~~
      |                  ny1
a.cc:59:18: error: 'nx2' was not declared in this scope; did you mean 'ny2'?
   59 |       if(r2[ny2][nx2]=='#') ny2=t.y2,nx2=t.x2;
      |                  ^~~
      |                  ny2
a.cc:60:9: error: expected ';' before 'u'
   60 |       P1 u=(P1){(P){ny1,nx1},(P){ny2,nx2}};
      |         ^~
      |         ;
a.cc:61:18: error: request for member 'find' in 'visited', which is of non-class type 'int'
   61 |       if(visited.find(u)!=visited.end()) continue;
      |                  ^~~~
a.cc:61:23: error: 'u' was not declared in this scope
   61 |       if(visited.find(u)!=visited.end()) continue;
      |                       ^
a.cc:61:35: error: request for member 'end' in 'visited', which is of non-class type 'int'
   61 |       if(visited.find(u)!=visited.end()) continue;
      |                                   ^~~
a.cc:62:15: error: request for member 'insert' in 'visited', which is of non-class type 'int'
   62 |       visited.insert(u);
      |               ^~~~~~
a.cc:62:22: error: 'u' was not declared in this scope
   62 |       visited.insert(u);
      |                      ^
a.cc:63:20: error: 'nx1' was not declared in this scope; did you mean 'ny1'?
   63 |       if(ny1==gy1&&nx1==gx1&&ny2==gy2&&nx2==gx2){
      |                    ^~~
      |                    ny1
a.cc:63:40: error: 'nx2' was not declared in this scope; did you mean 'ny2'?
   63 |       if(ny1==gy1&&nx1==gx1&&ny2==gy2&&nx2==gx2){
      |                                        ^~~
      |                                        ny2