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:
def resolve():
  n, a, b, c, d = map(int, input().split())
  a -= 1
  b -= 1
  c -= 1
  d -= 1
  s = input()

  # a と c の間に ## があったらだめ
  for i in range(a, c):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # b と d の間に ## があったらだめ
  for i in range(b, d):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # a が b を飛び越えないと行けない場合  b - d の間に ... がないとだめ
  if b < c and d < c:
    flag = False
    for i in range(b-1, d):
      if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
        flag = True
    if not flag:
      print('No')
      return
  print('Yes')

  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    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")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B, C, D = mapint()
S = list(input())

def exp(idx, goal):
    while 1:
        if idx==goal:
            return True
        if idx+1<N and S[idx+1]==".":
            idx += 1
        elif idx+2<N and S[idx+2]=='.':
            idx += 2
        else:
            return False

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

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = list(input().strip())
S.insert(0,0)
if C<D:
    flag = 0
    for i in range(A+1,C+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    for i in range(B+1,D+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")
else:
    flag = 0
    for i in range(A+1,C+1):
        if S[i]=="#" and S[i-1]=="#":
            flag = 1
            break
    if flag == 0:
        flag1 = 1
        for i in range(B,D+1):
            if i+1<=N and S[i-1]=="." and S[i]=="." and S[i+1]==".":
                flag1 = 0
                break
        if flag1==1:
            flag = 1
    if flag==0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
S = list(S)
Flag = False
if D > C:
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")
else:
  P = False
  for i in range(B-2,D-1):
    if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
      P = True
  if not P:
    #print("unko")
    print("No")
    exit()
  #Flag = False
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,A,B,C,D = map(int,readline().split())
S = readline().rstrip()

if C < D:#抜かさなくて良い
    if "##" not in S[A-1:D]:
        print("Yes")
    else:
        print("No")
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 = list(input())
s.append(".")
a -= 1
b -= 1
c -= 1
d -= 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ランレングス圧縮
def rle_comp(S):
    rle = []
    pre = 'X'
    chain = 1
    for c in S:
        if c == pre:
            chain += 1
        else:
            if pre != 'X':
                rle.append([pre,chain])
            
            pre = c
            chain = 1
    rle.append([pre,chain])

    #print(rle)
    return rle

N,A,B,C,D = map(int,input().split())
S = input()
#S = S[:A-1] + 'A' + S[A:]
#S = S[:B-1] + 'B' + S[B:]
#print(S)
ans = "Yes"
#すぬけ君がふぬけ君を2マスジャンプで追い越しが不要な場合
if C < D:
    rle = rle_comp(S[A-1:D])
    for i in range(len(rle)):
        #2マスジャンプで岩をやりすごせるか判定
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"
#すぬけ君がふぬけ君を2マスジャンプで追い越しが必要な場合
else:
    rle = rle_comp(S[A-1:C])
    for i in range(len(rle)):
        #2マスジャンプで岩をやりすごせるか判定
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"

    space = False
    #ふぬけ君がスタート地点またはゴール地点にいる状態で追い越しをする場合を考慮するため
    #範囲を1つずつ広げる
    rle = rle_comp(S[B-2:D+1])
    for i in range(len(rle)):
        #追い越しができるか判定
        if rle[i][0] == '.' and rle[i][1] >= 3:
            space = True
    
    if space == False:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

# 連続した岩がないか
for i in range(a + 1, max(c, d) - 1):
    if s[i:i + 2] == '##':
        print('No')
        sys.exit()

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

else:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            print('Yes')
            sys.exit()
    print('No')

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

# 連続した岩がないか
for i in range(a + 1, max(c, d)):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

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

else:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            print('Yes')
            sys.exit()
    print('No')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    # 二個以上連続で岩があったら無理
    for i in range(A + 1, max(C, D)):
        if S[i] == S[i + 1] == "#":
            print("No")
            return

    # 追い抜かす必要がない
    if C < D:
        print("Yes")
        return
    else:
        # 追い抜かす必要がある
        # 3つ以上連続で岩が置かれていない区間があれば良い
        for i in range(B - 1, D):
            if S[i] == S[i + 1] == S[i + 2] == ".":
                print("Yes")
                return

        print("No")
        return


main()

Submission status: Accepted

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, a, b, c, d = MAP()
s = 'a' + input()

flag = 0
for i in range(min(a,b)+1,max(c,d)):
        if (a < i < c or b < i < d) and s[i] == s[i-1] == '#':
                print("No")
                exit()       
        elif max(a,b) <= i <= min(c,d) and s[i-1] == s[i] == s[i+1] == '.':
                flag = 1

if c > d and flag == 0:
        print("No")
else:
        print("Yes")

Submission status: Accepted

Solution code:
def iwa_check(start, end):
    for i in range(start, end):
        if s[i] == '#' and s[i + 1] == '#':
            return False
    return True


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

# 岩が2個並ぶ
if not iwa_check(a, c) or not iwa_check(b, d):
    print('No')
    exit()

# 追い越す場合
if c > d:
    ok = False
    for i in range(b, d + 1):
        if s[i - 1] == '.' and s[i] == '.' and s[i + 1] == '.':
            ok = True
            break
    if not ok:
        print('No')
        exit()

# 追い越さない
print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N,A,B,C,D = I()
S = s()
if "##" in S[A-1:C] or "##" in S[B-1:D]:
    print("No")
else:
    if C > D and "..." not in S[B-2:D+1]:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = input()
    for i in range(A-1,D):
        if S[i] == '#' and S[i+1] == '#':
            print('No')
            exit()
    
    if C < D:
        print('Yes')
        exit()
    
    for i in range(B-1,D):
        if D != len(S):
            if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
                print('Yes')
                exit()

    print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if a > b and c > d or a < b and c < d:
  if s[a - 1:c].count('##') + s[b - 1:d].count('##') == 0:
    print('Yes')
  else:
    print('No')
else:
  i, j = (b, d) if a < b else (a, c)
  if any(s[k - 1] == s[k] == s[k + 1] == '.' for k in range(i - 1, j)):
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
import sys
N, A, B, C, D = map(int, input().split())
s = input()
if C < D:
    for x, y in zip(s[A:], s[A+1:D]):
        if x == '#' and y == '#':
            print('No')
            sys.exit()
    print('Yes')
else:
    for x, y in zip(s[A:], s[A+1:C]):
        if x == '#' and y == '#':
            print('No')
            sys.exit()
    for x, y, z in zip(s[B-2:], s[B-1:], s[B:D+1]):
        if x == '.' and y == '.' and z == '.':
            print('Yes')
            sys.exit()
    print('No')

Submission status: Accepted

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

    if("##" in s[a-1:c] or "##" in s[b-1:d]):return 0
    if(d>c):
        return 1
    else:
        if("..." in s[b-2:d+1]):
            return 1
        else:
            return 0

if __name__ == '__main__':
    k=main()
    if(k):
        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')
else:
    if d<c and '...' not in s[b-2:d+1]:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
N, *AB = [int(x) for x in input().split()]
As, Bs, Ag, Bg = map(lambda x : x - 1, AB)
S = input()
for (s, g) in [(As, Ag), (Bs, Bg)]:
    if '##' in S[s : g + 1]:
        print("No")
        sys.exit()

if Bg < Ag:  # AがBを飛び越える必要がある
    if '...' not in S[Bs - 1 : Bg + 2]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

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

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	n,a,b,c,d = linput()
	S = "_" + input().rstrip()
	
	res = 1
	#if c<d:
	X = S[a:c].count("##")
	X += S[b:d].count("##")
	if X!=0: res=0
	
	if c>d:
		Y = S[b-1:d+2].count("...")
		if Y==0: res=0
	
	sT = "No Yes".split()
	print(sT[res])

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)-1]:
  print("No")
  exit()
if C < D:
  print("Yes")
  exit()

count = 0
for i in range(B-1,D):
  if D != len(S): 
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

g = groupby(s[a:c])
h = groupby(s[b:d])

for i, j in g:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

for i, j in h:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

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

e = groupby(s[b-2:d+1])
for i, j in e:
    if i == "." and len(list(j)) > 2:
        print("Yes")
        exit()

print("No")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, A, B, C, D = MAP()
S = input()

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, A, B, C, D = MAP()
S = list(input())

def cango(a, b):
	for i in range(a, b):
		if S[i] == "#" and S[i+1] == "#":
			return False
			break
	else:
		return True

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

else:
	for i in range(B-2, D-1):
		if S[i] == S[i+1] == S[i+2] == ".":
			S[i+1] = "#"
			break
	else:
		print("No")
		exit()

	if cango(A-1, C-1):
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=str(input())
s=list(s)
cnts=0
cnti=0
space=0
iwa=0
temp=0
next=0
if c<d:
  for i in range(a-1,d):
    if s[i]==".":
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
  if iwa>1:
    print("No")
  else:
    print("Yes")
else:
  for i in range(a-1,c):
    if s[i]==".":
      if i<=b-2:
        cnts=0
      cnts=cnts+1
      space=max(space,cnts)
      cnti=0
    else:
      cnti=cnti+1
      iwa=max(iwa,cnti)
      cnts=0
    if i==d-1:
      temp=space
      if s[i-1]=="." and s[i+1]==".":
        next=1
  if iwa>1:
    print("No")
  elif temp<3 and next==0:
    print("No")
  else:
    print("Yes")

Submission status: Accepted

Solution code:
import re
n, a, b, c, d = map(int, input().split())
road = input()
if c < d:
    if re.search('##', road[a:d]) is None:
        print('Yes')
    else:
        print('No')
 
elif c > d:
    if re.search('##', road[a:]) is None and re.search('\.\.\.', road[b-2:d+1]) is not None:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

flg = True
if A < B and C > D:
    flg = False
    for i in range(B-2, D-1):
        if S[i:i+3] == "...":
            flg = True
            break
if A > B and C < D:
    flg = False
    for i in range(A-2, C-1):
        if S[i:i+3] == "...":
            flg = True
            break
for i in range(A-1, C-2):
    if S[i:i+2] == "##":
        flg = False
        break
for i in range(B-1, D-2):
    if S[i:i+2] == "##":
        flg = False
        break

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

Submission status: Accepted

Solution code:
import re
n, a, b, c, d = map(int, input().split())
road = input()
if c < d:
    if re.search('##', road[a:d]) is None:
        print('Yes')
    else:
        print('No')

elif c > d:
    if re.search('##', road[a:]) is None and re.search('\.\.\.', road[b-2:d+1]) is not None:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

    ret = 'No'
    if C<D:
        pathBtoD=S[B-1:D]
        pathAtoC=S[A-1:C]
        if pathBtoD.find('##')==-1 and pathAtoC.find('##')==-1:
            ret = 'Yes'
    else:
        pathBtoD=S[B-1:D]
        pathAtoC=S[A-1:C]
        pathBtoD2 = S[B-2:D+1]
        if pathBtoD.find('##')==-1 and pathAtoC.find('##')==-1:
            if pathBtoD2.find('...')!=-1:
                ret = 'Yes'
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
#n=int(input())
n,a,b,c,d=map(int,input().split())
#a=[int(i) for i in input().split()]
s='_'+input()

ans=['Yes','No']

#print(s,n,a,b,c,d)

def CanGo(x,y):
    cnt=0
    root=s[x:y]
    for c in root:
        if c=='#':
            cnt+=1
        elif c=='.':
            if cnt>2:
                return False
            cnt=0
    return True


def CanPass(x,y):  #(b,d)
    root=s[x-1:y+2]
    '''
    q=s[x-1:x+2]
    print(root,q)
    print(root,len(root)-3+1)
    for i in range(len(root)-3+1):
        if q=='...':
            return True
        q=q[1:3]+s[x+3+i]
    '''
    if root.find('...')!=-1:
        return True
    return False
        


if c<d:
    if CanGo(b,d) and CanGo(a,c):
        ai=0
    else:
        ai=1
elif c>d:
    if CanGo(b,d) and CanGo(a,c) and CanPass(b,d):
        ai=0
    else:
        ai=1
    
    

print(ans[ai])

Submission status: Accepted

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

from sys import exit

# check
goal = max(C, D)
if "##" in S[A-1:goal]:
    print("No")
    exit()

if C < D:
    # Bから先に動く
    print("Yes")

else:
    # 入れ替わる必要がある

    # cehck : 初期値で入れ替えられる
    if "..." in S[B-2:D+1]:
    # if ('...' in S[B-1:D]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

from sys import exit

# check
goal = max(C, D)
if "##" in S[A-1:goal]:
    print("No")
    exit()

if C < D:
    # Bから先に動く
    print("Yes")

else:
    # 入れ替わる必要がある

    # cehck : 初期値で入れ替えられる
    # if "..." in S[B-2:D]:
    if ('...' in S[B-1:D]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

from itertools import groupby 

gr = groupby(s)

#AからCへいけるかどうか
for i in range(a-1,c-1):
    if s[i]=='#' and s[i+1]=='#':
        print('No')
        exit(0)
#BからDへいけるかどうか
for i in range(b-1,d-1):
    if s[i]=='#' and s[i+1]=='#':
        print('No')
        exit(0)


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

Submission status: Accepted

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

def move(a,s):
    ar = a
    while(ar<n-2):
        if(s[ar+2]=='.'):
            ar += 2
        elif(s[ar+1]=='.'):
            ar +=1
        else:
            break
    if(ar!=n-1):
        ar+=(s[ar+1]=='.')
    return ar

def pr_end(x):
    if(x):
        print('Yes')
    else:
        print('No')
    exit()

ar = move(a,s)
br = move(b,s)

if(c<d):
    if(c<=ar)&(d<=br):
        pr_end(1)
    else:
        pr_end(0)

for i in range(b-1,d):
    if(s[i:i+3] =='...'):
        if(c<=ar)&(d<=br):
            pr_end(1)
        else:
            pr_end(0)

pr_end(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [-2,1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if C<D:
    print("Yes")
  else:
    count = 0
    MAX = 0
    prev = 0
    for c in dB[B-2:min(D+1,N-1)]:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
      prev = c
    if MAX >= 3:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Submission status: Accepted

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or B,Dの間に3マス空きがない
  if ('...' in S[B-1:D]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
    ok = True
  else:
    ok = False
# 必要がない場合は問題ない

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
# @lru_cache(None)






N,A,B,C,D=l()
S=input()
if '##' in S[min(A, B)-1:max(D, C)]:
    print('No')
    quit()
 
if C < D:
    print('Yes')
else:
    if '...' in S[B-2:D+1]:
        print('Yes')
        quit()
    print('No')