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: Accepted

Solution code:
n,A,B,C,D = map(int,input().split())
s = input()[A-1:max(C,D)]
flag = 1
a,b,c,d = 0,B-A,C-A,D-A
if s[a]=='#' or s[b]=='#' or s[c]=='#' or s[d]=='#':
  flag = 0
if bool('##' in s) == 1:
  flag = 0
if c > d:
  scut = s[b-1:d+2]
  if bool('...' in scut) == 0:
    flag = 0
if flag == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N,A,B,C,D=map(int,input().split())
S=input().strip()
S+="#####"

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

if C<D:
    while B!=D or  A!=C:
        #print(A,B)
        if B!=D and S[B+1]==".":
            B+=1
        elif B!=D and S[B+2]==".":
            B+=2
        elif B!=D and S[B+1]=="#" and S[B+2]=="#":
            print("No")
            sys.exit()


        if A!=C and S[A+1]==".":
            A+=1
        elif A!=C and S[A+2]==".":
            A+=2
        elif A!=C and S[A+1]=="#" and S[A+2]=="#":
            print("No")
            sys.exit()

    print("Yes")

else:
    while A<B:
            
        if S[A+1]=="." and A+1!=B:
            A+=1
        elif S[A+2]=="." and A+2!=B:
            A+=2
        elif S[A+1]=="#" and S[A+2]=="#":
            print("No")
            sys.exit()

        if A+1==B or (A+2==B and S[A+1]=="#"):
            break

    while True:
        if A+1==B and S[B+1]==".":
            A+=2
            break

        if S[B+1]==".":
            B+=1
        elif S[B+2]==".":
            B+=2
        else:
            print("No")
            sys.exit()

        if S[A+1]==".":
            A+=1
        elif S[A+2]==".":
            A+=2

        if B>D:
            print("No")
            sys.exit()

    
    while B!=D or  A!=C:
        
        if A!=C and S[A+1]==".":
            A+=1
        elif A!=C and S[A+2]==".":
            A+=2
        elif A!=C and S[A+1]=="#" and S[A+2]=="#":
            print("No")
            sys.exit()
            
        if B!=D and S[B+1]==".":
            B+=1
        elif B!=D and S[B+2]==".":
            B+=2
        elif B!=D and S[B+1]=="#" and S[B+2]=="#":
            print("No")
            sys.exit()




    print("Yes")

Submission status: Accepted

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

i=0
j=0
gg=0
nnt=0
if c<d:
    i=a-1
    while i!=d:
        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break
        i=i+1

else:
    i=a-1
    nnt=1
    while i!=c-1:

        if s[i]==".":
            gg=gg+1
        else:
            gg=0
        if gg>=3:
            if i>=b:
                if i<=d:
                    nnt=0




        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break

        i=i+1
if nnt==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
NABCD = list(map(int,input().split()))
N = NABCD[0]
A = NABCD[1]
B = NABCD[2]
C = NABCD[3]
D = NABCD[4]
S = input()

output = "No"

cous = 0
maxs = 0
cour = 0
maxr = 0
maxi = np.array([])
maxir = np.array([])

for i in range(N):
    p = S[i]
    if p == "#":
        cour += 1
        cous = 0
    elif p == ".":
        cous += 1
        cour = 0
    if cour > maxr:
        maxr = cour
    if cous > maxs:
        maxs = cous
    if cous > 2:
        maxi = np.append(maxi,i+1)
    if cour >= 2:
        maxir = np.append(maxir,i+1)

keysum = sum((maxi-1>=B)*(maxi-1<=D))
outsumA = sum((A<maxir)*(maxir<C))
outsumB = sum((B<maxir)*(maxir<D))
outsum = outsumA + outsumB
if C > D:
    if (maxr < 2)and(maxs >2)and(keysum>0):
        output = "Yes"
    elif (maxr >= 2)and(outsum==0)and(maxs >2)and(keysum>0):
        output = "Yes"
elif D > C:
    if maxr < 2:
        output = "Yes"
    elif (maxr >= 2)and(outsum==0):
        output = "Yes"

print(output)

Submission status: Accepted

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

ans = "Yes"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(a - 1, c - 1))):
    ans = "No"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(b - 1, d - 1))):
    ans = "No"
if d < c and not any(map(lambda i: b <= i + 1 <= d, list(filter(lambda i: s[i - 1] == s[i] == s[i + 1] == '.', range(1, n - 1))))):
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
import sys
import copy

def solve(n, a, b, c, d, s):
    if c < d:
        if b < c:
            width = [(a-1, d-1)]
        else:
            width = [(a-1, c-1), (b-1, d-1)]

        for left, right in width:
            for i in range(left, right):
                if s[i] == "#" and s[i+1] == "#":
                    return "No"
        return "Yes"
    else:
        flag = False
        for i in range(a-1, c-1):
            if s[i] == "#" and s[i+1] == "#":
                return "No"
            if b - 2 <= i <= d - 2 and s[i] == "." and s[i+1] == "." and  s[i+2] == "." :
                flag = True
        return "Yes" if flag else "No"


if __name__ == '__main__':

    n, a, b, c, d = map(int, sys.stdin.readline().strip().split(" "))
    s = sys.stdin.readline().strip()
    print solve(n, a, b, c, d, s)

Submission status: Accepted

Solution code:
import sys

def chk(p,q):
    if q==p+1: return 1
    else:
        for i in range(p,q-1):
            if s[i]+s[i+1]==2: return 0

        return 1


N,A,B,C,D=map(lambda x: int(x)-1,input().split())
N+=1
S=input()
s=[]
for i in range(N):
    if S[i]==".": s.append(0)
    else: s.append(1)

if chk(A,C)==0 or  chk(B,D)==0: print("No"),sys.exit()
if C<B or C<D: print("Yes"),sys.exit()



for i in range(B,D+1):
    if s[i-1]+s[i]+s[i+1]==0: print("Yes"),sys.exit()

print("No")

Submission status: Accepted

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

S = S[min(A, B)-1:max(C, D)]
if "##" in S:
    print("No")
else:
    if "..." in S:
        S_b = S[B-2:min(D+1, N)]
        if "..." in S_b:
            print("Yes")
        else:
            print("No")
    else:
        if C < D:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

if C < B:
    if S[A-1:C-1].find("##") == -1 and S[B-1:D-1].find("##") == -1:
        print("Yes")
    else:
        print("No")
elif D > C :
    if S[A-1:D-1].find("##") == -1 :
        print("Yes")
    else:
        print("No")
else:
    if S[A-1:C].find("##") == -1 and S[B-2:D+1].find("...") >= 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()
grid = []
for rock in s:
    grid.append(rock == '#')

if grid[c-1] or grid[d-1]:
    print('No')

max_rock_count = 0
rock_count = 0
if c < d:
    for i in range(a-1, d):
        if grid[i]:
            rock_count += 1
        else:
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count >= 2:
        print('No')
    else:
        print('Yes')
elif c > d:
    max_rock_count = 0
    rock_count = 0
    canSkip = False
    for i in range(a-1, c):
        if grid[i]:
            rock_count += 1
        else:
            if b - 1 <= i and i <= c - 2 and not grid[i-1] and not grid[i] and not grid[i+1]:
                if i-1 != d - 1:
                    canSkip = True
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count <= 1 and canSkip:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1
s = str(input())
if C < D:
    if "##" in s[A:C] or "##" in s[B:D]:
        print("No")
    else:
        print("Yes")
else:
    if "##" in s[A:C] or "##" in s[B:D]:
        print("No")
    else:
        if D-B >= 2:
            if "..." in s[B-1:D+1]:
                print("Yes")
            elif s[D-1] == ".":
                print("Yes")
            else:
                print("No")
        else:
            if s[B+2] == "." or s[B-1] == ".":
                print("Yes")
            else:
                print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
s2=s[min(a,b)-1:max(c,d)]
n2=len(s2)

sl=s[a-1:c]
sr=s[b-1:d]

for i in range(len(sl)-1):
    if sl[i]=="#" and sl[i+1]=="#":
        print("No")
        import sys
        sys.exit()
for i in range(len(sr)-1):
    if sr[i]=="#" and sr[i+1]=="#":
        print("No")
        import sys
        sys.exit()


if c<d:
    print("Yes")
else:
    for i in range(n2-2):
        if s2[i]=="." and s2[i+1]=="." and s2[i+2]=="." and i<d-1 and b<i+3:
            print("Yes")
            import sys
            sys.exit()
    print("No")

Submission status: Accepted

Solution code:
import copy
n,a,b,c,d=map(int, input().split())
S='.'+input()
dpa=[0]*(n+1)
dpb=[0]*(n+1)
seta=[c]
setb=[d]
if d<c:
    if S[b-1:d+2].find('...')>=0:
        while seta:
            i = seta.pop()
            if i>0 and S[i-1]=='.' and dpa[i-1]==0:
                dpa[i-1]=1
                seta.append(i-1)
            if i>1 and S[i-2]=='.' and dpa[i-2]==0:
                dpa[i-2]=1
                seta.append(i-2)
        while setb:
            i = setb.pop()
            if i>0 and S[i-1]=='.' and dpb[i-1]==0:
                dpb[i-1]=1
                setb.append(i-1)
            if i>1 and S[i-2]=='.' and dpb[i-2]==0:
                dpb[i-2]=1
                setb.append(i-2)
else:
    while setb:
        i = setb.pop()
        if i>0 and S[i-1]=='.' and dpb[i-1]==0:
            dpb[i-1]=1
            setb.append(i-1)
        if i>1 and S[i-2]=='.' and dpb[i-2]==0:
            dpb[i-2]=1
            setb.append(i-2)
    while seta:
        i = seta.pop()
        if i>0 and S[i-1]=='.' and dpa[i-1]==0:
            dpa[i-1]=1
            seta.append(i-1)
        if i>1 and S[i-2]=='.' and dpa[i-2]==0:
            dpa[i-2]=1
            seta.append(i-2)
if dpa[a]==1 and dpb[b]==1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

def PNO():
    print("No")
    sys.exit(0)

def PYES():
    print("Yes")
    sys.exit(0)



n, a, b, c, d = list(map(int, input().split()))
s = str(input())
a -= 1
b -= 1
c -= 1
d -= 1

ac = str(s[a:c])
##################
#print(ac)
if (ac.find("##") != -1):
    PNO()

bd = str(s[b:d])
##################
#print(bd)
if (bd.find("##") != -1):
    PNO()

if (c > d):
    bdd = str(s[b-1:d+2])
    ##################
    #print(bdd)
    if (bdd.find("...") == -1):
        PNO()

PYES()

Submission status: Accepted

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

S[A-1] = 'A'
S[B-1] = 'B'

        
if B < C:
    while(B < D):
        if S[B] == '.' and S[B-2] == '.':
            while(A < C):
                #print("1こ先")
                if S[A] == '.':
                    S[A] = 'A'
                    S[A-1] = '.'
                else:
                    #print('2こ先')
                    if A+1 < N and S[A+1] == '.':
                        S[A+1] = 'A'
                        S[A-1] = '.'
                        A += 1
                    else:
                        break
                A += 1
        
                #print(S)
        
        if S[B] == '.':
            S[B] = 'B'
            S[B-1] = '.'
        else:
            if S[B+1] == '.' and B+1 < N:
                S[B+1] = 'B'
                S[B-1] = '.'
                B += 1
            else:
                break
        
        B += 1
        
        #print(S)
    
    #print("B end")
    while(A < C):
        #print("1こ先")
        if S[A] == '.':
            S[A] = 'A'
            S[A-1] = '.'
        else:
            #print('2こ先')
            if A+1 < N and S[A+1] == '.':
                S[A+1] = 'A'
                S[A-1] = '.'
                A += 1
            else:
                break
        A += 1
        
        #print(S)
        
elif B > C:
    while(A < C):
        if S[A] == '.' and S[A-2] == '.':
            while(B < D):
                #print("1こ先")
                if S[B] == '.':
                    S[B] = 'B'
                    S[B-1] = '.'
                else:
                    #print('2こ先')
                    if B+1 < N and S[B+1] == '.':
                        S[B+1] = 'B'
                        S[B-1] = '.'
                        B += 1
                    else:
                        break
                B += 1
        
                #print(S)
        
        if S[A] == '.':
            S[A] = 'A'
            S[A-1] = '.'
        else:
            if S[A+1] == '.' and A+1 < N:
                S[A+1] = 'A'
                S[A-1] = '.'
                A += 1
            else:
                break
        
        A += 1
        
        #print(S)
    
    #print("A end")
    while(B < D):
        #print("1こ先")
        if S[B] == '.':
            S[B] = 'B'
            S[B-1] = '.'
        else:
            #print('2こ先')
            if B+1 < N and S[B+1] == '.':
                S[B+1] = 'B'
                S[B-1] = '.'
                B += 1
            else:
                break
        B += 1
        
        #print(S)
    
    
        
if A == C and B == D:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

if c<d:
    if '##' in s[a-1:d-1]:
        print('No')
    else:
        print('Yes')
elif d<c:
    if '##' in s[a-1:c-1]:
        print('No')
    else:
        if '...' in s[b-2:d+1]:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys

def is_dubble_wall(min_, max_, S):
    for i in range(min_, max_):
        if (S[i] == "#") and (i != max_ - 1) and (S[i + 1] == "#"):
            return True
    return False

def main():
    N, A, B, C, D = map(int, input().split())
    S = "#"
    S += input()
    assert(len(S) == N + 1)
    if (B < C):
        if is_dubble_wall(min(A, B), max(C, D), S):
            print("No")
            sys.exit()
        if (D < C):
            #二人が入れ替わる時
            num = 0
            array = []
            for i in range(B - 1, D + 2):
                if S[i] == ".":
                    num += 1
                else:
                    array.append(num)
                    num = 0
            array.append(num)
            if max(array) >= 3:
                print("Yes")
            else:
                print("No")
        else:
            #入れ替わらない時
            print("Yes")
    else:
        if (~is_dubble_wall(A, C, S) and ~is_dubble_wall(B, D, S)):
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

#N,A,B,C,D = 15,1,3,15,13
#S = "...#.#...#.#..."

#N,A,B,C,D = 4,1,2,4,3
#S = "...."

S = "#" + S + "#"
N = N+2

M = max(C,D)

if "##" in S[A:M+1]:
	print('No')
	exit()
if C < D:
	print('Yes')
	exit()

pos = B
while(True):
	if pos == D:
		if S[pos+1] == "#" or S[pos-1] == "#":
			print("No")
			exit()
		else:
			print("Yes")
			exit()
	if pos == D-1:
		if S[pos+2] == "#" and S[pos-1] == "#":
			print("No")
			exit()
		else:
			print("Yes")
			exit()
	loc = S[pos+1:pos+3]
	if loc == "..":
		print('Yes')
		exit()
	if loc == "#.":
		pos += 2
	if loc == ".#":
		if S[pos-1] == ".":
			print('Yes')
			exit()
		pos += 3

Submission status: Accepted

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

if S[A-1:max([C, D])].find('##') != -1:
    print('No')
    exit()

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

if S[B-2:D+1].find('...') >= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    split = input().split(' ')
    n = int(split[0]) - 1
    a = int(split[1]) - 1
    b = int(split[2]) - 1
    c = int(split[3]) - 1
    d = int(split[4]) - 1
    s = input()
    isOK = False
    if c < d:
        isOK = not ('##' in s[a:c] or '##' in s[b:d])
    else:
        isOK = (not ('##' in s[a:c] or '##' in s[b:d])) and ('...' in s[b-1:d+2])
    print('Yes' if isOK else 'No')

Submission status: Accepted

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

if B<C and C<D:
    f = True
    for i in range(A,D-1):
        if S[i-1]=="#" and S[i]=="#":
            f = False
            break
elif B<D and D<C:
    f = False
    if B<2:
        B = 2
    for i in range(B,D+1):
        if S[i-2]=="." and S[i-1]=="." and S[i]==".":
            f = True
            break
else:
    f = True
    for i in range(B,D-1):
        if S[i-1]=="#" and S[i]=="#":
            f = False
            break
    if f:
        for i in range(A,C-1):
            if S[i-1]=="#" and S[i]=="#":
                f = False
                break
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from copy import deepcopy

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


def start_funuke():
    s = deepcopy(S)
    funuke = s[B - 1 : D]
    for i in range(1, len(funuke)):
        if funuke[i] == "#" and funuke[i - 1] == "#":
            return False
    s[D - 1] = "#"
    sunuke = s[A - 1 : C]
    for i in range(1, len(sunuke)):
        if sunuke[i] == "#" and sunuke[i - 1] == "#":
            return False
    return True


def start_sunuke():
    s = deepcopy(S)
    funuke = s[B - 1 : D]
    f = True
    for i in range(2, len(funuke)):
        if (funuke[i] == "." and funuke[i - 1] == "." and funuke[i - 2] == ".") and (
            i - 1 != C - 1
        ):
            f = False
    s[B - 1] = "%"
    sunuke = s[A - 1 : C]
    for i in range(2, len(sunuke)):
        if sunuke[i] == "." and sunuke[i - 1] == "%" and sunuke[i - 2] == ".":
            f = False
    if f:
        return False
    s = deepcopy(S)
    sunuke = s[A - 1 : C]
    for i in range(1, len(sunuke)):
        if sunuke[i] == "#" and sunuke[i - 1] == "#":
            return False
    s[C - 1] = "#"
    funuke = s[B - 1 : D]
    for i in range(1, len(funuke)):
        if funuke[i] == "#" and funuke[i - 1] == "#":
            return False
    return True


f1 = start_funuke()
f2 = start_sunuke()
if f1 or f2:
    print("Yes")
else:
    print("No")
# ans = "Yes" if (start_funuke() or start_sunuke()) else "No"
# print(ans)

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = list(input())
S[A - 1] = 'A'
S[B - 1] = 'B'
a1 = 0
a2 = 0
ans = ''
if C > D:
    a1 = 'A'
    a2 = 'B'
    tmp1 = C - 1
    tmp2 = D - 1
    now1 = A - 1
    now2 = B - 1
else:
    a1 = 'B'
    a2 = 'A'
    tmp1 = D - 1
    tmp2 = C - 1
    now1 = B - 1
    now2 = A - 1

while True:
    if now1 != tmp1:
        if now1 + 1 <= len(S) - 1 and S[now1 + 1] == '.' and now1 + 1 <= tmp1:
            S[now1] = '.'
            S[now1 + 1] = a1
            now1 += 1
        elif now1 + 2 <= len(S) - 1 and S[now1 + 2] == '.' and now1 + 2 <= tmp1:
            S[now1] = '.'
            S[now1 + 2] = a1
            now1 += 2
        elif now2 + 1 <= len(S) - 1 and S[now2 + 1] == '.' and now2 + 1 <= tmp2:
            S[now2] = '.'
            S[now2 + 1] = a2
            now2 += 1
        elif now2 + 2 <= len(S) - 1 and S[now2 + 2] == '.' and now2 + 2 <= tmp2:
            S[now2] = '.'
            S[now2 + 2] = a2
            now2 += 2
        else:
            ans = 'No'
            break
    elif now2 != tmp2:
        if now2 + 1 <= len(S) - 1 and S[now2 + 1] == '.' and now2 + 1 <= tmp2:
            S[now2] = '.'
            S[now2 + 1] = a2
            now2 += 1
        elif now2 + 2 <= len(S) - 1 and S[now2 + 2] == '.' and now2 + 2 <= tmp2:
            S[now2] = '.'
            S[now2 + 2] = a2
            now2 += 2
        else:
            ans = 'No'
            break
    else:
        ans = 'Yes'
        break

print(ans)

Submission status: Accepted

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

if c < d:
  if "##" in s[a:c] or "##" in s[b:d]:
    print("No")
  else:
    print("Yes")
else:
  if "##" in s[:c]:
    print("No")
  else:
    if "..." in s[b-2:d+1]:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


N, A, B, C, D = inpl()
S = "#" + input() + "#"
section = [-1 for i in range(N + 2)]
ischange = defaultdict(lambda: False)
interval = defaultdict(lambda: [-1, -1])
sec_num = 0

flag = True
for i, s in enumerate(zip(S, S[1:])):
    if s == ("#", "#"):
        sec_num += 1
        section[i] = -1
        section[i + 1] = -1
        flag = True
    else:
        section[i] = sec_num
        section[i + 1] = sec_num
        if flag is True:
            interval[sec_num][0] = sec_num
            flag = False
        else:
            interval[sec_num][1] = sec_num + 1
    if B - 1 <= i < D and i < N and S[i] + S[i + 1] + S[i + 2] == "...":
        ischange[sec_num] = True

if section[A] != section[C] or section[B] != section[D]:
    print("No")
elif section[A] != section[B]:
    print("Yes")
elif C < D:
    print("Yes")
elif ischange[section[A]] is True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def f(A, B, C, D, S):
    T = list(S)
    T[A] = "A"
    T[B] = "B"
    T[C] = "C"
    T[D] = "D"
    print("".join(T))


def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    A = A-1
    B = B-1
    C = C-1
    D = D-1
    # f(A, B, C, D, S)

    def reachable(A, C, S):     # O(N)
        if A > C:
            return False
        # AからCへ到達可能ですか
        if S[A:C+1].find("##") == -1:
            return True
        else:
            return False

    if C > D:
        # できるだけ早く追い越す
        # 追い越すためには、"..."という領域が必要。
        oikoshi = S[B-1:].find("...")
        if oikoshi == -1:
            no()
            return
        if reachable(A, B-1+oikoshi, S) and reachable(B, B-1+oikoshi+1, S):
            A = B-1+oikoshi + 2
            B = B-1+oikoshi + 1
            # f(A, B, C, D, S)
        else:
            no()
            return

    # ２連岩なければ通れる
    if reachable(A, C, S) and reachable(B, D, S):
        yes()
    else:
        no()
    return


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: Accepted

Solution code:
import sys

n,a,b,c,d = map(int,input().split())
s = list(input())

a = a-1
b = b-1
c = c-1
d = d-1

s[a] = "A"
s[b] = "B"


if c < d:
    while s[c] != "A" or s[d] != "B":
        if s[d] != "B":
            if s[b+1] == ".":
                s[b+1] = "B"
                s[b] = "."
                b += 1
                continue
            elif s[b+2] == ".":
                s[b+2] = "B"
                s[b] = "."
                b += 2
                continue
        if s[c] != "A":
            if s[a+1] == ".":
                s[a+1] = "A"
                s[a] = "."
                a += 1
                continue
            elif s[a+2] == ".":
                s[a+2] = "A"
                s[a] = "."
                a += 2
                continue
        print("No")
        sys.exit()
if d < c:
    while s[c] != "A" or s[d] != "B":
        if s[c] != "A":
            if s[a+1] == ".":
                s[a+1] = "A"
                s[a] = "."
                a += 1
                continue
            elif s[a+2] == ".":
                s[a+2] = "A"
                s[a] = "."
                a += 2
                continue
        if s[d] != "B":
            if s[b+1] == ".":
                s[b+1] = "B"
                s[b] = "."
                b += 1
                continue
            elif s[b+2] == ".":
                s[b+2] = "B"
                s[b] = "."
                b += 2
                continue
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:

N,A,B,C,D = map(int,input().split())
a= input()
f = 0
s = 0
d = 1
t = []
k = []

f1 = 0
s1 = 0
d1 = 1
t1 = []
k1 = []


for i in a[A-1:C]:
    if i == "." and f ==1:
        k.append(d)
        s = 1
        f = 0
    elif i == ".":s+=1
    
    elif i == "#" and f==0:
        t.append(s)
        d = 1
        f = 1
    elif i == "#":d+=1
else:
    if f==1:
        k.append(d)
    else:
        t.append(s)
for i in a[B-2:D]:
    if i == "." and f1 ==1:
        k1.append(d1)
        s1 = 1
        f1 = 0
    elif i == ".":s1+=1
    
    elif i == "#" and f1==0:
        t1.append(s1)
        d1 = 1
        f1 = 1
    elif i == "#":d1+=1
else:
    if f1==1:
        k1.append(d1)
    else:
        t1.append(s1)
# print(t,k)
# print(t1,k1)
if C < D :
    if len(k) == sum(k) and  len(k1) == sum(k1):
        print("Yes")
    else:
        print("No")
else:
    if len(k) == sum(k) and any([i > 2 for i in t1]) :
        print("Yes")
    elif len(k) == sum(k) and t1[-1] >1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
s[c-1]="c"
s[d-1]="d"
flag=False
lim=max(c,d)
for i in range(a+1,lim-1):
  if s[i]!="#":
    if b-1<=i and i<=d-1:
      if s[i-1]!="#" and s[i+1]!="#":
        flag=True
    continue
  if s[i+1]=="#":
    print("No")
    exit()
if flag==False and d<c and (s[d-2]=="#" or s[d]=="#"):
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


N,A,B,C,D = ints_raw()
S = input()
#N = int_raw()


def main():
    ans = 0
    if D==C:
        return "No"
    if S[D-1]=="#" or S[C-1]=="#":
        return "No"
    if "##" in S[A:max(B, D)]:
        return "No"
    if D>C:
        return "Yes"
    else:
        if "..." in S[B-2:min(min(D+1,N),C)]:
            #print(S[B-2:min(min(D+1, N), C)])
            return "Yes"
        return "No" 
    return ans


print(main())

Submission status: Accepted

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

s = input() + '.'

def solve():
    if C < D:
        cnt = 0
        for i in range(B, D):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        cnt = 0
        for i in range(A, C):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        return True
    else:
        cnt = 0
        flg = False
        for i in range(B, D+1):
            if s[i] == '#':
                cnt += 1
            else:
                if s[i-1] == '.' and s[i+1] == '.':
                    flg = True
                cnt = 0
            if cnt > 1:
               return False 

        if not flg:
            return False

        cnt = 0
        for i in range(A, C):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        return True

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

Submission status: Accepted

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

# print(s[2])
if d < c:
    ans = "No"
    for j in range(b-2, d-1, 1):
        # print(s[j],s[j+1],s[j+2])
        if s[j] == "." and s[j+1] == "." and s[j+2] == ".":
            ans = "Yes"
else:
    ans = "Yes"
e = max(c, d)
for i in range(a, e-1, 1):
    if s[i] == "#" and s[i+1] == "#":
        ans = "No"

if s[c-1] == "#" or s[d-1] == "#":
    ans = "No"

print(ans)