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()
#0-indexedにするため
A-=1;B-=1;C-=1;D-=1
'''
A→C
B→D
順序としてありえるのは
A<B<D<C
A<B<C<D
A<C<B<D
C<Dなら飛び越える必要がない
C>Dなら飛び越える必要がある
飛び越えを成功させるためには3連続の.が途中にあることが必要十分である
'''
if C<D:
    #ここは飛び越える必要がないとき
    Snuke=[0 for i in range(N)]
    Fnuke=[0 for i in range(N)]
    Snuke[A]=1
    Fnuke[B]=1
    for i in range(1,N):
        if S[i]=="#":
            continue
        if Snuke[i-1]==1:
            Snuke[i]=1
        if i>1 and Snuke[i-2]==1:
            Snuke[i]=1
        if Fnuke[i-1]==1:
            Fnuke[i]=1
        if i>1 and Fnuke[i-2]==1:
            Fnuke[i]=1
    if Snuke[C]==1 and Fnuke[D]==1:
        print("Yes")
    else:
        print("No")
else:
    #A<B<D<C
    #ここは飛び越える必要があるとき
    Snuke=[0 for i in range(N)]
    Fnuke=[0 for i in range(N)]
    Snuke[A]=1
    Fnuke[B]=1
    for i in range(1,N):
        if S[i]=="#":
            continue
        if Snuke[i-1]==1:
            Snuke[i]=1
        if i>1 and Snuke[i-2]==1:
            Snuke[i]=1
        if Fnuke[i-1]==1:
            Fnuke[i]=1
        if i>1 and Fnuke[i-2]==1:
            Fnuke[i]=1
    flag=0
    for i in range(B,D+1):
        if S[i-1]=="." and S[i]=="." and S[i+1]==".":
            flag=1
            break
    if Snuke[C]==1 and Fnuke[D]==1 and flag==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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


def solve():
    if '##' in S[A:C + 1] or '##' in S[B:D + 1]:
        return 'No'

    if C > D:
        if '...' not in S[B - 1:D + 2]:
            return 'No'

    return 'Yes'


print(solve())

Submission status: Accepted

Solution code:
# A - Kenken Race
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,a,b,c,d=nl()
s=si()

ans=''
if c<d:
    for i in range(a,d-1):
        if s[i:i+2]=='##':
            ans='No'
            print(ans)
            exit()
    ans='Yes'
    print(ans)
elif c>d:
    for i in range(a-1,c-1):
        if s[i:i+2]=='##':
            ans='No'
            print(ans)
            exit()
    for i in range(b-2,d-1):
        if s[i:i+3]=='...':
            ans='Yes'
            print(ans)
            exit()
    ans='No'
    print(ans)

Submission status: Accepted

Solution code:
import sys

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

tmp = ""
for i in range(a,c):
	if s[i] == tmp == "#":
		print("No")
		sys.exit()
	tmp = s[i]

for i in range(b,d):
	if s[i] == tmp == "#":
		print("No")
		sys.exit()
	tmp = s[i]

if c < d:
	print("Yes")
	sys.exit()

else:
	cnt = 0
	for i in range(b-2,d+1):
		if s[i] == ".":
			cnt += 1
			if cnt == 3:
				print("Yes")
				sys.exit()
		else:
			cnt = 0

print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int,input().split())
S = list(input())
S = [0] + S
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:
    if S[B-1] == S[B+1] == '.':
        print('Yes')
        exit()
    else:
        count = 0
        for i in range(B,D):
            if S[i] == S[i+1] == S[i+2] == '.':
                print('Yes')
                exit()
    print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
A, B, C, D = A-1, B-1, C-1, D-1
S = input() + "###"
def chk(l, r):
    for i in range(l, r-1):
        if S[i:i+2] == "##":
            return 0
    return 1

def chk3(l, r):
    for i in range(l, r):
        if S[i:i+3].count("#") == 0:
            return 1
    return 0

if chk(A, C) and chk(B, D) and (C < D or chk3(B-1, D)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

if '##' in s[b-1:d] or '##' in s[a-1:c]:
    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 = input()
if '##' in s[a:d+1]:
    print('No')
elif c < d or '...' 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()
if c<d:
  if "#" in s[a-1]+s[b-1]+s[c-1]+s[d-1]:print("No");exit()
  ans="Yes"
  for i in range(c-a):
    if s[a+i-1]==s[a+i]=="#":ans="No"
  for i in range(d-b):
    if s[b+i-1]==s[b+i]=="#":ans="No"
  print(ans)
else:
  if "#" in s[a-1]+s[b-1]+s[c-1]+s[d-1]:print("No");exit()
  ans="No"
  for i in range(d-b+1):
    if s[b+i-2]==s[b+i-1]==s[b+i]==".":ans="Yes"
  for i in range(c-a):
    if s[a+i-1]==s[a+i]=="#":ans="No"
  print(ans)

Submission status: Accepted

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

def test(x,y):
  # xからyへ行ける
  substr = S[x:y-1]
  return substr.find('##') == -1

bl = test(A,C) and test(B,D)
if C > D:
  # 追い越す必要がある
  # 道の存在は保証されているので、局所的に詰まないようにBを配置できればよい
  can_swap = False
  for b in range(B-1,D):
    if S[b] == '#':
      continue
    if S[b-1] == '.' and S[b+1] == '.':
      can_swap = True
      break
  bl = bl and can_swap
answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

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

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

    print("Yes")

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

    print("No")

Submission status: Accepted

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

if "##" in s[a:d]:
    print("No")
    exit()

if c < d:
    for i in range(b, d):
        if s[i:i+2] == "##":
            print("No")
            exit()

    print("Yes")

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

    print("No")

Submission status: Accepted

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

if "##" in s[a:d]:
    print("No")
    exit()

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

    print("Yes")

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

    print("No")

Submission status: Accepted

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

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

    for i in range(a, c):
        if s[i] == "#" and s[i+1] == "#":
            print("No")
            exit()
    print("Yes")

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

    print("No")

Submission status: Accepted

Solution code:
import sys


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

S = {i : s for i, s in enumerate(input(), 1)}

# D < C の場合に備えて3連続空白地帯があるかのフラグを立てる
# C, D の大小関係で場合分けした方が若干早いがコードが汚くなる
stay_B = False
if S[B-1] == '.':
  continuous_empty = 2
else:
  continuous_empty = 1

while B != D:
  if S[B+1] == '.':
    B += 1
    continuous_empty += 1
    if continuous_empty == 3:
      stay_B = True
  else:
    if S[B+2] == '.':
      B += 2
      continuous_empty = 1
    else:
      print("No")
      sys.exit()
    
# D < C のときはAがBを追い越さなくてはならないので3連続空白地帯が必要
if (D > C) or stay_B or (continuous_empty == 2 and S[D+1] == '.'):
  while A != C:
    if S[A+1] == '.':
      A += 1
    else:
      if S[A+2] == '.':
        A += 2
      else:
        print("No")
        sys.exit()

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

Submission status: Accepted

Solution code:
import sys


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

S = {i : s for i, s in enumerate(input(), 1)}

stay_B = False
if S[B-1] == '.':
  continuous_empty = 2
else:
  continuous_empty = 1

while B != D:
  if S[B+1] == '.':
    B += 1
    continuous_empty += 1
    if continuous_empty == 3:
      stay_B = True
  else:
    if S[B+2] == '.':
      B += 2
      continuous_empty = 1
    else:
      print("No")
      sys.exit()
    
# D < C のときはAがBを追い越さなくてはならないので3連続空白地帯が必要
if (D > C) or stay_B or (continuous_empty == 2 and S[D+1] == '.'):
  while A != C:
    if S[A+1] == '.':
      A += 1
    else:
      if S[A+2] == '.':
        A += 2
      else:
        print("No")
        sys.exit()

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

Submission status: Accepted

Solution code:
import sys


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

S = {i : s for i, s in enumerate(input(), 1)}

# AとBは接触しないので個別に進めればOK
if C < D:
  while B != D:
    if S[B+1] == '.':
      B += 1
    else:
      if S[B+2] == '.':
        B += 2
      else:
        print("No")
        sys.exit()

  while A != C:
    if S[A+1] == '.':
      A += 1
    else:
      if S[A+2] == '.':
        A += 2
      else:
        print("No")
        sys.exit()
  print("Yes")
  
# AとBは途中ですれ違う必要がある
# BをAが飛び越えられる場所(3マス連続で空白になる場所)で止めておくことにする
# Aのループは普通に回してよい なぜならば、3マス連続の空白は普通に通過できるし、
# その間Bがそこにいることにすれば良いため
else:
  # AがBを追い越せる場所があるか判定をしつつBをゴールまで移動させる
  stay_B = False
  if S[B-1] == '.':
    continuous_empty = 2
  else:
    continuous_empty = 1

  while B != D:
    if S[B+1] == '.':
      B += 1
      continuous_empty += 1
      if continuous_empty == 3:
        stay_B = True
    else:
      if S[B+2] == '.':
        B += 2
        continuous_empty = 1
      else:
        print("No")
        sys.exit()
   
  # Bが到達できる場合
  if stay_B or (continuous_empty == 2 and S[D+1] == '.'):
    while A != C:
      if S[A+1] == '.':
        A += 1
      else:
        if S[A+2] == '.':
          A += 2
        else:
          print("No")
          sys.exit()
    print("Yes")
      
  # Bが空白地帯に到達できなければNo
  else:
    print("No")

Submission status: Accepted

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

if (a > b and c > d) or (a < b and c < d):
  rock = 0
  for i in range(a-1, c):
    if l[i] == '#':
      rock += 1
      if rock == 2:
        ans = 'No'
        break
    else:
      rock = 0
  rock = 0
  for i in range(b-1, d):
    if l[i] == '#':
      rock += 1
      if rock == 2:
        ans = 'No'
        break
    else:
      rock = 0
  if ans == '':
    ans = 'Yes'
else:
  rock = 0
  for i in range(a-1, c):
    if l[i] == '#':
      rock += 1
      if rock == 2:
        ans = 'No'
        break
    else:
      rock = 0
  rock = 0
  for i in range(b-1, d):
    if l[i] == '#':
      rock += 1
      if rock == 2:
        ans = 'No'
        break
    else:
      rock = 0
  blank = 0
  for i in range(max(a, b)-2, min(c, d)+1):
    if l[i] == '.':
      blank += 1
      if blank == 3:
        ans = 'Yes'
        break
    else:
      blank = 0    
  if ans == '':
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = list(input())
#pre = S[B - 2]
ans = "Yes"
is_reversed = False
flag = False
# cnt = 0
# max_cnt = 0
if D < C:
  is_reversed = True

for i in range(A,max(C,D) -1):
  if S[i] == S[i + 1] == "#":
    ans = "No"
if is_reversed == True:
  for i in range(B - 2,D - 1):
    if S[i] == S[i + 1] == S[i + 2] == ".":
      flag = True
    # if S[i] == ".":
    #   cnt += 1
    # elif S[i] == "#":
    #   cnt = 0
    # max_cnt = max(max_cnt,cnt)
    # pre = S[i]
  # if is_reversed == True and max_cnt < 3:
  #   ans = "No"
  if flag == False:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
# 1-indexed
S = ["$"] + list(input())

if A < B < D < C:
    flag = False

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d-=1
    s = list(input())
    for i in range(b, d):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            exit()
    for i in range(a, c):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            exit()
    if c < d:
        print("Yes")
    else:
        f = True
        for i in range(b-1, d):
            if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
                print("Yes")
                exit()
        print("No")



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,A,B,C,D = map(int,readline().split())
S = '.' + read().rstrip().decode('utf-8')

if A > B:
    A,B = B,A
    C,D = D,C

from_A = [False] * (N+10) # 負のインデックス対策
from_A[A] = True
for i,x in enumerate(S):
    if x == '#':
        continue
    if from_A[i-1] or from_A[i-2]:
        from_A[i] = True
from_A = from_A[:N+1]

from_B = [False] * (N+10) # 負のインデックス対策
from_B[B] = True
for i,x in enumerate(S):
    if x == '#':
        continue
    if from_B[i-1] or from_B[i-2]:
        from_B[i] = True
from_B = from_B[:N+1]

from_A[C+1:] = [False] * (N - C)
from_B[D+1:] = [False] * (N - B)

if not (from_A[C] and from_B[D]):
    print('No')
    exit()

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

# 追い越しが必要

can_swap = False
for i in range(0,N-1):
    j,k = i+1,i+2
    if from_A[i] and from_A[k] and from_B[j]:
        can_swap = True
        break

answer = 'Yes' if can_swap else 'No'
print(answer)

Submission status: Accepted

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

if C < D:
    flag = True
    for i in range(A-1,D-1):
        if S[i]=='#' and S[i+1]=='#':
            flag = False
    print('Yes' if flag else 'No')
else:
    flag = False
    for i in range(B-1,D):
        cnt = 0
        for j in {-1,0,1}:
            if S[i+j]=='.':
            	cnt += 1
        if cnt == 3:
            flag = True
    for i in range(A-1,C-1):
        if S[i]=='#' and S[i+1]=='#':
            flag = False

    print('Yes' if flag else '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
x=[]
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "."+S
flag=0
if C<B:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag=1
            break
    for i in range(B,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
elif B<C<D:
    for i in range(A,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
else:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag = 1
            break
    if flag==1:
        print("No")
    else:
        flag = 1
        for i in range(B+1,D):
            if S[i]=="#":continue
            if (S[i-1]=="#" and S[i+1]=="#") or (S[i-2:i]=="#." and S[i+1]=="#") or (S[i-1]=="#" and S[i+1:i+3]==".#"):continue
            else:
                flag=0
                break
        if flag==1:
            if S[B+1]=="#" or (S[B-1]=="#" and S[B+1:B+3]==".#"):
                flag=1
            else:
                flag=0
        if flag==1:
            print("No")
        else:
            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)-1):
  if s[i]==s[i+1]=='#':
    print('No')
    exit()
if c>d:
  for i in range(b-2,d-1):
    if s[i]==s[i+1]==s[i+2]=='.':
      print('Yes')
      exit()
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

def f(x, y, s):
  tmp=[0]*(N+1)
  tmp[x]=1
  if s[x+1]=='.':
    tmp[x+1]=1
  i=x+2
  while i<=y:
    if s[i]=='.' and (tmp[i-2]==1 or tmp[i-1]==1):
      tmp[i]=1
    i+=1
  if tmp[y]>0:
    out=True
  else:
    out=False
    
  return out

if C<D:
  if f(A, C, S)==True and f(B, D, S)==True:
    print('Yes')
  else:
    print('No')
  exit()

def g(x, y, s):
  out=False
  for i in range(x, y+1):
    if s[i-1:i+2]=='...':
      out=True
  return out
  
if f(A, C, S)==True and f(B, D, S)==True and g(B, D, S)==True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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 A<C<B<D:
        for i in range(A-1,C-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return
        for i in range(B-1,D-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return     
        print(YES)
        return
    
    if A<B<C<D:
        for i in range(A-1,C-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return
        for i in range(B-1,D-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return     
        print(YES)
        return

    if A<B<D<C:
        for i in range(B-1,D):
            if S[i-1] == S[i] == S[i+1] == ".":
                print(YES)
                return   
        print(NO)
        return     

    return


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:
import sys
n, a, b, c, d = [int(i) - 1 for i in sys.stdin.readline().split()]
n += 1
s = input()
s_memo_ls = [0 for i in range(n)]
s_memo_ls[a] = 1
f_memo_ls = [0 for i in range(n)]
f_memo_ls[b] = 1

for i in range(a+1, c+1):
    if s[i] == "#":
        continue
    s_memo_ls[i] = max(s_memo_ls[i - 1], s_memo_ls[i - 2])
for i in range(b+1, d+1):
    if s[i] == "#":
        continue
    f_memo_ls[i] = max(f_memo_ls[i - 1], f_memo_ls[i - 2])

if s_memo_ls[c] and f_memo_ls[d]:
    flg = d > c
    for i in range(1, n - 1):
        if s[i-1] == s[i] == s[i+1] == ".":
            flg |= f_memo_ls[i] and s_memo_ls[i-1]
        if flg:
            break
    print("Yes" if flg else "No")
else:
    print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=["."]+list(input())
k=0
for i in range(a,c):
    if s[i]==s[i+1]=="#":
        k=1
for i in range(b,d):
    if s[i]==s[i+1]=="#":
        k=1
if d<c:
    for i in range(b,d+1):
        if s[i]==s[i-1]==s[i+1]==".":
            break
    else:
        k=1

if k==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, A, B, C, D = [int(_)-1 for _ in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
if C < D:
    if '##' in S[A:D]:
        print('No')
    else:
        print('Yes')
else:
    if '##' in S[A:C] or '...' not in S[B-1:D+2]:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

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

if c < d:
    if "##" in s[a:d]:
        print("No")
    else:
        print("Yes")
else:
    if "##" in s[a:c] or "..." 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())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
if "##" in s[a: c+1] or "##" in s[b:d+1]:
    print('No')
else:
    if c < d:
        print('Yes')
    else:
        if "..." in s[b-1: d+2]:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
def cd(a, b, c, d, s):
    for i in range(b, d + 1):
        if s[i] + s[i + 1] == "##":
            return "No"
    for i in range(a, c + 1):
        if s[i] + s[i + 1] == "##":
            return "No"
    return "Yes"


def dc(a, b, c, d, s):
    flag = False
    for i in range(b, d + 1):
        if s[i] + s[i + 1] == "##":
            return "No"
        if s[i - 1] + s[i] + s[i + 1] == "...":
            flag = True
    for i in range(a, c + 1):
        if s[i] + s[i + 1] == "##":
            return "No"
    if flag:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = input()+"##"

    if c < d:
        ans = cd(a, b, c, d, s)
    else:
        ans = dc(a, b, c, d, s)
    print(ans)

Submission status: Accepted

Solution code:
import sys
N,A,B,C,D = map(int, input().split())
S = input()
for i in range(N-1):
  if S[i] == S[i+1] == '#':
    if A < i+1 < C or B < i+1 < D:
      print("No")
      sys.exit()
if C>D:
  for i in range(N-2):
    if S[i] == S[i+1] == S[i+2] == '.':
      if B <= i+2 <= D:
        break
    if i == N-3:
      print("No")
      sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b, c, d = list(map(int, readline().split()))
    s = str(readline().rstrip().decode('utf-8'))
    if c == d:
        print("No")
    elif c < d:
        print("Yes" if s[a-1:d+1].count("##") == 0 else "No")
    elif c > d:
        print("Yes" if s[a-1:c+1].count("##") == 0 and s[b-2:d+1].count("...") != 0 else "No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B,C,D=map(lambda x: int(x)-1,input().split())
    N+=1
    S=list(input())
    S.append('#')
    if C>D:
        f=False
    else:
        f=True
    for i in range(A,C-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
        if D-1>=i>=B-1 and S[i]=='.' and S[i+1]=='.' and S[i+2]=='.':
            f=True
    for i in range(B,D-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
    print('Yes' if f==True else 'No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
A-=1
B-=1
C-=1
D-=1
def test(i,m):
    while i<N :
        if i==m:
            return(1)
        if i+1<N and S[i+1]==".":
            i+=1
        elif i+2<N and S[i+2]==".":
            i+=2
        else:
            return(0)
    return(0)


if C<D:

    if test(A,C) and test(B,D):
        print("Yes")
    else:
        print("No")
else:
    T=B-1
    if "..." in S[T:min(D+2,N-1)] and test(A,C) and test(B,D):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

for i in range(b,d+1):
    if i==1:
        continue
    if res[i-2]=="." and res[i-1]=="." and res[i]==".":
        print("Yes")
        exit()
    if res[i-1]=="#" and res[i]=="#":
        print("No")
        exit()
        
print("No")
exit()

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
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
x=[]
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
"""
if s[b+1]=="." and s[b-1]==".":
    print("Yes")
    exit()
if s[d-1]=="." and s[d+1]==".":
    print("Yes")
    exit()
"""
print("No")

Submission status: Accepted

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

ans=True
if "##" in S[A:C+1]:
  ans=False
if "##" in S[B:D+1]:
  ans=False

if (A-B)*(C-D)<0:
  commonL=max(A,B)
  if commonL>0:
    commonL-=1
  commonR=min(C,D)
  if commonL<len(S)-1:
    commonR+=1
  if commonR<commonL:
    ans=False
  elif "..." not in S[commonL:commonR+1]:
    ans=False

print(("No","Yes")[ans])

Submission status: Accepted

Solution code:
import sys


def main():
    n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    s = '#' + sys.stdin.readline().rstrip()

    if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]:
        ans = 'No'
    else:
        if c < d:
            ans = 'Yes'
        else:
            for i in range(b, d+1):
                if s[i-1] == s[i] == s[i+1] == '.':
                    ans = 'Yes'
                    break
            else:
                ans = 'No'
        
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019-11-22 19:46:21(JST)
import sys


def main():
    n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    s = '#' + sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019-11-22 19:46:21(JST)
import sys


def main():
    n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    s = '#' + sys.stdin.readline().rstrip()

    if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]:
        ans = 'No'
    else:
        if c < d:
            ans = 'Yes'
        else:
            for i in range(b, d+1):
                if s[i-1] == s[i] == s[i+1] == '.':
                    ans = 'Yes'
                    break
            else:
                ans = 'No'
        
    print(ans)

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:c] or "##" in s[b-1:d]:
    print("No")
elif c < d:
    print("Yes")
elif "..." in s[b-2:d+1]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    N, A, B, C, D = map(int, readline().split())
    S = readline().decode('UTF-8')
    A -= 1
    B -= 1
    C -= 1
    D -= 1

    if C < D:
        s = A
        g = D
        for i in range(s, g):
            if S[i:i+2] == "##":
                print('No')
                sys.exit()
        else:
            print('Yes')

    else:
        s = A
        g = C
        for i in range(s, g):
            if S[i:i+2] == "##":
                print('No')
                sys.exit()

        s = B
        g = D
        for i in range(s-1, g):
            if S[i:i+3] == "...":
                print('Yes')
                sys.exit()
        else:
            print('No')


main()