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:
def check_double_block(start, end, S):
    for i in range(start, end-1):
        if S[i] == "#" and S[i+1] == "#":
            return False
    return True

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

    if C < D:
        if not check_double_block(A, C, S) or not check_double_block(B, D, S):
            print("No")
        else:
            print("Yes")
    else:
        for i in range(N-2):
            if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
                print("Yes")
                exit()
        print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    flag = None
    if C < D:
        for s1, s2 in zip(S[:-1], S[1:]):
            if s1 == "#" and s2 == "#":
                flag = False
                break
            flag = True
    else:
        for i in range(N-2):
            if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
                flag = True
                break
            flag = False

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AGC034 A-Kenken Race

import sys

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

if "##" in S[A:C+1] or "##" in S[B:D+1]:
    print("No")
    sys.exit()
    
if C < D:
    print("Yes")
else:
    if "..." in S[B:D+1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# AGC034 A-Kenken Race

import sys

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

if "##" in S:
    print("No")
    sys.exit()
    
if C < D:
    print("Yes")
else:
    if "..." in S[B:D+1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=[True if i=='.' else False for i in list(input())]
if c<d:
    for i in range(n-1):
        print('Yes')
        exit()
else:
    for i in range(n-2):
        if all(s[i:i+3]):
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s)-1 for s in input().split() if s]
    S = input()
    N += 1
    
    flag = True
    for i in range(A+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if flag and C > D:
        flag = False
        for i in range(B-1, min(C,D)-1):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(A+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if flag and C > D:
        flag = False
        for i in range(B-1, min(C,D)-1):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(A+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if flag and C > D:
        flag = False
        for i in range(B-1, min(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')
    
solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(A+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if flag and C > D:
        flag = False
        for i in range(B+1, min(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')
    
solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(A+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if C > D:
        flag = False
        for i in range(B+1, min(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(B+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if C > D:
        flag = False
        for i in range(B+1, min(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(B+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if C > D:
        flag = False
        for i in range(B+1, max(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('Yes' if flag else 'No')

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N,A,B,C,D = [int(s) for s in input().split() if s]
    S = input()
    
    flag = True
    for i in range(B+1, max(C,D)-1):
        if S[i] == '#' and S[i+1] == '#':
            flag = False
    
    if C > D:
        flag = False
        for i in range(B+1, max(C,D)-2):
            if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
                flag = True
    
    print('yes' if flag else 'no')

solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
p=1
for i in range(n-1):
    if s[i]==s[i+1]=='#':
        p=0
if d!=n:
    if s[d]=='#' and c>d:
        p=0
if p==1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b):max(c,d)-1]:
  print("No")
  exit()
if d > c:
  if "..." in s[b-2:d+1]:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if c > d:
  if "..." in s[b-1:d]:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if d > c:
  if "..." in s[b-1:d]:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if (a < b and c > d) or (a > b and c < d):
  if "..." in s[max(a,b)-1:min(c,d)]:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if (a < b and c > d) or (a > b and c < d):
  if "..." in s[min(a,b)-1:max(c,d)]:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if (a < b and c > d) or (a > b and c < d):
  if "..." in s[min(a,b)-1:max(c,d)]:
    print("Yes")
  else:
    print("No")
else:
  if ".." in s[max(a,b)-1:min(c,d)]:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = str(input())
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
  exit()
if (a < b and c > d) or (a > b and c < d):
  if "..." in s[min(a,b)-1:max(c,d)]:
    print("Yes")
  else:
    print("No")
else:
  if ".." in s[min(a,b)-1:max(c,d)]:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int, input().split())
s = input()
S = [0 if x is '.' else 0 for x in s]
ans ='Yes'
if d >= c:
  for i in range(a,c):
    if s[i-1] == 1 and s[i] == 1:
      ans = 'No'
  for i in range(b,d):
    if s[i-1] == 1 and s[i] == 1:
      ans = 'No'
else:
  for i in range(b,d):
    if s[i-1] == 1 and s[i] == 1:
      ans = 'No'
  for i in range(a,c):
    if s[i-1] == 1 and s[i] == 1:
      ans = 'No'
  if s[d-2] == 1:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

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


import sys
tmp = input().split()
n=int(tmp[0])
a=int(tmp[1])
b=int(tmp[2])
c=int(tmp[3])
d=int(tmp[4])

tmp = input()

#print("{}{}{}{}{}".format(n,a,b,c,d))
#print(tmp)

#追い越す必要
if(c > d):
	flg=0
	for i in range(b,d-2):
		if(tmp[i-1]==".")and(tmp[i]==".")and(tmp[i+1]=="."):
			flg=1
	if(flg!=1):
		print("No")
		sys.exit()

for i in range(a,d-1):
	if(tmp[i]=="#")and(tmp[i+1]=="#"):
		print("No")
		sys.exit()
print("Yes")

#print(hoge)
#hoge.sort()
#n=len(hoge)
#print(hoge)

Submission status: Wrong Answer

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


import sys
tmp = input().split()
n=int(tmp[0])
a=int(tmp[1])
b=int(tmp[2])
c=int(tmp[3])
d=int(tmp[4])

tmp = input()

#print("{}{}{}{}{}".format(n,a,b,c,d))
#print(tmp)

#追い越す必要
if(c > d):
	flg=0
	for i in range(b,d-2):
		if(tmp[i]==".")and(tmp[i+1]==".")and(tmp[i+2]=="."):
			flg=1
	if(flg!=1):
		print("No")
		sys.exit()

for i in range(a,d-1):
	if(tmp[i]=="#")and(tmp[i+1]=="#"):
		print("No")
		sys.exit()
print("Yes")

#print(hoge)
#hoge.sort()
#n=len(hoge)
#print(hoge)

Submission status: Wrong Answer

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

def check(l, r):
    for i in range(l, r):
        if s[i] == '#' and s[i+1] == '#':
            return False

    return True

if c < d:
    if check(a, c) and check(b, d):
        print("Yes")
    else:
        print("No")
else: # c > d
    space = False

    for i in range(b+1, d+1):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            space = True
            break

    if space and check(a, c) and check(b, d):
        print("Yes")
    else:
        print("No")
        # s = s[:d] + '#' + s[d+1:]
        # if check(a, c):
        #     print("Yes")
        # else:
        #     print("No")

Submission status: Wrong Answer

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

def check(l, r):
    for i in range(l, r):
        if s[i] == '#' and s[i+1] == '#':
            return False

    return True

if c < d:
    if check(a, c) and check(b, d):
        print("Yes")
    else:
        print("No")
else: # c > d
    space = False
    l = b
    while s[l-1] == '.':
        l -= 1

    for i in range(l+2, d+1):
        if s[i] == '.' and s[i-1] == '.' and s[i-2] == '.':
            space = True
            break

    if space and check(a, c) and check(b, d):
        print("Yes")
    else:
        s = s[:d] + '#' + s[d+1:]
        if check(a, c):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

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

def check(l, r):
    for i in range(l, r):
        if s[i] == '#' and s[i+1] == '#':
            return False

    return True

if c < d:
    if check(a, c) and check(b, d):
        print("Yes")
    else:
        print("No")
else: # c > d
    space = False
    l = b
    while s[l-1] == '.':
        l -= 1

    for i in range(l+2, d+1):
        if s[i] == '.' and s[i-1] == '.' and s[i-2] == '.':
            space = True
            break

    if space and check(a, c) and check(b, d):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(100000)
input = sys.stdin.readline

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

def able(m, n, S):
    for i in range(m+1, n):
        if S[i] == '#' and S[i+1] == '#':
            return False
    return True

def able2(m, n, S):
    if not able(m, n, S):
        return False
    for i in range(m, n):
        if S[i] == '.' and S[i-1] == '.' and S[i+1] == '.':
            return True
    return False

if C>D:
    if able(A-1, C-1, S) and able2(B-1, D-1, S):
        print("Yes")
    else:
        print("No")
else:
    if able(A-1, C-1, S) and able(B-1, D-1, S):
        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())

iwa2 = []
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] == "#":
#         iwa2.append(1)
        cnt += 1
#     else:
#         iwa2.append(0)
    iwa2.append(cnt)
    
#長さ揃える
iwa2.append(cnt)        
        
def iwa2_check(s,g):
    if iwa2[s] < iwa2[g]:
        return True
    return False

# aki3は複数あったら、そのどれかに二人でたどり着ければ良い
aki3 = [0]
cnt = 0
for i in range(len(S)-1):
    if S[i-1] == S[i] == S[i+1] == ".":
        cnt += 1
    aki3.append(cnt)
aki3.append(cnt)

def aki3_check(B,CORD):
    # AさんがBさんと出会える（iwa2ない）
#     if not iwa2(A,B):
#         return False
    # Bさんがaki3にたどり着ける（最寄りの2つを見るだけで良い）
    # oBoのような状態でもOKなので-1
    if aki3[B-1] < aki3[CORD]:
        return True
    return False

# 順序が入れ替わらないとき
def solve():
    if iwa2_check(A,C) or iwa2_check(B,D):
#         print("1")
        return False
    if C<D:
#         print("2")
        return True
    else:
        if aki3_check(B, D):
#             print("3")
            return True
        else:
#             print("4")
            return False

if solve():
    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())

iwa2 = []
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] == "#":
#         iwa2.append(1)
        cnt += 1
#     else:
#         iwa2.append(0)
    iwa2.append(cnt)
    
#長さ揃える
iwa2.append(cnt)        
        
def iwa2_check(s,g):
    if iwa2[s] < iwa2[g]:
        return True
    return False

# aki3は複数あったら、そのどれかに二人でたどり着ければ良い
aki3 = [0]
cnt = 0
for i in range(len(S)-1):
    if S[i-1] == S[i] == S[i+1] == ".":
        cnt += 1
    aki3.append(cnt)
aki3.append(cnt)

def aki3_check(B,CORD):
    # AさんがBさんと出会える（iwa2ない）
#     if not iwa2(A,B):
#         return False
    # Bさんがaki3にたどり着ける（最寄りの2つを見るだけで良い）
    # oBoのような状態でもOKなので-1
    if aki3[B-1] < aki3[CORD+1]:
        return True
    return False

# 順序が入れ替わらないとき
def solve():
    if iwa2_check(A,C) or iwa2_check(B,D):
#         print("1")
        return False
    if C<D:
#         print("2")
        return True
    else:
        if aki3_check(B, D):
#             print("3")
            return True
        else:
#             print("4")
            return False

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

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c+1]:
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c]:
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c]:
      print('No')
    elif (not '...' in course[b-2:c-1]) and course[c-2]=='#':
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c+1]:
      print('No')
    elif (not '...' in course[b-2:c-1]) and course[c-2]=='#':
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c+1]:
      print('No')
    elif (not '...' in course[b-2:c]) and course[c-2]=='#':
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:c+1]:
      print('No')
    elif (not '...' in course[b-2:c]) and course[c-1]=='#':
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a:d]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-1:c+1]:
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course:
  print('No')

else:
  if c > d:
    if not '...' in course[b-1:c+1]:
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B+1,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = -1
        prevprevS = -1

        for i in range(B-1,D+1):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                #print(i,prevS,prevprevS)
                if i - prevS == 1 and prevS - prevprevS ==1:
                    f = True
                prevprevS = prevS
                prevS = i
                
                
                
        # if S[D-1] == '.':
        #     f = True
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B+1,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = B
        prevprevS = B

        for i in range(B+1,D+1):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                #print(i,prevS,prevprevS)
                if i - prevS == 1 and prevS - prevprevS ==1:
                    f = True
                prevprevS = prevS
                prevS = i
                
                
                
        # if S[D-1] == '.':
        #     f = True
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B+1,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = -1

        for i in range(B+1,D):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                if i - prevS == 1:
                    f = True
                prevS = i
        if S[D-1] == '.':
            f = True
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C+1,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        prev = A-1
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = B

        for i in range(B+1,D):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                if i - prevS == 1:
                    f = True
                prevS = i
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C+1,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    prev = -1
    if C > D:  #AがBを追い越す時
        prev = A-1
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか

        prevS = -1

        for i in range(B+1,D):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                if i - prevS == 1:
                    f = True
                prevS = i
                
        if not f:
            print('No')
            return
        
        for i in range(D+1,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
def main():
    N,A,B,C,D = list(map(int,input().split()))
    S = input()
    A -=1
    B -=1
    C -=1
    D -=1
    #C>Dのとき:AがBを追い越す
    prev = -1
    if C < D:  #AがBを追い越さない場合
        
        for i in range(A+1,min(C+1,B)):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        for i in range(B,D):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i

        
        print('Yes')
    
    if C > D:  #AがBを追い越す時
        prev = A-1
        for i in range(A+1,B):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        f = False  #追い越せるか
        prev = B-1
        prevS = B-1

        for i in range(B+1,D):
            if S[i] == '#' :
                if i - prev == 1:
                    print('No')
                    return
                prev = i
            else:
                if i - prevS == 1:
                    f = True
                prevS = i
                
        if not f:
            print('No')
            return
        
        for i in range(D,C):
            if S[i] == '#' :
                if prev == i-1:
                    print('No')
                    return
                else:
                    prev = i
        print('Yes')
if __name__ == '__main__':
    main()