Language: C++

using namespace std;

int N,A,B,C,D;
char S[1000000];
int main(void){
  cin>>N>>A>>B>>C>>D;
  cin>>S;
  A--; B--; C--; D--;

  if(C<B){
    bool check=true;
    int cnt=0;
    for(int i=A;i<C;i++){
      if(S[i]=='#') cnt++;
      else cnt=0;
      if(cnt>=2) check=false;
    }
    cnt=0;
    for(int i=B;i<D;i++){
      if(S[i]=='#') cnt++;
      else cnt=0;
      if(cnt>=2) check=false;
    }
    if(check) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }

  /* 岩が二連続続くところから端は考えなくて良い */
  int L=0, R=N-1;
  int cnt=0;
  for(int i=0;i<N;i++){
    if(S[i]=='#') cnt++;
    else cnt=0;
    if(cnt>=2){
      if(i<A) L=i+1;
      else{
        R=i-cnt;
        break;
      }
    }
  }

  /* 移動できる領域右端よりCまたはDが右にある場合はNo */
  if(R<C||R<D){
    cout<<"No"<<endl;
    return 0;
  }

  /* 上の状態でなくC<Dの場合はYes */
  if(C<D){
    cout<<"Yes"<<endl;
    return 0;
  }

  /* D<Cの場合、空マスが三連続な場所があればA,Bを入れ替え可能なのでYes */
  bool check=false;
  cnt=0;
  for(int i=L;i<=R;i++){
    if(S[i]=='.') cnt++;
    else cnt=0;
    if(cnt>=3){
      check=true;
      break;
    }
  }

  if(check) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: 'cin' was not declared in this scope
    6 |   cin>>N>>A>>B>>C>>D;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:24:15: error: 'cout' was not declared in this scope
   24 |     if(check) cout<<"Yes"<<endl;
      |               ^~~~
a.cc:24:15: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:24:28: error: 'endl' was not declared in this scope
   24 |     if(check) cout<<"Yes"<<endl;
      |                            ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
a.cc:25:10: error: 'cout' was not declared in this scope
   25 |     else cout<<"No"<<endl;
      |          ^~~~
a.cc:25:10: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:25:22: error: 'endl' was not declared in this scope
   25 |     else cout<<"No"<<endl;
      |                      ^~~~
a.cc:25:22: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:46:5: error: 'cout' was not declared in this scope
   46 |     cout<<"No"<<endl;
      |     ^~~~
a.cc:46:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:46:17: error: 'endl' was not declared in this scope
   46 |     cout<<"No"<<endl;
      |                 ^~~~
a.cc:46:17: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:52:5: error: 'cout' was not declared in this scope
   52 |     cout<<"Yes"<<endl;
      |     ^~~~
a.cc:52:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:52:18: error: 'endl' was not declared in this scope
   52 |     cout<<"Yes"<<endl;
      |                  ^~~~
a.cc:52:18: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:68:13: error: 'cout' was not declared in this scope
   68 |   if(check) cout<<"Yes"<<endl;
      |             ^~~~
a.cc:68:13: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:68:26: error: 'endl' was not declared in this scope
   68 |   if(check) cout<<"Yes"<<endl;
      |                          ^~~~
a.cc:68:26: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:69:8: error: 'cout' was not declared in this scope
   69 |   else cout<<"No"<<endl;
      |        ^~~~
a.cc:69:8: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:69:20: error: 'endl' was not declared in this scope
   69 |   else cout<<"No"<<endl;
      |                    ^~~~
a.cc:69:20: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'