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 math
import numpy as np


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


def main():
    N, A, B, C, D = inputs()
    S = input()
    maxDst = max(C, D)
    courseA = S[A:C]
    courseB = S[B:D]
    cnt = 0
    ans = []
    for i in courseB:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    cnt = 0
    for i in courseA:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    if maxDst == C:
        cnt = 0
        for i in S[B:D+1]:
            if i == '.':
                cnt += 1
            else:
                cnt = 0
            if cnt == 3:
                ans.append(True)
                break
        else:
            ans.append(False)

    if all(ans):
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
T = S
if "##" in S[B:D-1] or "##" in S[A:C-1]:
    ans = False
else:
    if "..." in S[B:D-1]:
        ans = True
    elif S[B-2] == "." and S[B] == "." and "..." in S[A:C-1]:
        ans = True
    else:
        #B先動かす
        S = S[:D-1] + "#" + S[D:]
        if "##" in S[A:C]:
            ans = False
        else:
            ans = True
    #A先
    if ans == False:
        S = T
        if S[B-2] == "#" or S[B] == "#":
            ans = False
        else:
            S = S[:C-1] + "#" + S[C:]
            if "##" in S[B:D]:
                ans = False
            else:
                ans = True

if ans:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def dfs(x, y, field):
    if C-1 == x and D-1 == y:
        return True
    for idx, n in enumerate([1,2,1,2]):
        if idx <= 1:
            n += x
            if n < W:
                if n == y:
                    continue
                elif field[n] == "#":
                    continue
                return dfs(n, y, field)
        else:
            n += y
            if n < W:
                if n == x:
                    continue
                elif field[n] == "#":
                    continue
                return dfs(x, n, field)
    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 = input().split(" ")
s = input()
n = int(n)
a = int(a)
b = int(b)
c = int(c)
d = int(d)


if c > d:
    if "##" in s[a-1:c]:
        print("No")
        exit()
    
    if "..." not in s[a-1:c]:
        print("No")
        exit()

if c < d:
    if "##" in s[a-1:c] or "##" in s[b-1:d]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
c1 = [0] * N
c2 = [0] * N
cnt1 = 0
cnt2 = 0
for i in range(N):
    if S[i] == '.':
        c2[i] = cnt2
        cnt2 = 0
        cnt1 += 1
    else:
        c1[i] = cnt1
        cnt1 = 0
        cnt2 += 1
        
if cnt1 >= 1:
    c1[-1] = cnt1
if cnt2 >= 1:
    c2[-1] = cnt2
    
index2 = []
index1 = []
for i in range(N):
    if c2[i] >= 2:
        index2.append(i)
    if c1[i] >= 3:
        index1.append(i)

flag = True
for i in index2:
    if A <= i - c2[i] + 1 < C or B <= i - c2[i] + 1 < D:
        flag = False
    if C <= i < A or D <= i < B:
        flag = False

if len(index1) == 0:
    if A <= B and C >= D:
        flag = False
    if A >= B and C <= D:
        flag = False

if S[A-1] == '#' or S[B-1] == '#' or S[C-1] == '#' or S[D-1] == '#':
    flag = False

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

Submission status: Wrong Answer

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

for i in range(1, N):
	if S[i] == '#' and S[i-1] == '#':
		print('No')
		sys.exit()

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

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

if S[B+1] == '.' and S[B+2] == '.':
	print('Yes')
	sys.exit()
	
if D == B + 2:
	print('Yes')
	sys.exit()

for i in range(B, D-1):
	if S[i] == '#':
		if S[i+1] == '.' and S[i+2] == '.' and S[i+3] == '.':
			print('Yes')
			sys.exit()

print('No')
sys.exit()

Submission status: Wrong Answer

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

        else:
            print('Yes')
            v+=1
            break
    if c>d:
        if i>c and s[i]=='#' and s[i+1]=='#':
            v+=1
            print('No')
            break
        elif i>b and i<d and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.':
            v+=1
            print('Yes')
            break
if  v==0:
    print('No')

Submission status: Wrong Answer

Solution code:
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1

for i in range(firstsunuke, lastsunuke-1):
    if s[i] == '#' and s[i+1] == '#':
        tobenaiflag += 1
        break
for k in range(firstfunuke, lastfunuke-1):
    if s[k] == '#' and s[k+1] == '#':
        tobenaiflag += 1
        break
# if lastfunuke < lastsunuke:
#    for j in range(max(firstsunuke, firstfunuke)-1, lastfunuke-1):
#        if s[j] == '.' and s[j+1] == '.' and s[j+2] == '.':
#            nukaseruflag += 1
#            break
# else:
#    nukaseruflag += 1
nukaseruflag += 1
if tobenaiflag == 0 and nukaseruflag == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = [int(i) for i in input().split()]
s = input()
t = s.split("#")
cnt = -1
if(s.count('##') > 0):
    frag = 0
elif(c<d):
    frag = 1
else:
    frag = 0
    frag1 = 0
    frag2 = 0
    frag3 = 0
    for i in range(len(t)):
        cnt += len(t[i])+1
    for i in range(1, len(t)):
        if(t[i].count('.') >= 3):
            frag1 = 1
        if(frag1 == 1):
            break
    cnt -= t[len(t)-1].count('.')
    if(s[b] == '.' or frag1 == 1):
        frag2 = 1
    if(s[d-2] == '.' or frag1 == 1):
        frag3 = 1
    if(frag1 == 1 and frag2 == 1 and frag3 == 1):
        frag = 1
if(frag == 1):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

if c<d:
    m=d
else:
    m=c

for i in range(a, m-3):
        if s[i] == '#' and s[i+1] == '#':
            ans=0

if c<d:
    if s[c-2] =='#' or s[c] == '#':
        ans=0

flag=0
if d<c:
    for i in range(b-2, d-2):
        if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
            flag=1
    if flag == 0:
        ans=0
        
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not(c-d==2 and '...' in s[:d-1]):
            flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = [int(i) - 1 for i in input().strip().split(' ')]
N += 1
S = [c for c in input().strip()]


def get(a, b):
  s = S[:]
  s[a] = 'A'
  s[b] = 'B'

  return s


def is_reachable(s, a, b):
  i = a
  while i < C:
    if i + 1 <= C and s[i + 1] == '.':
      i = i + 1
    elif i + 2 <= C and s[i + 2] == '.':
      i = i + 2
    else:
      break
  is_a = i == C

  i = b
  while i < D:
    if i + 1 <= D and s[i + 1] == '.':
      i = i + 1
    elif i + 2 <= D and s[i + 2] == '.':
      i = i + 2
    else:
      break
  is_b = i == D

  return is_a, is_b


def move(s, i, dest):
  i = i + 1

  if i == dest:
    return -1

  while i <= dest:
    if i == dest:
      return dest

    if i + 2 < N:
      if s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.':
        return i + 1

    i = i + 1

  return -1


def main():
  a = A
  b = B

  for _ in range(1000):
    s = get(a, b)
    is_a, is_b = is_reachable(s, a, b)
    #print(_, (is_a, is_b), s)
    if is_a and is_b:
      return True
    elif not is_a:
      b = move(s, b, D)
      if b < 0:
        return False
    elif not is_b:
      a = move(s, a, C)
      if a < 0:
        return False
    else:
      return False


print('Yes' if main() else '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)
minim=min(a,b)
if temp[maxim:].count("...")!=0 or temp[maxim+1]==temp[maxim+2]=="." or temp[maxim+1]==temp[maxim-1]==".":
    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(minim,n-1):
    if s[i]==s[i+1]=="#":
        ans=0
        

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[B-1:D].count('...'))
            if(sf == 0):
                print(NO)
            ######### あとはここだけ考える ####
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS[D-1] = 'd'
                tS = ''.join(tS)
                if(tS[B-1:D].count('..b#d') == 1):
                    print(NO)
                else:
                    print(YES)
            #################################
            elif(sf >= 2):
                print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Wrong Answer

Solution code:
def count_renzoku_char(s, char):
    max_len = 0
    current_len = 0
    for c in s:
        if c == char:
            current_len += 1
        else:
            if max_len < current_len:
                max_len = current_len
            current_len = 0

    return max_len

if __name__ == "__main__":
    N, A, B, C, D = [int(x) for x in input().split()]
    S = input()

    def main():
        global A, B
        if C < D:
            raw_sharp = count_renzoku_char(S[B+1: D], '#')
            if raw_sharp >= 2:
                print('No')
                return

            raw_sharp = count_renzoku_char(S[A+1: C], '#')
            if raw_sharp >= 2:
                print('No')
                return
            else:
                print('Yes')
                return
        else:
            is_reached = False
            while(True):
                if A + 1 == C or A + 2 == C:
                    is_reached = True
                    break
                su2 = S[A+2]
                if su2 == '.':
                    A = A + 2
                    continue
                elif su2 == '#':
                    pass
                elif A + 2 == B:
                    if not (B == D or S[B+1] == '#'):
                        B = B + 1
                        A = A + 2
                        continue
                
                su1 = S[A+1]
                if su1 == '.':
                    A = A + 1
                    continue
                elif su1 == '#':
                    break
                elif A + 1 == B:
                    if not (B == D or S[B+1] == '#'):
                        B = B + 1
                        A = A + 1
                        continue
                    else:
                        break
                
                break
            
            print('Yes' if is_reached else 'No')

    main()

Submission status: Wrong Answer

Solution code:
n, a_, b_, c_, d_ = map(int, input().split())
s_ = input()

print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def SI(): return input()

N,A,B,C,D=LI()
st=input()

if C < D:
    if st[A:C].find('##') >= 0 or st[B:D].find('##') >= 0:
        print('No')
    else:
        print('Yes')
else:
    # Cの方がおおきいケース 入れ替わる
    if st[A:C].find('##') >= 0:
        print('No')
    else:
        fnd = st.find('...', A-1, D+1)
        if fnd >= 0:
            if fnd+1 == B or fnd+3 == B:
                fnd = st.find('...', fnd+1, D+1)
                if fnd >= 0:
                    if fnd+1 == D or fnd+3 == D:
                        print('No')
                    else:
                        print('Yes')
                else:
                    print('No')
            else:
                print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

def main():
	N, A, B, C, D = map(int, input().split(" "))
	#N = int(input())
	S = input()
	S = list(S)
	S = S[:-1]

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

	if C < D:
		S = S[A:D+1]
	else:
		S = S[A:C+1]

	iwa = []
	kara = []
	nige = []
	for i, val in enumerate(S):
		if val == "#":
			if len(iwa) > 1 and iwa[-1] == i-1:
				print("No")
				sys.exit()
			iwa.append(i)
		else:
			if len(kara) > 2 and kara[-1] == i-1 and kara[-2] == i-2:
				nige.append(i)
			kara.append(i)
	'''
	for i in range(A+1, C):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()

	for i in range(B+1, D):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()
	'''
	if A < B and B < C and C < D:
		print("Yes")
		sys.exit()
	else:
		for i in nige:
			if B < i and i+2 < D:
				print("Yes")
				sys.exit()
	'''
	elif A < B and B < D and D < C:
		for i in range(A+1, C):
			if i in kara:
				tmp = kara.index(i)
				if C >= i+2 and len(kara)-2 > tmp :
					if (kara[tmp+1] == i+1) and (kara[tmp+2] == i+2):
						print("Yes")
						sys.exit()
		print("No")
		sys.exit()
	'''
	print("No")
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
def judge1(x,y,s):
    count = 0
    slice = s[x:y+1]
    slice2 = [slice[i:i+2] for i in range(0,y-x+1,2)]
    return slice2
def judge2(x,y,s):
    count = 0
    slice = s[x:y+1]
    slice2 = [slice[i:i+3] for i in range(0,y-x+1,3)]
    return slice2

N,A,B,C,D = map(int,input().split())
S = input()
ans = 0
ans2 = 0
if C>D:
    E = judge2(A-1,C,S)
    F = judge1(A-1,C,S)
    for i in range(len(E)):
        if E[i].count(".") == 3:
            ans2 = 1
            break
    for i in range(len(F)):
        if F[i].count("#") == 2:
            ans = 1
            break
    if ans2 == 1 and ans == 0:
        print("Yes")
    else:
        print("No")
else:
    E = judge1(B-1,D,S)
    for i in range(len(E)):
        if E[i].count("#") == 2:
            ans = 0
            break
    if ans == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
li = input()
if c<b:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
elif c<d:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
else:
  li = li[:d+1]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  elif li[b-2] == "." and li[b] == ".":
    print("Yes")
  else:
    li = li[b:]
    if li.find("...") == -1:
      print("No")
    else:
      print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
c1 = [0] * N
c2 = [0] * N
cnt1 = 0
cnt2 = 0
for i in range(N):
    if S[i] == '.':
        c2[i] = cnt2
        cnt2 = 0
        cnt1 += 1
    else:
        c1[i] = cnt1
        cnt1 = 0
        cnt2 += 1
        
if cnt1 >= 1:
    c1[-1] = cnt1
if cnt2 >= 1:
    c2[-1] = cnt2
    
index2 = []
index1 = []
for i in range(N):
    if c2[i] >= 2:
        index2.append(i)
    if c1[i] >= 3:
        index1.append(i)

flag = True
for i in index2:
    if A <= i - c2[i] + 1 <= C or B <= i - c2[i] + 1 <= D:
        flag = False
    if C <= i <= A or D <= i <= B:
        flag = False

if len(index1) == 0:
    if A <= B and C >= D:
        flag = False
    if A >= B and C <= D:
        flag = False

if S[A-1] == '#' or S[B-1] == '#' or S[C-1] == '#' or S[D-1] == '#':
    flag = False

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 22:01:55 2019

@author: hisaki
"""

import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

for i in range(N):
    if i< N-1 and S[i] == '#':
        if S[i+1] == '#':
            print ("No")
            sys.exit()

if A_pos < B_pos and A_goal < B_goal:
    print ("Yes")
    sys.exit()

if B_pos < A_pos and B_goal < A_goal:
    print ("Yes")
    sys.exit()


if A_pos < B_pos and B_goal < A_goal :
    if A_pos >=1 and S[A_pos-1] == '.' and A_pos+1 <= N-1 and S[A_pos+1] == '.':
        print ("Yes")
        sys.exit()
    for i in range(N-3):
        if S[i] == '.' and S[i+1]== '.' and S[i+2] == '.':
            print ("Yes")
            sys.exit()

if B_pos < A_pos and A_goal < B_goal :
    if B_pos >=1 and S[B_pos-1] == '.' and B_pos+1 <= N-1 and S[B_pos+1] == '.':
        print ("Yes")
        sys.exit()
    for i in range(N-3):
        if S[i] == '.' and S[i+1]== '.' and S[i+2] == '.':
            print ("Yes")
            sys.exit()
            
print ("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


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

    flag = False
    S_original = S

    if A < C and C < B and B < D:
        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

    # case1 Cに先にたどり着くパターン
    S = list(S_original)
    S[C] = '#'
    S[B] = '#'

    S = ''.join(S)
    if '##' in S[A+1:C]:
        pass
    elif '##' in S[B+1:D]:
        pass
    else:
        flag = True

    # case2 Dに先にたどり着くパターン
    S = list(S_original)
    S[D] = '#'
    S[A] = '#'

    S = ''.join(S)
    if '##' in S[A+1:C]:
        pass
    elif '##' in S[B+1:D]:
        pass
    else:
        flag = True

    # case 3 途中で追い越すパターン
    S = list(S_original)
    S = ''.join(S)
    if '...' in S[B:C+1]:
        # case 3-1 Cに先にたどり着くパターン
        S = list(S_original)
        S[C] = '#'
        S = ''.join(S)

        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

        # case 3-2 Dに先にたどり着くパターン
        S = list(S_original)
        S[D] = '#'
        S = ''.join(S)

        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

    # case 4 途中で追い越すパターン
    S = list(S_original)

    S = ''.join(S)
    if '...' in S[B:D+1]:
        # case 3-1 Cに先にたどり着くパターン
        S = list(S_original)
        S[C] = '#'
        S = ''.join(S)

        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

        # case 3-2 Dに先にたどり着くパターン
        S = list(S_original)
        S[D] = '#'
        S = ''.join(S)

        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

    if flag == True:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: 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-2:D]:
      print('Yes')
    else:
      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:
N ,A, B, C, D = map(int, input().split())

rock = "#"
S = list()
three_empty = []
two_rocks = []
rock_cnt, empty_cnt = 0, 0

# 通れない２連続岩の場所とABが交差できる３emptyの場所取得
for i, s in enumerate(input().strip(), start=1):
  is_rock = s == rock
  if is_rock:
    if empty_cnt >= 3:
      three_empty.append(i - 1)
    rock_cnt += 1
    empty_cnt = 0
  else:
    if rock_cnt >= 2:
      two_rocks.append(i - 1)
    rock_cnt = 0
    empty_cnt += 1
if rock_cnt >= 2:
  two_rocks.append(i)
if empty_cnt >= 3:
  three_empty.append(i)

flag = True
left = A if A < B else B
right = B if A > B else A
left_rock = left
right_rock = 200001


for i in two_rocks:
  # 目標の間に岩があるか確認
  if A > i > C or B > i > D or A < i < C or B < i < D:
    flag = False
    break
  # 左と右にいる人から一番近い岩の位置
  if right_rock == 200001 and right < i:
    right_rock = i

if not flag:
  # 目標との間に2岩があるとき
  print("No")
elif (A > B and C > D) or (A < B and C < D):
  # 木彫との間に2岩がなく、交差が発生しない場合。
  print("Yes")
elif not three_empty:
  # 交差点となる3emptyがない場合
  print("No")
else:
  # 双方の一番近い岩との間に3emptyがあるかどうか 
  flag = False
  for i in three_empty:
    if left_rock < i < right_rock:
      flag = True
      break
  if flag:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
cb=0
ca=0
cB=0
sb=len(s)-d+1
for i in range(d-b):
    if b==d:
        cB=1
    if sb>=3 and cB==1:
        if b+1!=c and s[b]=="." and s[b+1]==".":
            b+=1
            break
    if b+1>len(s):
        cb=0
        break
    if s[b]==".":
        b+=1
        cb=1
    elif s[b+1]==".":
        b+=2
        cb=1
    else:
        cb=0
        break
for i in range(c-a+1):
    if a==b:
        ca=0
        break
    if a==c:
        break
    if a+1>len(s):
        ca=0
        break
    if s[a]=="." and a+1!=b:
        ca=1
        a+=1
    elif a+1<n and s[a+1]==".":
        ca=1
        a+=2
    else:
        ca=0
        break
if ca*cB==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#AGC34-A

#kenken race

N,A,B,C,D = list(map(int,input().split()))
S = list(input())
S2 = []
max = 0
c = 0
for i in range(N):
    if c == 0 and S[i] == "#":
        c = i
    elif c != 0 and S[i] == "#":
        if max < i - c - 1:
            max = i - c - 1
        c = i
    S2.append(S[i])
A -= 1
B -= 1
a = A
b = B
C -= 1
D -= 1
stack1 = []
stack2 = []
stack3 = []
stack4 = []
flg = 0
ansflg = 0
flg2 = 0
flg3 = 0
flg4 = 0
ansflg2 = 0

#ふぬけ先
while True:
    if B + 1 <= N-1:
        #print(B)
        if B + 2 <= N-1:
            if S[B+1] == "." and S[B+2] == ".":
                B += 2
                stack1.append(B+1)
                #print("a")
            elif S[B+1] == "#" and S[B+2] == ".":
                B += 2
                #print("b")
            elif S[B+1] == "." and S[B+2] == "#":
                B += 1
                #print("c")
            else:
                if len(stack1) == 0:
                    flg = 1
                else:
                    flg = 2
        else:
            if S[B+1] == ".":
                B += 1
            else:
                if len(stack1) == 0:
                    flg = 1
                else:
                    flg = 2
    if B == D:
        S[D] = "#"
        #print(S)
        break
    elif flg:
        ansflg = 1
        #print('No')
        break
    if flg == 2:
        B = stack1.pop()
if not ansflg:
    while True:
        if A + 1 <= N-1:
            if A + 2 <= N-1:
                if S[A+1] == "." and S[A+2] == ".":
                    A += 2
                    stack2.append(A+1)
                    #print("a")
                elif S[A+1] == "#" and S[A+2] == ".":
                    A += 2
                    #print("b")
                elif S[A+1] == "." and S[A+2] == "#":
                    A += 1
                    #print("c")
                else:
                    if len(stack2) == 0:
                        flg2 = 1
                    else:
                        flg2 = 2
            else:
                if S[A+1] == ".":
                    A += 1
                else:
                    if len(stack2) == 0:
                        flg2 = 1
                    else:
                        flg2 = 2
        if A == C:
            #print('Yes')
            break
        elif flg2:
            ansflg = 1
            #print('No')
            break
        if flg2 == 2:
            A = stack2.pop()
#すぬけ先
if D < C and max < 3:
    print('No')
    exit()
while True:
    if a + 1 <= N-1:
        if a + 2 <= N-1:
            if S2[a+1] == "." and S2[a+2] == ".":
                a += 2
                stack3.append(a+1)
                #print("a")
            elif S2[a+1] == "#" and S2[a+2] == ".":
                a += 2
                #print("b")
            elif S2[a+1] == "." and S2[a+2] == "#":
                a += 1
                #print("c")
            else:
                if len(stack3) == 0:
                    flg3 = 1
                else:
                    flg3 = 2
        else:
            if S2[a+1] == ".":
                a += 1
            else:
                if len(stack3) == 0:
                    flg3 = 1
                else:
                    flg3 = 2
    if a == C:
        S2[C] = "#"
        #print(S)
        break
    elif flg3:
        ansflg2 = 1
        #print('No')
        break
    if flg3 == 2:
        a = stack3.pop()
if not ansflg2:
    while True:
        if b + 1 <= N-1:
            if b + 2 <= N-1:
                if S2[b+1] == "." and S2[b+2] == ".":
                    b += 2
                    stack4.append(b+1)
                    #print("a")
                elif S2[b+1] == "#" and S2[b+2] == ".":
                    b += 2
                    #print("b")
                elif S2[b+1] == "." and S2[b+2] == "#":
                    b += 1
                    #print("c")
                else:
                    if len(stack4) == 0:
                        flg4 = 1
                    else:
                        flg4 = 2
            else:
                if S2[b+1] == ".":
                    b += 1
                else:
                    if len(stack4) == 0:
                        flg4 = 1
                    else:
                        flg4 = 2
        if b == D:
            #print('Yes')
            break
        elif flg4:
            ansflg2 = 1
            #print('No')
            break
        if flg4 == 2:
            b = stack4.pop()
#print(ansflg,ansflg2)
if ansflg == 1 and ansflg2 == 1:
    print('No')
else:
    print('Yes')