Problem:


Score : 400 points

Problem Statement

There are N squares arranged in a row, numbered 1, 2, ..., N from left to right.
You are given a string S of length N consisting of . and #. If the i-th character of S is #, Square i contains a rock; if the i-th character of S is ., Square i is empty.

In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.

You can repeat the following operation any number of times:

Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.

You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

S is a string of length N consisting of . and #.

1 \leq A, B, C, D \leq N

Square A, B, C and D do not contain a rock.

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

Print Yes if the objective is achievable, and No if it is not.

Sample Input 1

7 1 3 6 7
.#..#..

Sample Output 1

Yes

The objective is achievable by, for example, moving the two persons as follows. (A and B represent Snuke and Fnuke, respectively.)

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

7 1 3 7 6
.#..#..

Sample Output 2

No

Sample Input 3

15 1 3 15 13
...#.#...#.#...

Sample Output 3

Yes



Sample input:
7 1 3 6 7
.#..#..


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
class KenkenRace:
    def __init__(self):
        N, A, B, C, D = map(int, input().split())
        S = [str(c) for c in input()]

        self.N = N
        self.A = A
        self.B = B
        self.C = C
        self.D = D
        self.S = S

    def main(self):
        result = False

        # C < B のとき
        if self.C < self.B:
            # 割れているので, A -> C and B -> D を検証
            result = self.__canSepClear__(self.A, self.C) and self.__canSepClear__(self.B, self.D)

        # C < D のとき
        elif self.C < self.D:
            # クリアできるか確かめる
            result = self.__canClear__(self.D)

        # D < C のとき
        else:
            # 追い越せるかどうかを確かめる and クリアできるか確かめる
            result = self.__canClear__(self.C) and self.__canOvertake__(self.D)

        if result:
            print("Yes")
        else:
            print("No")

    def __canClear__(self, higher):
        isDouble = False
        preObject = ""
        for i in range(self.A - 1, higher):
            c = self.S[i]
            if c == "#" and preObject == "#":
                isDouble = True
                break
            else:
                preObject = c

        return not isDouble

    def __canSepClear__(self, start, end):
        isDouble = False
        preObject = ""

        for i in range(start - 1, end):
            c = self.S[i]
            if c == "#" and preObject == "#":
                isDouble = True
                break
            else:
                preObject = c

        return not isDouble

    def __canOvertake__(self, lower):
        isTriple = False
        objectCount = 0
        severalCount = 0

        for i in range(self.A - 1, lower):
            c = self.S[i]
            objectCount += 1

            # 何もない箇所が何連続目か, カウント
            if c == ".":
                severalCount += 1
            else:
                severalCount = 0

            if objectCount == lower:
                # この位置 or 次の位置で3連続でない場合, 追い越せない
                if severalCount < 2:
                    break
                elif severalCount == 2 and self.S[i + 1] == ".":
                    isTriple = True
                    break

            # 3連続で何もなければ追い越し可能か
            if severalCount == 3:
                isTriple = True
                break

        return isTriple


kenkenRace = KenkenRace()
kenkenRace.main()

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int, input().split())
s = input()

flag3 = 0
flagno = 0

if c > d:

    for i in range(a,c-3):

        if s[i:i+2] == "##":
            flagno += 1
            break

    if flagno == 0:

        for i in range(b,d):
        
            if s[i-2:i+1] == "...":
                flag3 += 1
                break
    
    if flagno == 0 and flag3 > 0:
        print("Yes")

    else:
        print("No")

else:

    if c-a <= 2:
        flagno = 0
    else:
        for i in range(a,c-3):

            if s[i:i+2] == "##":
                flagno += 1
                break

    if d-b <= 2:
        flagno = 0
    else:
        for i in range(b,d-3):

            if s[i:i+2] == "##":
                flagno += 1
                break
        
    if flagno == 0:
        print("Yes")

    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, A,B,C,D= (int(x) for x in input().split())

S= input()

if('##'  in S):
  print("No")
elif(C<D):
  print("Yes")
elif(C>D):
  if('...'in S):
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
p=list(input())
count=0
r1=0
for i in range(b,d-1):
    if p[i-1]=="#" and p[i]=="#" :
        r1=1
        break;
    else:
        r1=0
count=0
r2=0
for j in range(a,c-1):
    if p[j-1]=="#" and p[j]=="#" :
        r2=1
        break;
    else:
        r2=0

for k in range(b-1,d-1):
    if p[k-1]=='.' and  p[k]=='.' and  p[k+1]=='.' and k<(d-2):
        r4=0
        break;
    else:
        r4=1

        
if r1==0 and r2==0:
    if c<d:
        print("Yes")
    elif r4==0:
        print("Yes")
    else:
        print("No")     
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = str(input())

if c>d:
  if s[d-2]=="#" or s[d]=="#":
    if s[b-1:d-1].find("...")!=-1:
      print("Yes")
    else:
      print("No")
elif b>c:
  if s[a-1:c-1].find("##")==-1 and s[b-1:d-1].find("##")==-1:
    print("Yes")
elif s[a-1:max(c,d)-1].find("##")==-1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
line = input().split()
object_ = input()

N = int(line[0])
A = int(line[1])-1
B = int(line[2])-1
C = int(line[3])-1
D = int(line[4])-1

placing_objects = [True if s == '#' else False for s in list(object_)]

def main():
    if (A < B and C < D) or (A > B and C > D):
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1]:
                print('No')
                return
        print('Yes')
        return
    else:
        possible_trans = False
        trans_index = -1
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1]:
                print('No')
                return
            if i < N-2 and (not placing_objects[i]) and (not placing_objects[i+1]) and (not placing_objects[i+2]):
                possible_trans = True
                trans_index = i+1
        if not possible_trans:
            if C < D:
                if placing_objects[C-1] or placing_objects[C+1]:
                    print('No')
                    return
            else:
                if placing_objects[D-1] or placing_objects[D+1]:
                    print('No')
                    return
        else:
            if A > B:
                if A > trans_index:
                    print('No')
                    return
            else:
                if B > trans_index and D <= trans_index and C >= trans_index:
                    print('No')
                    return
        print('Yes')
        
main()

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
s = s[:max(c, d) + 2]
b_reachable = [b - 1]
current_b = b - 1
while True:
    target = s[current_b + 1:current_b + 3]
    if target == '..':
        b_reachable.extend([current_b + 1, current_b + 2])
        current_b += 2
    elif target == '#.':
        b_reachable.append(current_b + 2)
        current_b += 2
    elif target == '.#':
        b_reachable.append(current_b + 1)
        current_b += 1
    elif target == '.':
        b_reachable.append(current_b + 1)
        current_b += 1
    else:
        break
if c < d:
    if c - 1 in b_reachable and d - 1 in b_reachable:
        print('Yes')
    else:
        print('No')
else:
    if '#..#' in s:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def SI(): return input()

N,A,B,C,D=LI()
st=input()

if C < D:
    if st[A:C].find('##') >= 0 or st[B:D].find('##') >= 0:
        print('No')
    else:
        print('Yes')
else:
    # Cの方がおおきいケース 入れ替わる
    if st[A:C].find('##') >= 0:
        print('No')
    else:
        fnd = st.find('...', A-1, D+1)
        if fnd >= 0:
            if fnd+1 == B or fnd+3 == B:
                fnd = st.find('...', fnd+1, D+1)
                if fnd >= 0:
                    if fnd+3 == D:
                        fnd = st.find('...', fnd+1, D+1)
                        if fnd >= 0:
                            print('Yes')
                        else:
                            print('No')
                    else:
                        print('Yes')
                else:
                    print('No')
            else:
                print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
import sys
N, A, B, C, D = map(int, input().split())
S = input()
skip = 0
for i in range(max(C,D)-2):
	if i >= min(A,B-1) and S[i]==S[i+1]=="#":
		print('No')
		sys.exit()
	if B-2 <= i < max(C,D)-3 and S[i]==S[i+1]==S[i+2]==".":
		skip += 1
	if i == B-1 and S[i-1]==S[i+1]== ".":
		skip += 1
if C<D:
	print('Yes')

elif skip > 0:
	print("Yes")
else:
	print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
s = input() + '##'
ans = True

if C > D:
    if '...' not in s[B:D+1]:
        if s[B-2] != '.' or s[B] != '.':  ans = False

if ans:
    if '##' in s[B:D]:    ans = False
    if '##' in s[A:C]:    ans = False

if ans: print('Yes')
else:   print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S = list(input())
t=1
if A<C<B<D or A<B<C<D:
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	for i in range(A,C-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
else:
	for i in range(B,D-1):
		if S[i-1]==S[i]==S[i+1]=='.':
			t=0
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	if t==0:
		for i in range(A,C-1):
			if S[i] == S[i+1] == '#':
				print('No')
				exit()
	else:
		print('No')
		exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()

# stoneCnt=S.count("#")

# if stoneCnt == 0:
# 	print("Yes")
# 	exit(0)


curStoneLen=0

# 先にBがいけるか考える
# いけなければOUT
for b in range(B-1,D):
	if S[b] == ".":
		curStoneLen = 0
	else:
		curStoneLen += 1

	if 2 == curStoneLen:
		print("No")
		exit(0)



curStoneLen=0

for a in range(A-1,C):
	if S[a] == ".":
		curStoneLen = 0
	else:
		curStoneLen += 1

	if 2 == curStoneLen:
		print("No")
		exit(0)

# print(maxAtoDSeqSpaceLen)

if D < C:
	# AはBをかわさないといけない
	maxAtoDSeqSpaceLen=0
	curSeqSpaceLen=0
	for a in range(A-1,D+1):
		if S[a] == ".":
			curSeqSpaceLen += 1
		else:
			curSeqSpaceLen = 0

		maxAtoDSeqSpaceLen=max(maxAtoDSeqSpaceLen,curSeqSpaceLen)

	if maxAtoDSeqSpaceLen < 3:
		# D+1までにかわすスペースが無い
		print("No")
		exit(0)	
else:
	# その他の場合は、Bを無視して良い
	pass


print("Yes")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = (int(_) for _ in input().split())
x = input()

ng = [i+1 for i in range(n) if x[i:i+2] == "##"]
ng.extend([0,2000001])

L = max([i for i in ng if i < a])
R = min([i for i in ng if i > c])
ng1 = [a < i < c or b < i < d for i in ng]

x2 = x[L:R+1]
ex = [x2[i:i+3] == "..." for i in range(len(x2))]

if any(ng1):
    res = "No"
elif c > d:
    if any(ex):
        res = "Yes"
    else:
        res = "No"
else:
    res = "Yes"

print(res)

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
road = input()
if "##" in road[a-1:c-1] or "##" in road[b-1:d-1]:
  print("No")
else:
  if c < d:
    print("Yes")
  else:
    if "..." in road[b-2:d]:
      print("Yes")
    else:print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input() + "##"
line = [0 for i in range(len(S))]
for i in range(len(S)):
    line[i] = 0 if S[i]=="." else 1
A -= 1
B -= 1
C -= 1
D -= 1
line[A] = "A"
line[B] = "B"


A_checkin = False
B_checkin = False

while True:
    if (line[A+1] != 0) and (line[A+2] != 0) and(not A_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+1]==0 and not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (line[B+2]==0 and not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (S[B+1]=="C" and not B_checkin) :
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (S[B+2]=="C" and not B_checkin) :
            line[B+2] = "B"
            line[B] = 0
            B += 2
        else:   
            break
    if (line[C-1]=="A" or line[C-2]=="A"):
        line[C] = "A"
        A_checkin = True
        line[A] = 0
        A = C
    
    elif (line[A+2]==0) and (not A_checkin):
        line[A+2] = "A"
        line[A] = 0
        A += 2
    elif (line[A+1]==0) and (not A_checkin):
        line[A+1] = "A"
        line[A] = 0
        A += 1
    else:
        break


while True:
    if (not B_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+2]==0) and (not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (line[B+1]==0) and (not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        else:
            break
    else:
        break

print("Yes" if (A_checkin and B_checkin) else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = ( int(i) for i in input().split())
s = input()

a_to_c = s[a-1:c-1]
b_to_d = s[b-1:d-1]
if b > 2:
    b_to_d2 = s[b-3:c-1]
elif b == 2:
    b_to_d2 = s[b-2:c-1]
else:
    b_to_d2 = s[b-1:c-1]

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if c>d:
    if not(b_to_d2.find('...')!=-1):
        possibility = False

if possibility:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = [int(i) for i in input().split()]
S = list(input())

gyaku = 0
if C > D:
    gyaku = 1

flag = 0
renzoku = 0
irekae = 0
for i in range(A,max(D,C)):
    if S[i] == '#':
        renzoku = 0
        if flag == 1:
            if A < i < C-1 or B < i < D-1:
                print('No')
                exit()
        flag = 1

    else:
        flag = 0
        renzoku += 1
        if renzoku == 3:
            irekae = 1
            irekaeiti = i

    if gyaku:
        if i == D-1:
            if S[i-1] == '#' or S[i+1] == '#':
                if irekae == 0 :
                    print('No')
                    exit()
                elif B < irekaeiti < D:
                    pass
                else:
                    print('No')
                    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

def main():
	N, A, B, C, D = map(int, input().split(" "))
	#N = int(input())
	S = input()
	S = list(S)
	S = S[:-1]

	A -= 1
	B -= 1
	C -= 1
	D -= 1

	if C < D:
		S = S[A:D]
	else:
		S = S[A:C]

	iwa = []
	kara = []
	nige = []
	for i, val in enumerate(S):
		if val == "#":
			if len(iwa) > 1 and iwa[-1] == i-1:
				print("No")
				sys.exit()
			iwa.append(i)
		else:
			if len(kara) > 2 and kara[-1] == i-1 and kara[-2] == i-2:
				nige.append(i)
			kara.append(i)
	'''
	for i in range(A+1, C):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()

	for i in range(B+1, D):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()
	'''
	if A < B and B < C and C < D:
		print("Yes")
		sys.exit()
	else:
		for i in nige:
			if B < i and i+2 < D:
				print("Yes")
				sys.exit()
	'''
	elif A < B and B < D and D < C:
		for i in range(A+1, C):
			if i in kara:
				tmp = kara.index(i)
				if C >= i+2 and len(kara)-2 > tmp :
					if (kara[tmp+1] == i+1) and (kara[tmp+2] == i+2):
						print("Yes")
						sys.exit()
		print("No")
		sys.exit()
	'''
	print("No")
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int, input().split())
S=input()
result = ""

for i in range(len(S)):
    if S[i:i+2]=="##":
        print("No")
        break

if result == "":
    if C < D:
        result ="Yes"
    else: # D < C
        if S[B-2] == "." and S[B] == ".":
            result = "Yes"
        else:
            for i in range(B-2,D-2):
                if S[i:i+4] == "#...":
                    result = "Yes"

if result == "":
    result = "No"

print(result)

Submission status: Wrong Answer

Solution code:
def f(i, y, S):
    while i < y:
        if S[i + 2] == '.':
            i += 2
        elif S[i + 1] == '.':
            i += 1
        else:
            return False
    return True
def g(i, y, S):
    while i < y:
        if S[i + 2] == '.':
            i += 2
        elif S[i + 1] == '.':
            i += 1
        else:
            break
    return i
def dc(n, a, b, c, d, S):
    S = list(S)
    S[b] = 'B'
    while a < b:
        a = g(a, c, S)
        if S[b + 1] == '.':
            S[b] = '.'
            b += 1
            S[b] = 'B'
        elif S[b + 2] == '.':
            S[b] = '.'
            b += 2
            S[b] = 'B'
        else:
            return a >= c
    return True
def solve():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    S = input() + "##"
    if c < d:
        S = list(S)
        return f(b, d, S) and f(a, c, S)
    else:
        if "##" in S[a + 1:c]:
            return False
        return dc(n, a, b, c, d, S)
    return True
print("Yes" if solve() else "No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
dot = []
sharp = []
A_clear = True
B_clear = True

if C<D:
    # print(S[B-1:D])
    tmp_s = 0
    for s in S[B-1:D]:
        if s == '#' and tmp_s>0 :
            B_clear = False
            break
        elif s == '#':
            tmp_s += 1
        else:
            tmp_s = 0

    tmp_s = 0
    for s in S[A-1:C]:
        if s == '#' and tmp_s>0 :
            A_clear = False
            break
        elif s == '#':
            tmp_s += 1
        else: 
            tmp_s = 0
    if A_clear == True and B_clear == True:
        print('Yes')
    else:
        print('No')
    
elif D<C:
    # A
    tmp_s = 0
    for s in S[A-1:C]:
        if s == '#' and tmp_s>0 :
            A_clear = False
            break
        elif s == '#':
            tmp_s += 1
    if A_clear==True:
        # B
        tmp_s = 0
        tmp_d = 0
        A_clear = False
        for s in S[B-1:D]:
            if s == '.' and tmp_d>=2:
                tmp_s += 1
                A_clear = True
            elif s == '.' and tmp_s>=0:
                tmp_d += 1
                tmp_s = 0
            elif s == '#' and tmp_d>=0:
                tmp_s += 1
                tmp_d = 0
            elif s == '#' and tmp_s>0 :
                B_clear = False
                break
        if A_clear == True and B_clear == True:
            print('Yes')
        else:  
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[B-1:D].count('...'))
            if(sf == 0):
                print(NO)
            ######### あとはここだけ考える ####
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[B-1:D].count('..b#') == 1):
                    print(NO)
                else:
                    print(YES)
            #################################
            elif(sf >= 2):
                print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = (int(i) for i in input().split())  
s = input()
if c<d:
  if s[a:c+1].count("##")>0 and s[b:d+1].count("##")>0:
    print("No")
  else:
    print("Yes")
else:
  if s[a:c+1].count("##")==0 and s[b:d+1].count("##")==0 and s[b-1:d+2].count("...")>0 :
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
N, A, B, C, D = map(int, input().split())
S = str(input())

if D > C:
    if '##' in S[B:D] or '##' in S[A:C]:
        print('No')
    else:
        print('Yes')
elif C > D:
    if '...' in S[0: A] and '##' in S[0:A]:
        print('No')
    elif '...' in S[D - 1: N] and '##' in S[D - 1: N]:
        print('No')
    elif '##' in S[B:D] or '##' in S[A: C]:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
n,a,b,c,d = map(int,input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
truth = [[0 for i in range(n)],[0 for j in range(n)]]

def solve(now,dest,i):
    if truth[i][now] == 1:
        return True
    if truth[i][now] == -1:
        return False
    if now == dest:
        truth[i][now] = 1
        return True
    if now + 2 < n:
        if s[now + 2] == '.' and solve(now + 2, dest,i):
            truth[i][now] = 1
            return True
    if now + 1 < n:
        if s[now + 1] == '.' and solve(now + 1, dest,i):
            truth[i][now] = 1
            return True
    else:
        truth[i][now] = -1
        return False

if c < d:
    if solve(a,c,0) and solve(b,d,1):
        print('Yes')
    else:
        print('No')

else:
    if solve(a,c,0) and solve(b,d,1):
        q = False
        for i in range(b,d):
            if truth[0][i-1] == 1 and s[i] == '.' and truth[0][i+1] == 1:
                q = True
                break
        if q:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
rocks = []
flag = True
for i, s in enumerate(S):
    if s == '#':
        rocks.append(i+1)
if 1 in [rocks[i+1] - rocks[i] for i in range(len(rocks) - 1)]:
    flag = False
if flag:
    if C > D:
        r_in_fpath = [r for r in rocks if r in range(B, D)]
        dif_r_in_fpath = [r_in_fpath[i+1] - r_in_fpath[i] for i in range(len(r_in_fpath) - 1)]
        if (B + 1 in rocks or B - 1 in rocks) and r_in_fpath[0] - B <= 2:
            if len(set(dif_r_in_fpath) - {2, 3}) == 0:
                if (D + 1 in rocks or D - 1 in rocks) and D - r_in_fpath[-1] <= 2:
                    flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

N,A,B,C,D = map(int, input().split())
S = input()

A -= 1
B -= 1
C -= 1
D -= 1

for i in range(A, max(C,D)):
    if S[i] == '#' and S[i+1] == '#':
        print('No')
        exit()
if C > D:
    for i in range(A, max(C,D)-1):
        if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.' and B <= i+1:
            print('Yes')
            exit()
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())

s = input()

flagA = True
flagB = True

for i in range(d - b - 1):
    if s[b + i] == "#" and s[b + i + 1] == "#":
        flagB = False

for i in range(c - a - 1):
    if ((s[a + i] == "#") or (a + i == d - 1)) and ((s[a + i + 1] == "#") or (a + i + 1 == d - 1)):
        flagA = False
        for j in range(d - b - 2):
            if (s[b + j] == "." and s[b + j + 1] == "." and s[b + j + 2] == "."):
                flagA = True
            if (s[b + 1] == "." and s[b + 2] == "."):
                flagA = True

if flagA and flagB:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()

def scan(a_, c_, f=False):
    mae = ''
    for i, l in enumerate(s, 1):
        if a_ > i:
            continue
        if c_ == i:
            return True
        if mae == l == '#':
            return False
        mae = l

def scan2(b_, d_):
    mae = ''
    maemae = ''
    for i, l in enumerate(s, 1):
        if b_ > i:
            continue
        if d_ == i - 1:
            return False
        if mae == maemae == l == '.':
            return True
        maemae = mae
        mae = l

if d > c and scan(a, c) and scan(b, d):
    print('Yes')
elif d < c and scan(a, c) and scan(b, d) and scan2(b, d):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#A問題
N,A,B,C,D = map(int,input().split())
Slist = list(str(input()))
if C < D:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0

    if flag == 1:
        print("No")
    else:
        print("Yes")
    
else:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    mass = 0
    Maxmass = 0
    aflag = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
                
    now = B-1
    for i in range(D-B+2):
        I = now + i
        if i == 0:
            mass+=1
        else:
            if Slist[I] == "#":
                Maxmass = max(Maxmass,mass)
                mass = 0
            else:
                mass+=1
    Maxmass = max(Maxmass,mass)

    if Maxmass <= 2:
        flag = 1
    
    if flag == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

for i in range(1, N):
	if S[i] == '#' and S[i-1] == '#':
		print('No')
		sys.exit()

if C < D:
	print('Yes')
	sys.exit()

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

if S[B+1] == '.' and S[B+2] == '.':
	print('Yes')
	sys.exit()

if B == D - 1:
	print('Yes')
	sys.exit()

for i in range(B, D-1):
	if S[i] == '#':
		if S[i+1] == '.' and S[i+2] == '.' and S[i+3] == '.':
			print('Yes')
			sys.exit()

print('No')
sys.exit()