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: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, A, B, C, D = map(int, input().split(' '))
A -= 1
B -= 1
C -= 1
D -= 1


S = input()
if S[A:C+1].count('##') or S[B:D+1].count('##'):
    print('No')
    exit(0)

if C > D:
    if not S[B-1: D+2].count('...'):
        print('No')
        exit(0)

print('Yes')

Submission status: Accepted

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

for i in range(a, max(c, d)):
    if s[i] == '#' and s[i-1] == '#':
        print('No')
        exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    def rock_check(start, end):
        for a, b in zip(S[start:end], S[start + 1:end]):
            if a == b == "#":
                return False
        else:
            return True

    def three_space_check(start, end):
        start -= 2
        end += 1
        for a, b, c in zip(S[start:end], S[start + 1:end], S[start + 2:end]):
            if a == b == c == ".":
                return True
        else:
            return False

    bfirst = False
    if C < D:
        bfirst = True

    if bfirst:
        if A > B:
            if rock_check(B, D) and rock_check(A, C) and three_space_check(A, C):
                print("Yes")
            else:
                print("No")
        else:
            if rock_check(B, D) and rock_check(A, C):
                print("Yes")
            else:
                print("No")
    else:
        if B > A:
            if rock_check(B, D) and rock_check(A, C) and three_space_check(B, D):
                print("Yes")
            else:
                print("No")
        else:
            if rock_check(B, D) and rock_check(A, C):
                print("Yes")
            else:
                print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    length, snuke_start, hnuke_start, snuke_goal, hnuke_goal = map(lambda x: int(x) - 1, input().split())
    grid = input()
    is_rock_continuing = False
    is_space_continuing = False
    if "##" in grid[min(snuke_start, hnuke_goal):max(snuke_goal, hnuke_goal) + 1]:
        is_rock_continuing = True
    if "..." in grid[hnuke_start - 1:hnuke_goal + 2]:
        is_space_continuing = True
    if snuke_goal < hnuke_goal and not is_rock_continuing:
        print("Yes")
    elif hnuke_goal < snuke_goal and not is_rock_continuing and is_space_continuing:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = '.'+input()

def dp(s,g):
  if s==g or s==g-1 or s==g-2:
    return 1
  if S[s+1]=='.' and S[s+2]=='.':
    return DP[s+1]|DP[s+2]
  if S[s+1]=='#' and S[s+2]=='.':
    return DP[s+2]
  if S[s+1]=='.' and S[s+2]=='#':
    return DP[s+1]
  if S[s+1]=='#' and S[s+2]=='#':
    return 0
DP=[0]*(N+1)
for i in range(C,A-1,-1):
  DP[i] = dp(i,C)
ansA = DP[A]
for i in range(D,B-1,-1):
  DP[i] = dp(i,D)
ansB = DP[B]
#print(ansA,ansB)
if C<D:
  ans = ansA & ansB
else:
  ans = ansA & ansB & ('...' in S[B-1:D+2])

Ans = ['No','Yes']
print(Ans[ans])

Submission status: Accepted

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

S = '.' + input() + '#'

# S[A,C],S[B,D]には'##'が存在してはいけない
if '##' in S[A: C + 1] or '##' in S[B: D + 1]:
    print('No')
    exit()

# 追い越さなければいけないとき
# S[B,D]に'...'が存在する必要がある
if D < C:
    if not '...' in S[B - 1 : D + 2]:

        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

def isBlock(S,i):
    return S[i] == "#"

def hasContinuingSharp(S,A,B):
    prevSharp = False
    for i in range(A,B):
        if isBlock(S,i):
            if prevSharp:
                return True
            else:
                prevSharp = True
        else:
            prevSharp = False
    return False

def hasThreeContinueingNonSharp(S,A,B):
    nonBlockCount = 0
    for i in range(A,B):
        if isBlock(S,i):
            nonBlockCount = 0
        else:
            nonBlockCount += 1
            if nonBlockCount == 3:
                return True
    return False

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    A-=1
    B-=1
    C-=1
    D-=1
    if hasContinuingSharp(S,A,C) or hasContinuingSharp(S,B,D):
        print(NO)
        return
    if C < D:
        print(YES)
        return
    if hasThreeContinueingNonSharp(S,B-1,D+2):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 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: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
s=list(S.split("#"))

answer="Yes"


if "##" in S[min(A,C):max(B,D)]:
    answer="No"
if C<D:
    pass
else:
    if "..." not in S[B-2:D+1]:
        answer="No"
    
print(answer)

Submission status: Accepted

Solution code:
def main():
    N, A, B, C, D = (int(i) for i in input().split())
    S = "#" + input() + "#"
    if "##" in S[A:C+1] or "##" in S[B:D+1]:
        return print("No")
    if D < C and "..." not in S[B-1:D+2]:
        return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, A, B, C, D = (int(i) for i in input().split())
    S = input()
    if "##" in S[A:C] or "##" in S[B:D]:
        return print("No")
    if D < C and (S[D-2] == "#" or S[D] == "#"):
        if (S[B-2] == "#" or S[B] == "#") and "..." not in S[B-1:D]:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
p = 0
t = 0
stri = 0
for i in range(A-1, max(C, D) - 1):
  if S[i:i+2] == '##':
    p = 1
for j in range(B-1, min(C, D) - 1):  
  if S[j:j+3] == '...':
    if stri == 0:
      stri = j + 1
    t = 1
if S[B] == '.' and S[B-2] == '.':
  t = 1
if (C < D and p == 0) or (C > D and p == 0 and t == 1 and stri <= D-1):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
p = 0
t = 0
sti = 0
for i in range(A-1, max(C, D) - 1):
  if S[i:i+2] == '##':
    p = 1
for j in range(B-1, min(C, D) - 1):  
  if S[j:j+3] == '...':
    if sti == 0:
      sti = j + 1
    t = 1
if S[B] == '.' and S[B-2] == '.':
  t = 1
if (C < D and p == 0) or (C > D and p == 0 and t == 1 and sti <= D-1):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from copy import deepcopy
def solve():
    N,A,B,C,D = map(lambda x:int(x)-1, input().split())
    field_orig = list(input())
    field = deepcopy(field_orig)

    if C < D:
        if existsContinuousRocks(field,A,B,C,D):
            print('No')
        else:
            print('Yes')
    else:
        if not existsContinuousRocks(field,A,B,C,D) \
            and existsContinuousDots(field,A,B,C,D):
            print('Yes')
        else:
            print('No')

def existsContinuousRocks(field, A, B, C, D):
    for i in range(A, min(max(C,D), len(field)-1)):
        if field[i] == '#' and field[i+1] == '#':
            return True
    return False

def existsContinuousDots(field,A,B,C,D):
    for i in range(B-1,min(D, len(field)-2)):
        if field[i] == '.' and field[i+1] == '.' and field[i+2] == '.':
            return True
    return False


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Sarr = [True if s == '.' else False for s in S]
#print(Sarr)

def canmove(st):
  global N, Sarr
  can = [False] * N
  can[st-1] = True
  for i in range(st, N):
    if Sarr[i]:
      if can[i-1] or can[i-2]:
        can[i] = True
  return can

Acan = canmove(A)
Bcan = canmove(B)
#print(Acan)
#print(Bcan)

ans = Acan[C-1] and Bcan[D-1]
#print(ans)

def canpass(st, ed):
  global Sarr
  for i in range(st, ed-1):
    if Sarr[i] and Sarr[i+1] and Sarr[i+2]:
      return True
  return False

if C > D:
  ans = ans and canpass(B-2, D)
#print(ans)

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, a, b, c, d = list(map(int,ipti().split()))
    a -= 1
    b -= 1
    c -= 1
    d -= 1

    s = input()

    if c > d:
        s_groupby = itertools.groupby(s[b-1:d+2])
        for key, group in s_groupby:
            group_list = list(group)
            if key == "." and len(group_list) >= 3:
                break
        else:
            print('No')
            sys.exit()

    for i in range(a + 1, d):
        if s[i] == "#":
            if s[i + 1] == "#":
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

long_s = s[a-1:max(c,d)]
short_s = s[b-2:min(c,d)+1]
rocks = long_s.count("##")
change = short_s.count("...")

if rocks >= 1:
  print("No")
elif c > d and change == 0:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

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

right_end = max(C, D)
S = S[A:right_end+1]

ans = True
if A < B < C < D:
    if S.count('##'):
        ans = False
elif A < C < B < D:
    if S[A:C+1].count('##') or S[B:D+1].count('##'):
        ans = False
else:
    if S.count('##'):
        ans = False
    elif S[B:D+2].count('...'):
        pass
    elif S[B-1:B+2] == '...':
        pass
    else:
        ans = False

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

# print(S)
# print(iwaiwa)
# print(S[B-1:B+2])

Submission status: Accepted

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

flg = '##' in S[A-1:C] or '##' in S[B-1:D]
if C > D and not flg:
  f,e = max(A-1,B-2),min(D+1,N)

  flg = not '...' in S[f:e]
print("No" if flg else "Yes")

Submission status: Accepted

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    s = input()
    r = 'Yes'
    if ('##' in s[a-1:c]) or ('##' in s[b-1:d]):
        r = 'No'
    else:
        if (c>d) and not ('...' in s[b-2:d+1]):
            r = 'No'
    print(r)

main()

Submission status: Accepted

Solution code:
# ???
n,a,b,c,d=map(int,input().split())
s=input()
ans="Yes"

if c<d:
    btod=s[b:d]
    atoc=s[a:c]
    if btod.count("##")>0:ans="No"
    if atoc.count("##")>0:ans="No"
else:
    btod=s[b-1-1:d+1]
    atoc=s[a:c]
    if atoc.count("##")>0:ans="No"
    else:
        if btod.count("...")==0:ans="No"
    
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,a,b,c,d=map(int,input().split())
s=input()
for i in range(b-1,d-1):
    if s[i]=="#" and s[i+1]=="#":
        print("No")
        quit()

if c<d:
    for i in range(a-1,c-1):
        # print(s[i],s[i+1])
        if s[i]=="#" and s[i+1]=="#":
            print("No")
            quit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    a -= 1; b -= 1; c -= 1; d -= 1;
    s = input()

    if c < d:
        for i in range(a, d-1):
            if s[i:i+2] == "##":
                print("No")
                return 0
        print("Yes")

    else:
        for i in range(a, c-1):
            if s[i:i+2] == "##":
                print("No")
                return 0
        for i in range(b-1, d):
            if s[i:i+3] == "...":
                print("Yes")
                return 0
        print("No")

main()

Submission status: Accepted

Solution code:
def reach(s, x, y):
    for i in range(x, y-1):
        if s[i] == "#" and s[i+1] == "#":
            return False
    return True
def search(s, x, y):
    for i in range(x-1, y):
        if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
            return True
        if s[i] == "#" and s[i+1] == "#":
            break
    return False

def main():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = input().rstrip()
    if reach(s, a, c) and reach(s, b, d):
        if c < d:
            print("Yes")
        else:
            if search(s, b, d):
                print("Yes")
            else:
                print("No")

    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
E=min(C,D)
F=max(C,D)
if S.find('##',A,F)>0:
  print('No')
else:
  if C<D:
    print('Yes')
  else:
    if S.find('...',B-2,E+1)>0:
      print('Yes')
    else:
      print('No')

Submission status: Accepted

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

s = input()

if s.find('##',a,max(c, d)) < 0:
    if c<d :
        print('Yes')
    else :
        if s.find('...',b-2,d+1)>=0:
            print('Yes')
        else :
            print('No')
else :
    print('No')

Submission status: Accepted

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

s = input()

if s.find('##',a,c) < 0 and s.find('##',b,d) < 0:
    if c<d :
        print('Yes')
    else :
        if s.find('...',b-2,d+1)>=0:
            print('Yes')
        else :
            print('No')
else :
    print('No')

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
ng = '##'
if c < d:
    if (ng in s[b-1:d]) or (ng in s[a-1:c]):
        print('No')
    else:
        print('Yes')
else:
    if ('...' not in s[b-2:d+1]):
        print('No')
    else:
        print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
a-=1
b-=1
c-=1
d-=1
s=input()
bl_bl=[]
jump=[]
ans=1

for i in range(1,n-1):
    if s[i-1:i+1]=="##":
        if a<i<c or b<i<d:
            ans=2
            break
    if s[i-1:i+2]=="...":
        jump.append(i)

if ans!=2:
    if c<d:
        ans=0
    else:
        for i in jump:
            if b<=i<=d:
                ans=0
                break

print("Yes" if ans==0 else "No")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int, input().split())
S=input()
if S.find("##", A, B)<0 and S.find("##", C, D)<0:
    if C<D:
        print("Yes")
    else:
        if S.find("...", B-2, D+1)>=0:
            print("Yes")
        else:
            print("No")
else:
    print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    if Aok and Bok:
        print("Yes")
    else:
        print("No")
else:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    jumpok = "..." in S[B-2:D+1]
    if Aok and Bok and jumpok:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n, a, b, c, d = na()
a -= 1
b -= 1
c -= 1
d -= 1
s = ns()

if "##" in s[a:c + 1] or "##" in s[b:d + 1]:
    print("No")
else:
    if c > d and "..." not in s[b - 1:d + 2]:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

if c > d:
	if "..." not in s[max(0,b-2):min(d+1,n)]:
		print ("No")
		exit()
print ("Yes")

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
F = True
#飛び越えられるのは2マスまで
if ("##" in S[B-1:D]) or ("##" in S[A-1:C]):
  F  =False

#C > DのときAがBを飛び越える必要がある。
#... ->　.B. -> AB. -> .BA -> .B. :真ん中にBを退避させる
#飛び越えるためには...が必要，範囲はBが動ける範囲±1
if C > D and ("..." not in S[B-1-1:D+1]): 
    F = False
#print(S[B-1-1:D+2])

print("Yes" if F else "No")

Submission status: Accepted

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


#%%
flag = True
# A -> Cの間に#が二連続するパターン
if '##' in S[A-1:C]:
    flag = False
# B -> Dの間に#が二連続するパターン
if '##' in S[B-1:D]:
    flag = False

# A, Bの位置交換が必要な時
if C > D:
    if '...' not in S[B-2:D+1]:
    # B,Dの間に連続する3つの'.'が必要
        flag = False

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

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = input()
if C < D or C < B:
    if '##' in S[A:C+1] or '##' in S[B:D+1]:
        print('No')
    else:
        print('Yes')
else:
    if '##' in S[A:C+1]:
        print('No')
    else:
        if '...' not in S[B-1:D+2]:
            print('No')
        else:
            print('Yes')

Submission status: Accepted

Solution code:
import re
n, a, b, c, d = map(int, input().split())
s = input()
for i in range(a-1, c-1):
  if s[i] + s[i+1] == "##":
    print("No")
    exit()
for i in range(b-1, d-1):
  if s[i] + s[i+1] == "##":
    print("No")
    exit()
if c < d:
  print("Yes")
else:
  f = False
  for i in range(b-2, min(d-1, n-2)):
    if s[i] + s[i+1] + s[i+2] == "...":
      f = True
  if f:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
if '##' in s[a:c+1] or "##" in s[b:d+1]:
    print('No')
    exit()

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

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
E = max(C,D)
AE = S[A:E]
BD = S[B-2:D+1]
if "##" in AE:
  print("No")
elif C > D and "..." not in BD:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

def main():
    N,A,B,C,D = map(int,input().split())
    s = str(input())
    
    if "##" in s[A:max(C,D)]:
        print("No")
    elif (C > D and "..." not in s[B-2:D+1]):
        print("No")
    else:
        print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

if "##" in s[a-1:max(c,d)]:print("No")
elif c>d and "..." not in s[b-2:d+1]:print("No")
else:print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c,d = inpl()
s = input()
def chk(i):
    if s[i] == s[i+1] == '#':
        print('No')
        quit()
    return True
def cc(i):
    if s[i] == s[i+1] == s[i+2] == '.':
        return True
    return False

if c < d:
    for i in range(b-1,d-1):
        chk(i)
    for i in range(a-1,c-1):
        chk(i)
else:
    for i in range(b-2,d-1):
        if cc(i):
            break
    else:
        print('No')
        quit()
    for i in range(a-1,c-1):
        chk(i)
print('Yes')

Submission status: Accepted

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

if c < d:
    for i in range(b-1, d-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    t = ''
    for i in range(len(s)):
        if i == d-1:
            t += '#'
        else:
            t += s[i]

    for i in range(a-1, c-1):
        if t[i] == '#' and t[i+1] == '#':
            print('No')
            exit()

    print('Yes')
elif c > d:
    for i in range(a-1, c-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    for bi in range(b-1,d):
        if s[bi-1] == s[bi] == s[bi+1] == '.':
            print('Yes')
            exit()

    print('No')

else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin

n,a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
s = ["."]+list(stdin.readline().rstrip())
for i in range(b,d):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
for j in range(a,c):
    if s[j] == "#" and s[j+1] == "#":
        print("No")
        exit()
if c < d:
    print("Yes")
    exit()
for k in range(b,d+1):
    if s[k-1] == "." and s[k] == "." and s[k+1] == ".":
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
N,Sa,Sb,Ga,Gb = map(int, input().split())
S = input()

Sa-=1
Sb-=1
Ga-=1
Gb-=1

for i in range(Sa,Ga):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(Sb,Gb):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if Gb < Ga: #Need to swap

    for i in range(Sb-1,Gb):
        if S[i] == "." and S[i+1] == "." and S[i+2] == "." :
            print("Yes")
            exit()

    print("No")

else: # No need to swap
    print("Yes")

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
X = max(C,D)
rock = 0
check = 0
for i in S[A:X]:
    if i == '#':
        rock += 1
    else:
        rock = 0
    if rock == 2:
        check = 1
        break
if check == 0 and C > D:
    plane = 0
    pcheck = 0
    for i in S[B-2:D+1]:
        if i == '.':
            plane += 1
            if plane == 3:
                pcheck = 1
                break
        else:
            plane = 0
    if pcheck == 0:
        check = 1
if check == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def is_possible(start, goal):
    for i in range(start, goal - 1):
        if s[i] == "#" and s[i + 1] == "#":
            return False
    return True
  
def is_possible2(start, goal):
    for i in range(start, goal):
        if s[i - 1] == "." and s[i] == "." and s[i + 1] == ".":
            return True
    return False

if c < d:
    if is_possible(a - 1, c) and is_possible(b - 1, d):
        print("Yes")
    else:
        print("No")
else:
    if is_possible(a - 1, c) and is_possible(b - 1, d) and is_possible2(b - 1, d):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
def is_a(x, y):
  for i in range(x, y-1):
    if s[i]==s[i+1]=="#":
      return False
  return True
def is_f(x, y):
  for i in range(x, y+1):
    if s[i-1]==s[i]==s[i+1]==".":
      return True
  return False

ans = "No"
if is_a(a, b) and is_a(c, d):
  if c < d or is_f(b, d):
    ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
# import sys
n, a, b, c, d = map(int, input().split())
s = list(input().replace(".", " "))

a -= 1
b -= 1
c -= 1
d -= 1

end = max(c, d)

for i in range(a, end):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
        # sys.exit(0)


if c > d and s[d-1] == "#":
    for i in range(b, d):
        if s[i-1] == " " and s[i] == " " and s[i+1] == " ":
            print("Yes")
            exit()
            # sys.exit(0)
    print("No")
    exit()
    # sys.exit(0)
else:
    print("Yes")
    exit()
    # sys.exit(0)