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:
import re
a=list(map(int,input().split()))
s=input()
N=a[0]
A=a[1]
B=a[2]
C=a[3]
D=a[4]
if C<D:
    l=s[A-1:C]
    l1=re.findall('#+',l)
    n=0
    max=0
    while True:
        if max<len(l1[n]):
            max=len(l1[n])
        n=n+1
        if n==len(l1):
            break            
    if max>=2:
        print('No')
    else:
        l=s[B-1:D]
        l1=re.findall('#+',l)
        n=0
        max=0
        while True:
            if max<len(l1[n]):
                max=len(l1[n])
            n=n+1
            if n==len(l1):
                break
        if max>=2:
           print('No')
        else:
            print('YES')
else:
    l=s[A-1:C]
    l1=re.findall('#+',l)
    n=0
    max=0
    while True:
        if max<len(l1[n]):
            max=len(l1[n])
        n=n+1
        if n==len(l1):
            break            
    if max>=2:
        print('No')
    else:
        l=s[B-1:D]
        l1=re.findall('#+',l)
        n=0
        max=0
        while True:
            if max<len(l1[n]):
                max=len(l1[n])
            n=n+1
            if n==len(l1):
                break
        if max>=2:
            print('No')
        else:
            l=s[B-2:D+1]
            l1=re.findall('\.+',l)
            print(l1)
            n=0
            max=0
            while True:
                if max<len(l1[n]):
                    max=len(l1[n])
                n=n+1
                if n==len(l1):
                    break
            if max>=3:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
if c<d:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f==1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
  if f==1:print('No')
  else:print('Yes')
else:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
  if f==0:
    if (s[d-2]=='#' or s[d]=='#') and (s[b-2]=='#' or s[b]=='#'):
      ct=0
      for i in range(b-1,d-2):
        if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
          ct=1
          break
      if ct==0:
        f=1
  if f==1:print('No')
  else:print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
N, A, B, C, D = map(int, input().split())
S = [i for i in input()]
action = [1,2,1,2]
W = len(S)
judge = [False, False]

def dfs(x, y, field, tmp):
    if C-1 == x and D-1 == y:
        return True
    for idx, nx in enumerate(action):
        if idx <= 1:
            nx += x
            if nx < W:
                if nx == y:
                    continue
                elif field[nx] == "#":
                    continue
                tmp = field[nx]
                field[nx] = "#"
                field[x] = tmp
                return dfs(nx, y, field, tmp)
        else:
            nx += y
            if nx < W:
                if field[nx] == "#":
                    continue
                elif nx == x:
                    continue
                tmp = field[nx]
                field[nx] = "#"
                field[y] = tmp
                return dfs(x, nx, field, tmp)
    return False


if dfs(A-1,B-1,S, "."):
    print("Yes")
else:
    print("No")

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 - 2):
    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(c - a - 3):
            if (s[a + j] == "." and s[a + j + 1] == "." and s[a + j + 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())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
if (A < B < D < C):
    cnt = 0
    cntl = [0]
    for i in range(A+1,C):
        if (S[i] == '.') & (S[i+1] == '.'):
            cnt += 1
            if i == C-1:
                cntl.append(cnt)
        elif (S[i] == '.') & (S[i+1] == '#'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) < 2:
        print('No')
    else:
        cnt = 0
        cntL = [0]
        for i in range(B+1,D-1):
            if (S[i] == '#') & (S[i+1] == '#'):
                cnt += 1
                if i == C-1:
                    cntL.append(cnt)
            elif (S[i] == '#') & (S[i+1] == '.'):
                cntL.append(cnt)
                cnt = 0
        if max(cntL) >= 1:
            print('No')
        else:
            if (S[D+1] == '.')&(S[D-1] == '.'):
                if (S[B+1] == '.')&(S[B-1] == '.'):
                    print('Yes')
                else:
                    x = 0
                    xl = [0]
                    for i in range(B+1,D-1):
                        if (S[i] == '.') & (S[i+1] == '.'):
                            x += 1
                            if x == D-2:
                                xl.append(x)
                        elif (S[i] == '.') & (S[i+1] == '#'):
                            xl.append(x)
                    if max(xl) >= 2:
                        print('Yes')
                    else:
                        print('No')
            elif S[D-1] == '#':
                x = 0
                xl = [0]
                for i in range(B-1,D-2):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                        if i == D-3:
                            xl.append(x)
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('Yes')
                else:
                    print('No')
            else:
                x = 0
                xl = [0]
                for i in range(B-1,D-1):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                        if x == D-2:
                            xl.append(x)
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('Yes')
                else:
                    print('No')
else:
    cnt = 0
    cntl = [0]
    for i in range(A+1,C):
        if (S[i] == '#') & (S[i+1] == '#'):
            cnt += 1
            if i == C-1:
                cntl.append(cnt)
        elif (S[i] == '#') & (S[i+1] == '.'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) >= 1:
        print('No')
    else:
        if (S[B+1] == '.')&(S[B-1] == '.'):
                print('Yes')
        else:
            x = 0
            xl = [0]
            for i in range(B+1,D-1):
                if (S[i] == '.') & (S[i+1] == '.'):
                    x += 1
                    if x == D-2:
                        xl.append(x)
                elif (S[i] == '.') & (S[i+1] == '#'):
                    xl.append(x)
            if max(xl) >= 2:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding; utf 8 -*-
# KenKen race
# 2019. 6/2

import sys


def jump_right(S, current, goal):
    for i in range(current, goal - 1):
        if (S[i+1] == '#' and S[i+2] == '#'):
            return False
    return True



if __name__ == '__main__':
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    S.insert(0, "")

    print(S)

    is_hunuke = jump_right(S, B, D)
    if not is_hunuke:
        print("No")
        sys.exit()

    if is_hunuke:
        S[D] = '#'

    is_sunuke = jump_right(S, A, C)
    if not is_sunuke:
        print("No")
        sys.exit()

    if is_sunuke:
        print("Yes")

Submission status: Wrong Answer

Solution code:
N,a,b,c,d = map(int,input().split())
S = input()
a -= 1
b -= 1
c -= 1
d -= 1

"""
Sa = "."
for i in range(a+1,len(S)) :
    Sa += S[i]
    if S[-2:] == "##" :
        break
for i in range(a-1,-1,-1) :
    Sa += S[i]
    if S[:2] == "##" :
        break

Sb = ""
for i in range(b+1,len(S)) :
    Sb += S[i]
    if S[-2:] == "##" :
        break
for i in range(b-1,-1,-1) :
    Sb += S[i]
    if S[:2] == "##" :
        break
"""
if S[a:(c+1)].count("##") == 0 :
    flg1 = 1
else :
    flg1 = 0

if S[b:(d+1)].count("##") == 0 :
    flg2 = 1
else :
    flg2 = 0

if c < d :
    flg3 = 1
else :
    S = S[:c] + "#" + S[c+1:]
    if (S.count("...") >= 1) and (S[b:].count("##") == 0) :
        flg3 = 1
    else :
        flg3 = 0
    
if flg1*flg2*flg3 :
    print("Yes")
else :
    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
try:
    S.index('##')
    print('No')
except:
    try:
        S.index('...')
        print('Yes')
    except:
        if C > D:
            if S[D-2] == '#' or S[D] == '#':
                print('No')
            else:
                print('Yes')
        else:
            print('Yes')

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-2):

        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:

    for i in range(a,d-1):

        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 = map(lambda x : int(x) - 1, input().split())
S = input()

def scan_map(start, end):
  for i in range(start, end-1):
    if S[i] == "#" and S[i+1] == "#":
      return False
  return True

def scan_map2(start, end):
  A_goal = False
  for i in range(start, end-1):
    if S[i] == "#" and S[i+1] == "#":
      return False
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
      A_goal = True

  if S[end-1] == "." and S[end] == "." and S[end+1] == ".":
    A_goal = True
  return A_goal

if C < D:
  A_goal = scan_map(A, C)
  B_goal = scan_map(B, D)
  if A_goal and B_goal:
    print("Yes")
  else:
    print("No")
else:
  B_goal = scan_map2(B, D)
  A_goal = scan_map(A, C)
  if A_goal and B_goal:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = [ s for s in input()]
a = a-1
b = b-1
s[a] = "a"
s[b] = "b"

result = True
cnt = 0

if c > d and a < b:
    while True:
        if b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
            s[b+1] = "b"
            s[b] = "."
            b += 1
        elif b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
            s[b+2] = "b"
            s[b] = "."
            b += 2
        else:
            cnt = 1
        if b+1 >= n:
            resut = False
            break
        elif s[b-1] == "." and s[b+1] == ".":
            break
        if cnt == 1:
            result = False
            break
    while a < b:
        if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
            s[a+2] = "a"
            s[a] = "."
            a += 2
        elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
            s[a+1] = "a"
            s[a] = "."
            a += 1
        else:
            reult = False
            break
if not result:
    print("NO")
else:
    while True:
        if a != c-1:
            if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
                s[a+2] = "a"
                s[a] = "."
                a += 2
            elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
                s[a+1] = "a"
                s[a] = "."
                a += 1
            else:
                cnt += 1
        if b != d-1:
            if b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
                s[b+2] = "b"
                s[b] = "."
                b += 2
            elif b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
                s[b+1] = "b"
                s[b] = "."
                b += 1
            else:
                cnt += 1
        if cnt == 2:
            result = False
            break
        if a == c-1 and b == d-1:
            break
if result:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
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'
    i = a
    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 False
    return True
def solve():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    S = input() + "##"
    if "##" in S[a + 1:max(c, d)]:
        return False
    if c < d:
        return True
    else:
        return dc(n, a, b, c, d, S)
    return True
print("Yes" if solve() else "No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

[N, A, B, C, D] = [int(i) for i in input().split()]

S = input()

# '#'が2連続あれば移動不可能
S_split = S.split('.')

max_length = 0
for s in S_split:
    if len(s) > max_length:
        max_length = len(s)

if max_length >= 2:
    print('No')
    sys.exit()

# ここまでくればBは必ず目的地に到着可能

# もしC<DだったらAも必ず到着可能
if C < D:
    print('Yes')
    sys.exit()

# もしC>Dだったら、Dの手前が'#'もしくはDの奥が'#'の場合はAはほぼ到達不可能
if S[D-2] == '#' or S[D] == '#':
    # もしS[B-1]からS[D-1]の間に'...'があれば、もしくは[A, B, .]であればAは到達可能
    if '...' in S[B-2:D]:
        print('Yes')
        sys.exit()
    elif A + 1 == B and S[B] == '.':
        print('Yes')
        sys.exit()
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:

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

S = input()

def AA(mojiretu):
    if '##' in mojiretu:
     print("No")
    else:
     print("Yes")

Scp = S
if C < D:
      Scp = Scp[:D-1]+"#" + Scp[D:]
      AA(Scp[:D])
      
else:
    if "..." in Scp[B-2:D]:
      AA(Scp[:C])
    else:
      Scp = Scp[:D-1]+"#" + Scp[D:]
      AA(Scp[:C])

Submission status: Wrong Answer

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

def not_double_stone(way):
    already=False
    for i in way:
        if i=="#" and already:
            return False
        elif i=="#":
            already=True
        else:
            already=False
    return True

def can_over(way):
    count=0
    for i in way:
        if i==".":
            count+=1
        else:
            count=0
        if count==3:
            return True
    return False

if c<d:
    if not_double_stone(way[b-1:d]) and not_double_stone(way[a-1:c]):
        answer='Yes'
    else:
        answer='No'
else:
    if can_over(way[a-1:c]):
        if not_double_stone(way[a-1:c]):
            answer='Yes'
        else:
            answer='No'
    else:
        if not_double_stone(way[a-1:c]) and way[d-2]!="#" and way[d]!="#":
            answer='Yes'
        else:
            answer='No'

print(answer)

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = [int(x) for x in input().split(" ")]
S = str(input())

Sn = list()
for i in S:
    if(i == "."):
        Sn.append(0)
    else:
        Sn.append(1)
        

front = b-1
back = a-1
tof = d-1
tob = c-1

isCan = True
isHide = False

for i in range(front,tof-2):
    if(Sn[i+1] == 1 and Sn[i+2]==1):
        isCan = False
        break
        
    if(Sn[i] == 0 and Sn[i-1] == 0 and Sn[i+1] == 0):
        isHide = True
        
if(isCan == True and isHide == False):
    Sn[tof] = 1
    
for j in range(back,tob-2):
    if(Sn[j+1] == 1 and Sn[j+2] == 1):
        isCan = False
        break
        
if(isCan == False):
    isCan = True
    Sn[tof] = 0
    Sn[front] = 1
    for j in range(back,tob-2):
        if(Sn[j+1] == 1 and Sn[j+2] == 1):
            isCan = False
            break

    
        
if(isCan == True):
    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)-1):
	if S[i]==S[i+1]=="#":
		print('No')
		sys.exit()
	if B-1 <= i < max(C,D)-3 and S[i]==S[i+1]==S[i+2]==".":
		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()
for i in range(a, c - 2):
    if s[i] == "#" and s[i + 1] == "#":
        print("No")
        exit()
for i in range(b, d - 2):
    if s[i] == "#" and s[i + 1] == "#":
        print("No")
        exit()
if c > d:
    f = s[b - 3:].find("...")
    if f == -1:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = (int(i) for i in input().split())  
s = str(input())
s = s[a-1:]
n=len(s)

m = max([c, d])
if n>m:
    n = m
    s = s[:n]
    
if '##' in s:
    print('No')
else:
    if c>d:
        if '...' in s[:d]:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
N, A, B, C, D = map(int, input().split())
S = [i for i in input()]
action = [1,2,1,2]
W = len(S)
judge = [False, False]

def dfs(x, y, field, tmp):
    if C-1 == x and D-1 == y:
        return True
    for idx, nx in enumerate(action):
        if idx <= 1:
            nx += x
            if nx < W:
                if nx == y:
                    continue
                elif field[nx] == "#":
                    continue
                tmp = field[nx]
                field[nx] = "#"
                field[x] = tmp
                return dfs(nx, y, field, tmp)
        else:
            nx += y
            if nx < W:
                if field[nx] == "#":
                    continue
                elif nx == x:
                    continue
                field[nx] = "#"
                field[y] = tmp
                return dfs(x, nx, field, tmp)
    return False


if dfs(A-1,B-1,S, "."):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def give(list):
    i=0
    count=0
    count1=0
    while i<len(list)-2:
        if list[i]=='A':
            count1+=1
            if list[i]=='A' and list[i+1]=='B' and list[i+2]=='C':
                list[i]='B'
                list[i+1]='C'
                list[i+2]='A'
                i+=2
                count+=count1
                count1=0
            else:
                i+=1
        else:
            count1=0
            i+=1
    return count
s=list(input())
print(give(s))

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
right = max(C,D)
r = min(C,D)-1

if '##' in S[A-1:C] or '##' in S[B-1:D]:
  print('No')
else:
  if C < D:
  	print('Yes')
  else:
    if '...' in S[B-1:right]:
      print('Yes')
    else:
      #print(S[A-1:right])
      if len(S[A-1:right])<=6:
        print('Yes')
      elif S[B-2]=='.' and S[B]=='.':
        print('Yes')
      else:
        print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding; utf 8 -*-
# KenKen race
# 2019. 6/2

import sys


def jump_right(S, current, goal):
    for i in range(current, goal - 1):
        if (S[i+1] == '#' and S[i+2] == '#'):
            return False
    return True



if __name__ == '__main__':
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    S.insert(0, "")

    print(S)

    is_hunuke = jump_right(S, B, D)
    if not is_hunuke:
        print("no")
        sys.exit()

    if is_hunuke:
        S[D] = '#'

    is_sunuke = jump_right(S, A, C)
    if not is_sunuke:
        print("no")
        sys.exit()

    if is_sunuke:
        print("yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
flag=0
span=0
buf=-5
if(c<d):
    for i in range(a-1,d):
        if(s[i]=='#' and s[i+1]=='#'):
            flag=1
            break
else:
    for i in range(a-1,c):
        if(s[i]=='#' and s[i+1]=='#'):
            flag=1
            break
        elif s[i]=='#' :
            buf=max([span,buf])
            span=0
        elif b-2<i<d-1:
            span+=1
    if buf<=2:
        flag=1
        #print(buf)
print('No' if flag==1 else 'Yes')

Submission status: Wrong Answer

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 b < c < d 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: Wrong Answer

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

for i in range(max(C, D)):
    if S[i:i+2] == "##":
        print("No")
        quit()

if C > D and C - D == 1:
    if S[D-2:D] == "#.":
        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 - 2):
    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(c - a - 2):
            if (s[a + j] == "." and s[a + j + 1] == "." and s[a + j + 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())
a-=1
b-=1
c-=1
d-=1

temp=str(input())
maxim=max(a,b)
if temp[maxim:].count("...")!=0 or temp[maxim+1]==temp[maxim+2]==".":
    flag=1
else:
    flag=0
    
s=list(temp)
s[a]="A"
s[b]="B"
s[c]="C"
s[d]="D"

ans=1

for i in range(n-1):
    if s[i]==s[i]=="#":
        ans=0

if a<b and c<d:
    ans=1
elif a<b and c>d:
    if flag==1:
        ans=1
    elif s[d-1]=="#" or s[d+1]=="#":
        ans=0
    else:
        ans=1
elif a>b and c>d:
        ans=1
elif a>b and c<d:
    if flag==1:
        ans=1
    elif s[c-1]=="#" or s[c+1]=="#":
        ans=0
    else:
        ans=1
                
if ans==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
N, A, B, C, D = map(int, input().split())
S = [i for i in input()]
action = [1,2,1,2]
W = len(S)
judge = [False, False]

def dfs(x, y, field, tmp):
    if C-1 == x and D-1 == y:
        return True
    for idx, nx in enumerate(action):
        if idx <= 1:
            nx += x
            if nx < W:
                if nx == y:
                    continue
                elif field[nx] == "#":
                    continue
                tmp = field[nx]
                field[nx] = "#"
                field[x] = tmp
                return dfs(nx, y, field, tmp)
        else:
            nx += y
            if nx < W:
                if field[nx] == "#":
                    continue
                elif nx == x:
                    continue
                field[nx] = "#"
                field[y] = tmp
                return dfs(x, nx, field, tmp)
    return False


print(dfs(A-1,B-1,S, "."))

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int, input().split(" ")))


def count3(S, l, r):
    for i in range(l, r+1):
        if S[i:i+3] == "...":
            return True
    return False


def is_twocontinusblock(S, l, r):
    for i in range(l, r-1):
        if S[i:i+2] == "##":
            return True
    return False


N, A, B, C, D = spaceinput()
S = input()


def solve():
    if is_twocontinusblock(S, A, C-1) or is_twocontinusblock(S, B, D-1):
        return False
    if D < C:
        if count3(S, B-1, D-1):
            return True
        else:
            return False

    return True


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

Submission status: Wrong Answer

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: Wrong Answer

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

a_to_c = s[a-1:c]
b_to_d = s[b-1:d]
# print(a_to_c)
# print(b_to_d)
if '##' in a_to_c or '##' in b_to_d:
    print('No')
    exit()

if not ((a > b and c > d) or (a < b and c < d)):
    if '...' not in max(a_to_c, b_to_d, key=len):
        print('No')
        exit()
# print(max(a_to_c, b_to_d, key=len))
print('Yes')

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 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:
n, a, b, c, d = map(int,input().split())
s = input()

if '##' in s:
    print('No')
elif c < d:
    print('Yes')
else:
    i = 0
    while True:
        i = s.find('...', i + 1)
        if b <= i < d:
            print('Yes')
            break
        elif i >= d:
            print('No')
            break
        else:
            pass

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, a, b, c, d = MI()
s = [s for s in input()]
aki = []
for i in range(1, len(s)):
    if s[i] == '#' and s[i-1] == '#':
        if a-1 < i < c-1 or b-1 < i < d-1:
            print('No')
            exit()

if c < d:
    print('Yes')
else:
    for i in range(2, len(s)):
        if s[i] == '.' and s[i-1] == '.' and s[i-2] == '.':
            aki.append(i)
    if s[d-2] == '#':
        for num in aki:
            if b-1 <= num < d-2:
                print('Yes')
                exit()
    elif s[d] == '#':
        for num in aki:
            if b-1 <= num < d:
                print('Yes')
                exit()
    elif s[d-2] == '.' and s[d] == '.':
        print('Yes')
        exit()
    print('No')