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:
# 2019/06/02
# AtCoder Grand Contest 034 - A

# For the answer:
# 1-1. Search min(ac) and max(abcd)
# 1-2. Search ## between min and max
# 2. Case:B<C, Left of B is . and (. or C), or exist .. -> Yes

# Def 1 : True is "Case No"
def searchRock(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg:
            rcflg = True
            break
    return rcflg

def searchPlain(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 2): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg and in_str[i+2] == in_tg:
            rcflg = True
            break
    return rcflg

# Input
n, a, b, c, d = map(int, input().split())
s = input()
ans = ""

# 1. Search ##
if c < b:
    # Search between a and c, b and d
    rflg = searchRock(a, c, s, "#")
    if rflg == True:
        ans = "No"
    else:
        rflg = searchRock(b, d, s, "#")
        if rflg == True:
            ans = "No"

else:
    # Search between a and max(c, d)
    rflg = searchRock(a, max(c, d), s, "#")
    if rflg == True:
        ans = "No"
    
# 2. Check around b
if ans != "No":
    if (b < c and d < c):
        # Case: B < D < C 
        pflg = searchPlain(b+1, d+1, s, ".")
        if pflg == False:
            if s[b-2] == "." and s[b] == ".":
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"

# Output
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-3,D+2):
    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 S[D-2] == "#":
    answer = 0
if answer == 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n, a, b, c, d = map(int, input().split())
s = input()
if '###' not in s:
    ans = 'Yes'
    if c > d:
        ans = 'Yes'
        if '...' in s:
            ans = 'Yes'
        elif '##' not in s:
            ans = 'Yes'
        else:
            ans = 'No'
    else:
        ans = 'No'
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
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:
#!/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
x = 0
if D < C:
    x = 1
if D < C and max < 3:
    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()

#すぬけ先
if ansflg == 0 and x == 1 and S[D-1] == "#":
    print('No')
    exit()
if ansflg == 0 and x == 1 and D+1 < N and S[D+1] == "#":
    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')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

N, A, B, C, D = map(int, input().split())
S = list(input())
S[A-1] = '#'; S[B-1] = '#'
S.extend(['#']*2)
def dfs(a = A, b = B):
    if a == C and b == D:
        return 'Yes'

    if S[a] == '.':
        S[a] = '#'; S[a-1] = '.'
        return dfs(a+1, b)
    if S[a+1] == '.':
        S[a+1] = '#'; S[a-1] = '.'
        return dfs(a+2, b)
    if S[b] == '.':
        S[b] = '#'; S[b-1] = '.'
        return dfs(a, b+1)
    if S[b+1] == '.':
        S[b+1] = '#'; S[b-1] = '.'
        return dfs(a, b+2)
    return 'No'
print(dfs())

Submission status: Wrong Answer

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

outflag=0
giveup=0
while giveup<1:
  end=0
  if S[D] != 'B':
    ind = S.index('B')
    if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='A':
      S[ind] = '.'
      S[ind+1] = 'B'
    elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='A':
      S[ind] = '.'
      S[ind+2] = 'B'
    else:
      giveup+=1
      end=1

  if S[C]!='!':
    ind = S.index('A')
    if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='B':
      S[ind] = '.'
      S[ind+1] = 'A'
    elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='B':
      S[ind] = '.'
      S[ind+2] = 'A'
    else:
      giveup+=1
      end=1
      
if S[C]=='A' and S[D]=='B':
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

def unchi(a,b,c,d,s):
  #s = s[:b] + '#' + s[b+1:]
    
  if (len(max(s[b:d].split("."))) < 2):
    #s = s[:b] + '.' + s[b+1:]
    b = d
    #s = s[:b] + '#' + s[b+1:]
  
  if (len(max(s[a:c].split("."))) < 2):
    a = c
    
  if(a==c and b==d):
    return 1
  else:
    return 0

if (unchi(a_-1,b_-1,c_-1,d_-1,s_) or unchi(b_-1,a_-1,d_-1,c_-1,s_)):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
#atcoder grand A
#2019/06/02

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

i = 0
judge1 = False
judge2 = False

if C > D:               #CがDより大きい場合
    i = A               #Aを先に動かす場合
    while True:
        if (S[i-1+1] == ".") & (i+1 != B):
            i = i + 1
            if i == C:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != B):
            i = i + 2
            if i == C:
                judge1 = True
                break
        else:
            break
    i = B
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge2 = True
                break
        else:
            break
    
    i = B               #Bを先に動かす場合
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge1 = True
                break
        else:
            break
    i = A
    while True:
        if (S[i-1+1] == ".") & (i+1 != D):
            i = i + 1
            if i == C:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != D):
            i = i + 2
            if i == C:
                judge2 = True
                break
        else:
            break

else:                   #DがCより大きい場合
    i = B
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge1 = True
                break
        else:
            break

    i = A
    while True:
        if (S[i-1+1] == ".") & (i+1 != D):
            i = i + 1
            if i == C:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != D):
            i = i + 2
            if i == C:
                judge2 = True
                break
        else:
            break
  
if judge1 & judge2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
class KenkenRace:
    def __init__(self):
        N, A, B, C, D = map(int, input().split())
        S = [str(c) for c in input()]

        self.N = N
        self.A = A
        self.B = B
        self.C = C
        self.D = D
        self.S = S

    def main(self):
        result = False

        # C < B のとき
        if self.C < self.B:
            # 割れているので, A -> C and B -> D を検証
            result = self.__canClear__(self.A, self.C) and self.__canClear__(self.B, self.D)

        # C < D のとき
        elif self.C < self.D:
            # クリアできるか確かめる
            result = self.__canClear__(self.A, self.D)

        # D < C のとき
        else:
            # 追い越せるかどうかを確かめる and クリアできるか確かめる
            result = self.__canClear__(self.A, self.C) and self.__canOvertake__(self.D)

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

    def __canClear__(self, start, end):
        isDouble = False
        preObject = ""

        for i in range(start - 1, end):
            c = self.S[i]
            if c == "#" and preObject == "#":
                isDouble = True
                break
            else:
                preObject = c

        return not isDouble

    def __canOvertake__(self, lower):
        isTriple = False
        objectCount = 0
        severalCount = 0

        for i in range(self.B - 2, lower):
            c = self.S[i]
            objectCount += 1

            # 何もない箇所が何連続目か, カウント
            if c == ".":
                severalCount += 1
            else:
                severalCount = 0

            if objectCount == lower:
                # この位置 or 次の位置で3連続でない場合, 追い越せない
                if severalCount < 2:
                    break
                elif severalCount == 2 and self.S[i + 1] == ".":
                    isTriple = True
                    break
                elif severalCount == 2 and self.S[i + 1] == "#":
                    break

            # 3連続で何もなければ追い越し可能か
            if severalCount == 3:
                isTriple = True
                break

        return isTriple


kenkenRace = KenkenRace()
kenkenRace.main()

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 check(s, i, dest):
  while i < dest:
    if i + 1 <= dest and s[i + 1] == '.':
      i = i + 1
    elif i + 2 <= dest and s[i + 2] == '.':
      i = i + 2
    else:
      break

  return i == dest


def move(s, i, dest):
  if i == dest:
    return -1

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

    if i > dest:
      return -1

    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):
    if a == C and b == D:
      return True

    s = get(a, b)
    # print(_, s)
    if a == C:
      return check(s, b, D)
    if b == D:
      return check(s, a, C)

    if C > D:
      if check(s, a, C):
        a = C
      else:
        b = move(s, b, D)
        if b < 0:
          return False
    else:
      if check(s, b, D):
        b = D
      else:
        a = move(s, a, C)
        if a < 0:
          return False


print('Yes' if main() else 'No')

Submission status: Wrong Answer

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

S= input()

if('##'  in S[A-1:max({C,D})]):
  print("No")
elif(C<B):
  if('##'  in S[A-1:C]):
    print("No")
  else:
    print("Yes")
elif(B<C):
  if(C<D):
    if('##'  in S[A-1:C]):
      print("No")
    else:
      print("Yes")
  elif(D<C):
    if('##'  in S[A-1:D]):
      print("No")
    elif(('...'in S[A-1:C])):
      print("Yes")
    else:
      print("No")

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:ffin]
kiritorifin=sss[fin-1:fst]
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("No")
if(afin =="#" or bfin =="#"):
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input() + "##"
line = [0 for i in range(len(S))]
for i in range(len(S)):
    line[i] = 0 if S[i]=="." else 1
A -= 1
B -= 1
C -= 1
D -= 1
line[A] = "A"
line[B] = "B"


A_checkin = False
B_checkin = False

while True:
    if (line[A+1] != 0) and (line[A+2] != 0) and (not A_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+1]==0 and not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (line[B+2]==0 and not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        else:   
    
            break

    if (line[D-1]=="B" or line[D-2]=="B"):
        B_checkin = True
        line[D] = "B"
        line[B] = 0
        B = D
    
    if (line[C-1]=="A" or line[C-2]=="A"):
        line[C] = "A"
        A_checkin = True
        line[A] = 0
        A = C
    
    if (line[A+2]==0) and (not A_checkin):
        line[A+2] = "A"
        line[A] = 0
        A += 2
    elif (line[A+1]==0) and (not A_checkin):
        line[A+1] = "A"
        line[A] = 0
        A += 1
    else:
        break


while True:
    if (not B_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+2]==0) and (not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (line[B+1]==0) and (not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        else:
            break
    else:
        break



if (not A_checkin or not B_checkin):
    line = [0 for i in range(len(S))]
    for i in range(len(S)):
        line[i] = 0 if S[i]=="." else 1

    A_checkin = False
    B_checkin = False
    while True:
        if (line[B+1] != 0) and (line[B+2] != 0) and (not B_checkin):
            if (line[C-1]=="A" or line[C-2]=="A"):
                A_checkin = True
                line[C] = "A"
                line[A] = 0
                A = C
            elif (line[A+1]==0 and not A_checkin):
                line[A+1] = "A"
                line[A] = 0
                A += 1
            elif (line[A+2]==0 and not A_checkin):
                line[A+2] = "A"
                line[A] = 0
                A += 2
            else:   
                break

        if (line[D-1]=="B" or line[D-2]=="B"):
            A_checkin = True
            line[C] = "A"
            line[A] = 0
            A = C
        
        if (line[D-1]=="B" or line[D-2]=="B"):
            line[D] = "B"
            B_checkin = True
            line[B] = 0
            B = D
        
        if (line[B+2]==0) and (not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (line[B+1]==0) and (not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        else:
            break
        print(line)

    while True:
        if (not A_checkin):
            if (line[C-1]=="A" or line[C-2]=="A"):
                A_checkin = True
                line[C] = "A"
                line[A] = 0
                A = C
            elif (line[A+2]==0) and (not A_checkin):
                line[A+2] = "A"
                line[A] = 0
                A += 2
            elif (line[A+1]==0) and (not A_checkin):
                line[A+1] = "A"
                line[A] = 0
                A += 1
            else:
                break
        else:
            break
        print(line)



print("Yes" if (A_checkin and B_checkin) 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"

mac=max(c,d)
ans=1

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

if c<b:
    ans=0
elif 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()

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] > a and i[1] > b) or (i[1] != b and i[1] > a and i[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 = list(map(int, input().split()))
S = list(input())
A = A-1
B = B-1
C = C-1
D = D-1
flag = False
flag2 = False
bflag = False
dflag = False
if A > B:
    B, A = (A, B)
    D, C = (C, D)

a = A
b = B
S[A] = 'a'
S[B] = 'b'
Atame = S.copy()
count_a = a
dlag3 = False
for i in range(N):
    if count_a > N-3:
        break
    if Atame[count_a+1] == '#' and Atame[count_a+2] == '#':
        dflag = True
    count_a += 1
count_b2 = b
# for i in range(N):
#     if count_b2 > N-3:
#         break
#     if Atame[count_b2+1] == '#' and Atame[co]
dflag2 = False


if B > A and D > C:
    for i in range(N):
        if b == D:
            flag = True
            break
        if S[b+1]=='.':
            S[b+1] = 'b'
            S[b] = '.'
            b += 1
        elif S[b+2]=='.':
            S[b+2] = 'b'
            S[b] = '.'
            b += 2
    for i in range(N):
        if a == C:
            flag2 = True
            break
        if S[a+1]=='.':
            S[a+1] = 'a'
            S[a] = '.'
            a += 1
        if S[a+2]=='.':
            S[a+2] = 'a'
            S[a] = '.'
            a += 2

    if flag and flag2 and (dflag==False):
        print("Yes")
    else:
        print("No")

else:
    for i in range(N):
        if b > 0 and b + 1 < N:
            if (S[b-1] == '.' or S[b-1] == 'a') and S[b+1] == '.' and S[b] != '#':
                bflag = True
                break
        b += 1
    if bflag:
        b = B
        count_b = b
        for i in range(N):
            if S[count_b+1] == '#' and S[count_b+2] == '#':
                dflag2 = True

    if bflag and (dflag2==False) and (dflag==False):
        print('Yes')
    else:
        print('No')


# elif B > A and C > D:
#     for i in range(N):
#         if b > 1 and b+1 < N:
#             if S[b-1] == '.' and S[b+1] == '.':
#                 bflag = True
#                 break
#         if b + 1 < N:
#             if S[b+1] == '.':
#                 S[b+1] = 'b'
#                 S[b] = '.'
#                 b += 1
#             elif b + 2 < N:
#                 if S[b+2] == '.':
#                     S[b+2] = 'b'
#                     S[b] = '.'
#                     b += 2

#     if bflag:
#         a = a+1
#         for i in range(N-a):
#             if a == C:
#                 flag = True
#                 break
#             if S[a+1] == '.':
#                 S[a+1] = 'a'
#                 S[a] = '.'
#                 a += 1
#             elif S[a+2] == '.':
#                 S[a+2] = 'a'
#                 S[a] = '.'
#                 a += 2

# if flag and (dflag==False):
#     print('Yes')
# else:
#     print('No')

Submission status: Wrong Answer

Solution code:
#A問題
N,A,B,C,D = map(int,input().split())
Slist = list(str(input()))

if C < D:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
                else:
                    pass
            else:
                Rock = 0
    now = A-1
    Rock = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0

    if flag == 1:
        print("No")
    else:
        print("Yes")
    
else:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    mass = 0
    Maxmass = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
                
    now = A-1
    for i in range(D-B):
        I = now + i
        if i == 0:
            mass+=1
        else:
            if Slist[I] == "#":
                Maxmass = max(Maxmass,mass)
                mass = 0
            else:
                mass+=1
                
    Maxmass = max(Maxmass,mass)

    if Maxmass <= 2:
        if mass == 2 and Slist[D] == ".":
            pass
        else:
            flag = 1
    else:
        pass
    
    if flag == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
    if b>c:
        print(aaa)
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        if (b>3):
            if '...' in s[:b]:
                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 = map(int,input().split())
s = input()
ans = 'Yes'
if C<D:
    pass
else:
    if s[B-2:D].count('...')==0:
        ans = 'No'
    elif D-B == 1:
        ans = 'No'
    elif D-B == 2: 
        if s[B-2:D].count('#')!=0:
            ans = 'No'
    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()
count1 = 0
count2 = 0
if C>D:
    for i in range(B-1,D):
        if S[i] == ".":
            count1 += 1
            if count1 ==3:
                break
        else:
            count1 = 0
    for i in range(A-1,D):
        if S[i] == '#':
            count2 +=1
            if count2 == 2:
                break
        else:
            count2 =0
    if count1 == 3 and count2 !=2:
        print("Yes")
    else:
        print("No")
else:
    for i in range(A-1,D):
        if S[i] == "#":
            count2 += 1
            if count2 == 2:
                break
        else:
            count2 = 0
    if count2 != 2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split(' '))
S = input()
blocks = [i+1 for i, s in enumerate([s for s in S]) if s == '#']

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n, a, b, c, d = list(map(int, input().split()))
s = input()
f1 = s.find("##") == -1
f2 = s.find("...") > -1

if a > b:
    t = a
    a = b
    b = t
    t = c
    c = d
    d = t
r = False
if c < d and f1:
    r = True
elif c > d and f1 and f2:
    r = True

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