Language: C++

// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

bool check(string S, int a, int b)
{
	// aからbにイク
	if (a > b) swap(a, b);

	vector<int> P(S.size(), -1); // ブロックがあっていけない→1 , なにもない→ 0 
	// いけた 2 
	FOR(i, S.size()) {
		auto c = S[i];
		if (c == '.') {
			P[i] = 0;
		}
		else if (c == '#') {
			P[i] = 1;
		}
	}

	queue<int> Q;
	Q.push(a);
	while (!Q.empty()) {
		auto now = Q.front(); Q.pop();
		if (now >= S.size()) continue;

		if (P[now] == 0) {
			P[now] = 2;
			Q.push(now + 1);
			Q.push(now + 2);
		}
		//S[now] = "x";
	}
	if (P[b] == 2) return true;
	return false;
}

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll A, B, C, D, N;
	cin >> N >> A >> B >> C >> D;
	A -= 1;
	B -= 1;
	C -= 1;
	D -= 1;
	string S;
	cin >> S;
	if (C < D) {
		// BがDに行ったあとで、AがCにイク。
		// Bが Dにいけるか
		auto BtoD = check(S, B, D);
		auto AtoC = check(S, A, C);
		if (BtoD and AtoC) {
			cout << "Yes" << endl;
			exit(0);
		} else {
			cout << "No" << endl;
			exit(0);
		}
	}
	else {
		// 3つ連続する場所があり、そこにいけるか
		vector<int> P(S.size(), -1); // ブロックがあっていけない→1 , なにもない→ 0  // いけた 2 
		FOR(i, S.size()) {
			auto c = S[i];
			if (c == '.') {
				P[i] = 0;
			}
			else if (c == '#') {
				P[i] = 1;
			}
		}


		vector<ll> mittu;
		FOR(_i, N - 2) {
			auto i = _i + 1;
			if (P[i - 1] == 0 and P[i] == 0 and P[i + 1] == 0) {
				if (i+1 < D)
					mittu.push_back(i);
			}
		}


		bool Aok = false;
		bool Bok = false;

		for (auto m : mittu) {
			if (check(S, A, m)) {
				Aok = true;
			}
			if (check(S, B, m)) {
				Bok = true;
			}
		}

		if (Aok and Bok and check(S,A,C)) {
			cout << "Yes" << endl;
		}
		else {

			bool second_chance = false;
			vector<ll> mittu;
			FOR(_i, N - 2) {
				auto i = _i + 1;
				if (P[i - 1] == 0 and P[i] == 0 and P[i + 1] == 0 and (i-1 != D ) and (i > B)) {					
					mittu.push_back(i);
					second_chance = true;
				}
			}
			if (second_chance == false) {
				
				cout << "No" << endl;
				exit(0);
			}

			FOR(_i, N - 2) {
				auto i = _i + 1;
				if (P[i - 1] == 0 and P[i] == 0 and P[i + 1] == 0 and (i-1==D) and (!(i+1 ) {					
					cout << "No" << endl;
					exit(0);
				}
			}

			bool Aok = false;
			bool Bok = false;
			for (auto m : mittu) {
				if (check(S, A, m)) {
					Aok = true;
				}
				if (check(S, B, m)) {
					Bok = true;
				}
			}
			if (Aok and Bok) {
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
			
	
		}
	} // この場合が怖い

	return 0;
}
 

Compiler output:
a.cc: In function 'int main()':
a.cc:158:108: error: expected ')' before '{' token
  158 |                                 if (P[i - 1] == 0 and P[i] == 0 and P[i + 1] == 0 and (i-1==D) and (!(i+1 ) {
      |                                                                                                    ~       ^~
      |                                                                                                            )
a.cc:161:34: error: expected ')' before '}' token
  161 |                                 }
      |                                  ^
      |                                  )
  162 |                         }
      |                         ~         
a.cc:158:36: note: to match this '('
  158 |                                 if (P[i - 1] == 0 and P[i] == 0 and P[i + 1] == 0 and (i-1==D) and (!(i+1 ) {
      |                                    ^
a.cc:162:25: error: expected primary-expression before '}' token
  162 |                         }
      |                         ^