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:
l = list(map(str, input().split()))
sss=input()

num = int(l[0])
ast = l[1]
bst = l[2]
afin=int(l[3])
bfin=int(l[4])




if(ast > bst):
    st=int(bst)
    fin=int(ast)
if(bst > ast):
    st=int(ast)
    fin=int(bst)


if(afin > bfin):
    fst=int(bfin)
    ffin=int(afin)
if(bfin > afin):
    fst=int(afin)
    ffin=int(bfin)


kiritorist= sss[st:num]
kiritorifin=sss[fin-1:fst]
print(kiritorifin)
print(kiritorist)
if(afin !="#" or bfin !="#"):
    if(kiritorist.find('##')>0):
        print("No")
    
    if(kiritorist.find('##')<0):
        if((ast<bst and afin<bfin)or(bst<ast and bfin<afin)):
            print("Yes")
    
        if((ast<bst and bfin<afin)or(bst<ast and afin<bfin)):
            if(kiritorifin.find("..")>=0):
                print("Yes")
                
            else:
                print("NN")
if(afin =="#" or bfin =="#"):
    print("Yes")

Submission status: Wrong Answer

Solution code:
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(0,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2):
        flag = False
        break
for j in range(0,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (j <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    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())
if C<D:
    ans = 'Yes'
else:
    if s[B-2:D].count('...')>0:
        ans = 'Yes'
#        if D-B == 1:
#            ans = 'No'
#        elif D-B == 2: 
#            if s[B-2]== '#' or s[D]== '#':
#                ans = 'No'
        s[B-1] = '#'
        s[D-1] = '#'
    else:
        ans = 'No'
if s[A:C-2].count('##')!=0 or s[B:D-2].count('##')!=0:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

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

rock = 0
max_rock = []
non = 0
max_non = []
k = 0
for i in s:
    if i == '#':
        rock += 1
        if non >= 3:
            max_non.append([non, k])
        non = 0
    else:
        non += 1
        if rock >= 2:
            max_rock.append([rock, k])
        rock = 0
    if k == n-1:
        k += 1
        if non >= 3:
            max_non.append([non, k])
        if rock >= 2:
            max_rock.append([rock, k])
    k += 1

# print(max_non)
max_non1 = [i for i in max_non if i[1]-i[0]+2 < d and i[1]-i[0]+2 < c and i[1]-2 > b and not i[1]-1 == b]
# max_rock1 = [i for i in max_rock if (i[1] < d and i[1] < c and i[1] > a and i[1] > b) or (i[1])]
max_rock1 = [i for i in max_rock if (i[1] > a and i[1] < b) or (i[1] > b and i[1] < c) or (i[1] > c and i[1] < d)]
max_rock3 = [i for i in max_rock if (i[1] > a and i[1] < b) or (i[1] > b and i[1] < d) or (i[1] > d and i[1] < c)]
max_rock2 = [i for i in max_rock if (i[1] < d and i[1] > b) or (i[1] > a and i[1] < c)]
# print(max_non1)
# print(max_rock1)
if b > c:
    if len(max_rock2) > 0:
        print('No')
    else:
        print('Yes')
elif c > d:
    if len(max_rock3) > 0:
        print('No')
    elif len(max_non1) > 0:
        print('Yes')
    else:
        print('No')
elif len(max_rock1) > 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = (int(_) for _ in input().split())
x = input()

ng = [i+1 for i in range(n) if x[i:i+2] == "##"]
ng.extend([0,20000001])

ng1 = [a <= i <= c or b <= i <= d for i in ng]

x2 = x[b-1:d+1]
ex = [x2[i:i+3] == "..." for i in range(len(x2))]

if any(ng1):
    res = "No"
elif c > d:
    if any(ex):
        res = "Yes"
    else:
        res = "No"
else:
    res = "Yes"

print(res)

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split(" "))
s=input()
pathA=s[a-1:c-1]
pathB=s[b-1:d-1]
isBlockCont = pathA.count("##") == 0 and pathB.count("##") == 0
if c < d :
    if isBlockCont:
        print("Yes")
    else:
        print("No")
else:
    if isBlockCont and s[b-2:d].count("...") > 0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

def mymain(s):
    a_b_d_s = list(enumerate(s))[a-1:c if c > d else d]
    for i, p in a_b_d_s:
        if i+1 < len(s) and p == "#" and s[i+1] == "#":
            return 'No'
    if c > d:
        if s[b] == "." and s[b-2] == "." or s[b] == "." and s[b+1] == ".":
                return 'Yes'
        else:
            b_d = list(enumerate(s))[b:d]
            for i, s_b_d_point in b_d:
                if i+2 < len(b_d) and s_b_d_point == '.' and s[i+1] == '.' and s[i+2] == '.':
                    return "Yes"
        return'No'
    return 'Yes'
                
print(mymain(input()))

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[A-1:D].count('...'))
            if(sf == 0):
                print(NO)
            
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D].count('..b') == 1):
                    print(NO)
                else:
                    print(YES)
            ######### あとはここだけ考える ####
            elif(sf >= 2):
                # print('Im here!')
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                ptS = tS.rfind('..b')
                if(ptS == -1):
                    print(YES)
                else:
                    if(tS[ptS:D].count('...') == 0):
                        print(ptS)
                        # print(tS[ptS:D])
                        print(NO)
                    else:
                        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:
n,a,b,c,d = map(int,input().split())
s = input()

ans = "No"
if "##" in s[0:d] or "##" in s[0:c]: pass
else:
    # Bを先にゴールさせる
    l = list(s) ; l[d-1]="#" ; s2 = "".join(l)
    if "##" in s2[0:c]:
        # Aを先にゴールさせる可能性
        if "..." in s[b:d-1]:
            s[b:d-1].replace("...",".#.")
            if s[c-1]=="#": pass
            else:
                l = list(s) ; l[c-1]="#" ; s3 = "".join(l)
                if "##" in s3[0:d]: pass
                else: ans = "Yes"
    else: ans = "Yes"


print(ans)

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)]
        if len(r_in_fpath) == 0:
            if B+1 == D and B - 1 in rocks and D + 1 in rocks:
                flag = False
        else:
            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 r_in_fpath[0] - B <= 2:
                if 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())
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"

mac=max(c,d)
ans=1

for i in range(minim,mac):
    if s[i]==s[i+1]=="#":
        ans=1

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]=="#":
        ans=0
    else:
        ans=1
                
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()
if '##' in S:
	print('No')
elif d < c:
    if not '...' in S:
        print('No')
    if d <= n and S[d] == '#' and d - 2 >= 0 and S[d - 2] == '#':
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if s.count("##")>=1:
    print("No")
    exit()

if C < D:
    print("Yes")

elif C > D:
    if len(index)>=1:
        for i in index:
            if A <= i and B <= i+1 and i+2<=C and i+1<=D:
                print("Yes")
                exit()
        print("No")
        exit()
    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

flag = True
for i in range(A_goal):
    if i< A_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False

for i in range(B_goal):
    if i< B_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False
if flag == False:
    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 :
    for i in range(A_goal-2):
        if (S[i] == '.' or i == A_pos) and (S[i+1]== '.' or i+1 == A_pos ) and (S[i+2] == '.' or i+2 == A_pos):
            print ("Yes")
            sys.exit()

if B_pos < A_pos and A_goal < B_goal :
    for i in range(B_goal-2):
        if (S[i] == '.' or i == B_pos) and (S[i+1]== '.' or i+1 == B_pos ) and (S[i+2] == '.' or i+2 == B_pos):
            print ("Yes")
            sys.exit()
            
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())

ans = 'Yes'
if C < D:
    for i in range(A , C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
else:
    for i in range(A, C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D - 1):
        if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
            break
    else:
        for i in range(B, D):
            if i - 1 == A and i == B and S[i + 1] == '.':
                break
        else:
            ans = 'No'
            
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(0,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2):
        flag = False
        break
for j in range(0,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (j + 3 <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        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)
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"

mac=max(c,d)
ans=1

for i in range(minim,mac):
    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=0
    elif s[d-1]=="#" or s[d+1]=="#":
        ans=0
    else:
        ans=1
                
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()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = 0
if C < D:
    S1 = S[A: D-1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
        ans1 = max(ans1, cou1)
    if ans1 < 2:
        print("Yes")
    else:
        print("No")
else:
    S1 = S[A: C-1]
    S2 = S[B: D+1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    ans1 = max(ans1, cou1)
    for j in S2:
        if i == ".":
            cou2 += 1
        else:
            ans2 = max(ans2, cou2)
            cou2 = 0
    ans2 = max(ans2, cou2)
    if ans1 < 2 and ans2 >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
s_flag = False
can_flag = True
count = 0
max_count = 0
for i in range(n):
  if s[i] == '#':
    count = 0
    if s_flag:
      can_flag = False
      break
    s_flag = True

  else:
    s_flag = False
    count += 1
    max_count = max(max_count, count)
    
if max_count <= 2:
  if c > d:
    can_flag = False
  else:
    can_flag = True
if can_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")
    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())
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"

mac=max(c,d)
ans=1

for i in range(minim,mac):
    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]=="#":
        ans=1
    else:
        ans=1
                
if ans==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
lis=list(map(int,input().split()))
S=input()
ans="Yes"
memo=0
if lis[3]<lis[4]:
    for i in range(lis[2],lis[0]-1):
        if S[i:i+2]=="##":
            ans="No"
            break
    for i in range(lis[1],lis[4]-1):
        if S[i:i+2]=="##":
            ans="No"
            break
    print(ans)

else:
    #Bの位置に岩を置く
    a=S[:lis[2]-1]
    b=S[lis[2]:]
    S=a+"#"+b
    #Aを先に行かせる。可能なら終了。ダメならBを先に行かせてみる
    for i in range(lis[1],lis[3]):
        if S[i:i+2]=="##":
            ans="No"
            break
    #先にBを行かせる。まず可能か判定
    if ans=="No":
        ans="Yes"
        for i in range(lis[2],lis[4]):
            if S[i:i+2]=="##":
                ans="No"
                break
        for i in range(lis[2],lis[4]-1):
            if S[i:i+3]=="...":
                memo=i+1
                break
    #だめなら終了。可能ならDに岩を置いてAについて検討
        if ans=="Yes":
            a=S[:memo]
            b=S[memo+1:]
            S=a+"#"+b
            a=S[:lis[2]-1]
            b=S[lis[2]:]
            S=a+"."+b
            for i in range(lis[1],lis[3]):
                if S[i:i+2]=="##":
                    ans="No"
                    break
        if memo==0:
            ans="No"
    print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
S = input()
S =S+"#"
S =S+"#"
S =S+"#"
answer = 1
a = 1
distance = []
distance_2 = []
for n in range(A-1,max(C-1,D-1)):
  a += 1
  if S[n] == "#":
    distance.append(a)
    a = 0
if 1 in distance:
  answer = 0
if D < C and answer == 1:
  a = 1
  for n in range(B-2,D):
    a += 1
    if S[n] == "#":
      distance_2.append(a)
      a = 0
  if max(distance_2) < 4:
    answer = 0
  if S[D] == "." and S[D-2] ==".":
    answer = 1
if answer == 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[43]:


N, A, B, C, D = map(int, input().split())
S = input()
"""
7 1 3 7 6
.#..#..
"""


# In[54]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    shc = 0
    for s in S[B-1:D+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    #print(1)
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C+1]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        #print(2)
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        #print(2)
        shc = 0
        for i, s in enumerate(S[0:A+1:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        shc = 0
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        #print(l, r)
        mdc = 0
        dc = 0
        shc = 0
        for i, s in enumerate(S[l:r]):
            #print('{}: {}'.format(i, dc))
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)] + [0]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(0,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2):
        flag = False
        break
for j in range(0,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (j + 2 <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
 
N, A, B, C, D = map(int, input().split())
s = list(input())
 
A -= 1
B -= 1
C -= 1
D -= 1
 
for i in range(len(s)):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#':
            print("No")
            exit()
 
if D < C:
    tmp = 0
    for i in range(len(s)):
        if i == len(s) - 2 or i == len(s) - 1:
            continue
        else:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' and i + 1 <= D  and B - 1 <= i:
                tmp = 1
    if tmp != 1:
        print("No")
        exit()
 
 
 
def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans
 
ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

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())

ans = 'Yes'
if C < D:
    for i in range(A , C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
else:
    for i in range(A, C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D - 1):
        if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
            break
    else:
        for i in range(B, D - 1):
            if i - 1 == A and i == B and S[i + 1] == '.':
                break
        else:
            ans = 'No'
            
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return

    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

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

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

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
if D < C and max < 3:
    print('No')
    exit()
elif D < C and max >= 3:
    if S[C-1] == "#":
        print('No')
        exit()
    if C < N - 1 and S[C+1] == "#":
        print('No')
        exit()
#ふぬけ先
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()
#すぬけ先
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')