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):
from collections import deque
def solve():
    n,a,b,c,d = map(int,input().split())
    s = input()
    
    flag1 = True
    
    flag2 = True
    
    flag3 = False
    cnt = 0
    for i in range(a-1,c):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag1 = False
    cnt=0
    for i in range(b-1,d):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag2 = False
    mx = a
    mn = a
    que = deque()
    que.append((a-1,0))
    while len(que):
        p = que.pop()
        cnt = p[1]
        pos = p[0]
        mx = max(mx,pos)
        mn = min(mn,pos)
        if pos==a-1:
            if pos+1<n:
                if s[pos+1]=='#':
                    new = cnt+1
                else:
                    new = 0
                if new>=2:
                    continue
                else:
                    que.append((pos+1,new))
            if pos-1>=0:
                if s[pos-1]=='#':
                    new = cnt+1
                else:
                    new = 0
                if new>=2:
                    continue
                else:
                    que.append((pos-1,new))
        if pos<a-1:
            if pos-1>=0:
                if s[pos-1]=='#':
                    new = cnt+1
                else:
                    new = 0
                if new>=2:
                    continue
                else:
                    que.append((pos-1,new))
        if pos>a-1:
            if pos+1<n:
                if s[pos+1]=='#':
                    new = cnt+1
                else:
                    new = 0
                if new>=2:
                    continue
                else:
                    que.append((pos+1,new))
    cnt=0
    print(mn,mx)
    for i in range(mn,mx+1):
        if s[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt>=3:
            flag3 = True

    if flag1 and flag2:
        if c<d:
            print('Yes')
        else:
            if flag3:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
if __name__ == "__main__":
    solve()

from collections import deque
def solve():
    n,a,b,c,d = map(int,input().split())
    s = input()
    
    flag1 = True
    
    flag2 = True
    
    flag3 = False
    cnt = 0
    for i in range(a-1,c):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag1 = False
    cnt=0
    for i in range(b-1,d):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag2 = False
    l = max(a,b)
    r = min(c,d)
    if r<n and s[r]!='#':
        r+=1
    if l-2>=0 and s[l-2]!='#':
        l-=1
    for i in range(l-1,r):
        if s[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt>=3:
            flag3 = True

    if flag1 and flag2:
        if c<d:
            print('Yes')
        else:
            if flag3:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
if __name__ == "__main__":
    solve()

Verdicts: Wrong Answer

Accepted