Problem: 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.

Submission attempts (in order):
##agc034_a
N,A,B,C,D = map(int, input().split()) 
S = [0] + list(input())









#A<B
#A<C
#B<D

if A < B < D < C:
    need_passing = True
elif (A < B < C < D) or (A < C < B < D):
    need_passing = False



    #Yes
        
        
            
    #No
        

passing_point_set = set() 
imos_stop = list() 
imos_stop.append(0)

for i in range(1,N-1):
    if S[i] == S[i+1] == "#":
        imos_stop.append(imos_stop[-1] + 1)
    else:
        imos_stop.append(imos_stop[-1])

    if S[i] == S[i+1] == S[i+2] == ".":
        passing_point_set.add(i)

i += 1
if S[i] == S[i+1] == "#":
    imos_stop.append(imos_stop[-1] + 1)
else:
    imos_stop.append(imos_stop[-1])

imos_stop.append(imos_stop[-1])


#print(passing_point_set)

def is_reachable(start,goal):
    if imos_stop[start] == imos_stop[goal] and start < goal: 
        return True
    else:
        return False

if need_passing == True:
    for passing_point in passing_point_set
        if is_reachable(A,passing_point) == is_reachable(passing_point,C) == is_reachable(B,passing_point) == is_reachable(passing_point,D) == True
            and D != passing_point and D != passing_point+2:
            
            
            
            
            print("Yes")
            break
    else:
        print("No")
else:
    if is_reachable(A,C) == is_reachable(B,D) == True:
        print("Yes")
    else:
        print("No")

##agc034_a
N,A,B,C,D = map(int, input().split()) 
S = [0] + list(input())









#A<B
#A<C
#B<D

if A < B < D < C:
    need_passing = True
elif (A < B < C < D) or (A < C < B < D):
    need_passing = False



    #Yes
        
        
            
    #No
        

passing_point_set = set() 
imos_stop = list() 
imos_stop.append(0)

for i in range(1,N-1):
    if S[i] == S[i+1] == "#":
        imos_stop.append(imos_stop[-1] + 1)
    else:
        imos_stop.append(imos_stop[-1])

    if S[i] == S[i+1] == S[i+2] == ".":
        passing_point_set.add(i)

i += 1
if S[i] == S[i+1] == "#":
    imos_stop.append(imos_stop[-1] + 1)
else:
    imos_stop.append(imos_stop[-1])

imos_stop.append(imos_stop[-1])


#print(passing_point_set)

def is_reachable(start,goal):
    if imos_stop[start] == imos_stop[goal] and start < goal: 
        return True
    else:
        return False

if need_passing == True:
    for passing_point in passing_point_set
        if is_reachable(A,passing_point) == is_reachable(passing_point,C) == is_reachable(B,passing_point) == is_reachable(passing_point,D) == True and D != passing_point and D != passing_point+2:
            
            
            
            
            print("Yes")
            break
    else:
        print("No")
else:
    if is_reachable(A,C) == is_reachable(B,D) == True:
        print("Yes")
    else:
        print("No")

##agc034_a
N,A,B,C,D = map(int, input().split()) 
S = [0] + list(input())





#  A<B
#  A<C
#  B<D

if A < B < D < C:
    need_passing = True
elif (A < B < C < D) or (A < C < B < D):
    need_passing = False



    #Yes
        
        
            
    #No
        

passing_point_set = set() 
imos_stop = list() 
imos_stop.append(0)

for i in range(1,N-1):
    if S[i] == S[i+1] == "#":
        imos_stop.append(imos_stop[-1] + 1)
    else:
        imos_stop.append(imos_stop[-1])

    if S[i] == S[i+1] == S[i+2] == ".":
        passing_point_set.add(i)

i = N-1
if S[i] == S[i+1] == "#":
    imos_stop.append(imos_stop[-1] + 1)
else:
    imos_stop.append(imos_stop[-1])
#i = N

imos_stop.append(imos_stop[-1]) #   .##.


#print(passing_point_set)

def is_reachable(start,goal):
    if imos_stop[start] == imos_stop[goal] and start <= goal: 
        return True
    else:
        return False

if need_passing == True: 
    for passing_point in passing_point_set:
        if ((is_reachable(A,passing_point) == True and is_reachable(passing_point,C) == True and is_reachable(B,passing_point) == True and is_reachable(passing_point,D) == True and D != passing_point) or
            (B-1 in passing_point_set and is_reachable(A,C) == True and is_reachable(B,D) == True)):
            
            
            
            
                
                
                
                
                
            
            print("Yes")
            break
    else:
        print("No")
else:
    if is_reachable(A,C) == True and is_reachable(B,D) == True:
        print("Yes")
    else:
        print("No")
        
        


Verdicts: Runtime Error

Runtime Error

Accepted