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: Time Limit Exceeded

Solution code:
from collections import deque

N,A,B,C,D=(int(x) for x in input().split())
S=list(input())
sa=A-1
sb=B-1
ag=C-1
bg=D-1
count=0
stack=deque([[sa,sb]])
while stack:
    a,b=stack.pop()
    if a==ag and b==bg:
        count=1
        break
    for idoua,idoub in([1,0],[2,0],[0,1],[0,2]):
        na=a+idoua
        nb=b+idoub
        if na>ag or nb>bg:
            continue
        elif S[na]=='#' or S[nb]=='#' or na==nb:
            continue
        else:
            stack.append([na,nb])
if count==1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]

def Solution():
  for i in range(A,C):
    if S[i]*S[i+1]==1:
      return False
    for i in range(B,D):
      if S[i]*S[i+1]==1:
        return False
  if C<D:
    return True
  if C>D:
    for i in range(B,C-1):
      if S[i]+S[i+1]+S[i+2]==0:
        return True
    else:
      return False

if Solution():
  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')
    exit()

if C<D:
    print('Yes')
else:
    cnt=0
    for i in range(B-1,D):
        if S[i-1]==S[i] and S[i]==S[i+1] and S[i]=='.':
            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(A, C-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(B, D-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

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

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
canCross = False
for i, s in enumerate(S, start=1):
  if A < i < max(C, D) and s == '#' and (S[i-2] == '#' or S[i] == '#'):
    print('No')
    exit()
  if B <= i <= min(C, D) and s == '.' and S[i-2] == '.' and S[i] == '.':
    canCross = True
if C < D:
  print('Yes')
else:
  if canCross:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

kabe = S.find("##")
if kabe != -1:
    if kabe < C or kabe < D:
        print('No')
        exit()
if C < D:
    print('Yes')
else:
    A = S[:B].rfind(".")
    S = S[A:]
    B -= A
    C -= A
    D -= A
    A = 0
    irekae = S.find("...")
    if irekae == -1:
        print('No')
        exit()
    if irekae + 2 <= C and irekae < D:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from itertools import accumulate
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

N, A, B, C, D = mi()
S = input()
f = (not '##' in S[A-1:C]) and (not '##' in S[B-1:D])
if C > D:
    f = f and ('...' in S[B-2:D+1])

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

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = 'x' + input()
mx = D if D > C else C
if '##' in S[A:mx]:
    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 = input()
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif C>D:
    #print(S[B - 2:D + 1])
    if not '...' in S[B-2:D+1]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Accepted

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

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,min(d+1,n-1)):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    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:
    if "##" in s[a:c+1] or "##" in s[b:d+1]:
        print("No")
    else:
        print("Yes")
    exit()
else:
    if "##" in s[a:c+1] :
        print("No")
        exit()
    print("Yes" if "..." in s[b-1:d+2] else "No")

Submission status: Accepted

Solution code:
n,A,B,c,d=map(int,input().split())
s=input()
b=B-1
a=A-1
t=0
while t<2*n:
  if a!=c-1:
    if a+1<n and s[a+1]=='.' and a+1!=b:
      a+=1
    elif a+2<n and s[a+2]=='.' and a+2!=b and a+2<=c-1:
      a+=2
    else:
      if b+1<n and s[b+1]=='.' and b+1!=a:
        b+=1
      elif b+2<n and s[b+2]=='.' and b+2!=a and b+2<=d-1:
        b+=2
  else:
    if b!=d-1:
      if b+1<n and s[b+1]=='.' and b+1!=a:
        b+=1
      elif b+2<n and s[b+2]=='.' and b+2!=a and b+2<=d-1:
        b+=2
  t+=1
if a==c-1 and b==d-1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,d+2):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

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

def f(m,n):
    block2 = space3 = False
    b = s = 0
    for i in range(m-1,n):
        (b,s) = (b+1,0) if S[i]=='#' else (0,s+1)
        if not block2 and b==2:
            block2 = True
        if not space3 and s==3:
            space3 = True
    return block2, space3

if D<C:
    judge(not f(A,C)[0] and f(B-1,D+1)[1])
else:
    judge(not f(A,C)[0] and not f(B,D)[0])

Submission status: Accepted

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

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

ok = []
ng = []

for i in range(1, N - 1):
    if S[i] == S[i + 1] and S[i] == "#":
        ng.append(i)
    elif S[i - 1] == S[i] and S[i] == S[i + 1] and S[i] == ".":
        ok.append(i)

for ngi in ng:
    if (A < ngi and ngi < C) or (B < ngi and ngi < D):
        print("No")
        exit()

if C < D:
    print("Yes")

else:
    for oki in ok:
        if B <= oki and oki <= D:
            print("Yes")
            exit()

    print("No")

Submission status: Accepted

Solution code:
#58 A - Kenken Race
import sys
sys.setrecursionlimit(10**7)
N,A,B,C,D = map(int,input().split())
S = input()
A,B,C,D = A-1,B-1,C-1,D-1

# A が B を抜かせるエリア
if B == 1:
    a = S.find('...') + 1
else:
    a = S.find('...',3) + 1

dx = [1,2]

# 先に移動させる方の関数
def dfs_ini(v,seen_ini,X):
    seen_ini[v] = True# v を訪問済みにする
    for i in range(2):
        next_v = v + dx[i]
        # next_v が範囲外 or 壁の場合 or 他方が存在する場合
        if not(-1<next_v<N):
            continue
        if (S[next_v] == '#') or (next_v == X):
            continue
        if seen_ini[next_v] == True:# next_v が探索済みならスルー
            continue
        dfs_ini(next_v,seen_ini,X)

# 後に移動させる方の関数
def dfs_fin(w,seen_fin,Y):
    seen_fin[w] = True# w を訪問済みにする
    for j in range(2):
        next_w = w + dx[j]
        # next_w が範囲外 or 壁の場合 or 他方が存在する場合
        if not(-1<next_w<N):
             continue
        if (S[next_w] == '#')  or (next_w == Y):
             continue
        if seen_fin[next_w] == True:# next_w が探索済みならスルー
             continue
        dfs_fin(next_w,seen_fin,Y)

# A を先に動かした方がいいとき
# B を 先に a まで移動させる
if C>D:
    seen_ini_A = [False]*N
    seen_fin_B = [False]*N
    # B を抜かせるエリアがないとき、B の位置はスタート位置
    if (a < B) or (a > D):
        a = B
    dfs_ini(A,seen_ini_A,a)
    dfs_fin(B,seen_fin_B,C)
    result = 'No'
    if seen_ini_A[C] and seen_fin_B[D]:
        result = 'Yes'

# B を先に動かした方がいいとき
else:
    seen_ini_B = [False]*N
    seen_fin_A = [False]*N
    dfs_ini(B,seen_ini_B,A)
    dfs_fin(A,seen_fin_A,D)
    result = 'No'
    if seen_ini_B[D] and seen_fin_A[C]:
        result = 'Yes'

print(result)

Submission status: Accepted

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

S=input()
jump=False
n=0
R=0

for i in range(A-1,D):
    if S[i]=="#":
        R+=1
        n=0
        if R>=2:
            print("No")
            exit()
    else:
        n+=1
        R=0

b=0
S=S+"G"
for j in range(B-2,D+1):
    if S[j]==".":
        b+=1
        if b>=3:
            print("Yes")
            exit()
    else:
        b=0

if C<D:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    E = max(C, D)
    cnt = 0
    for i in range(A-1, E):
        if S[i] == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 2:
            print('No')
            return
    if C < D:
        print('Yes')
        return
    cnt = 0
    for i in range(B-2, D+1):
        if S[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            print('Yes')
            return
    print('No')
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(250000)


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


def check_reachable(N, S, start):
    reachable = [False for s in S]
    reachable[start] = True
    
    def _bfs(x):
        for d in [1, 2]:
            nx = x + d
            if 0 <= nx < N and not reachable[nx] and S[nx] == ".":
                reachable[nx] = True
                _bfs(nx)
    
    _bfs(start)
    return reachable


def solve(N, A, B, C, D, S):
    r1 = check_reachable(N, S, A)
    r2 = check_reachable(N, S, B)
    if r1[B] and r2[D]:
        if C < D:
            return "Yes"
        else:
            for i in range(B, D+1):
                if r2[i] and 0 <= i-1 < N and 0 <= i+1 < N and r1[i-1] and r1[i+1]:
                    return "Yes"
    return "No"
        


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
import sys
import math


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


def main():
    N, A, B, C, D = map(int, input().split())
    S = input()
    flag = 0
    b=B
    a =A
    while A < C:
        if flag ==1 and S[A]=="#":
            print("No")
            exit()
        elif S[A] =="#":
            flag =1
        else:
            flag =0

        A +=1

    while B < D:
        if flag ==1 and S[B]=="#":
            print("No")
            exit()
        elif S[B] =="#":
            flag =1
        else:
            flag =0

        B +=1

    if C>D:
        j=b-1
        while j<D:
            if S[j-1]=="." and S[j]=="." and S[j+1]==".":
                print("Yes")
                exit()
            j+=1
        print("No")
        exit()
    else:
        print("Yes")




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,A,B,C,D=list(map(int,input().split()))
l=list(input())
if "##" in "".join(l[A-1:max(C,D)-1]):
   print("No")
   exit()
if C>D:
   pass
else:
   print("Yes")
   exit()
if "..." in "".join(l[B-2:D+1]):
   print("Yes")
else:
   print("No")

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,a,b,c,d = LI()
    s = "#" + S()
    ans = True
    if a<b and b<c and c<d:
        ans &= "##" not in  s[b:d]
        ans &= "##" not in  s[a:c]
    elif a<b and b<d and d<c:
        ans &= "##" not in  s[b:d]
        ans &= "..." in s[b-1:d+2]
        ans &= "##" not in  s[a:c]
    elif a<c and c<b and b<d:
        ans &= "##" not in  s[b:d]
        ans &= "##" not in  s[a:c]
    
    print("Yes" if ans else "No")
    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
##agc034_a
N,A,B,C,D = map(int, input().split()) #A→C、B→D #4≤N≤200,000
S = [0] + list(input())

#すれ違うには . の3連続が必要
#すれ違わなくても、#が2連続であるとアウト

#すれ違いが必要かを判定する
#  A<B
#  A<C
#  B<D
#を利用すると下記の3パターンしかない。
if A < B < D < C:
    need_passing = True
elif (A < B < C < D) or (A < C < B < D):
    need_passing = False

#下記のように考える
#すれ違いが必要
    #Yes
        #すれ違い可能点(. . .)を列挙
        #A/B→すれ違い可能点へ行ける = 左記の区間に # # な並びがない
            #すれ違い可能点→C/Dへ行ける? = 左記の区間に # # な並びがない
    #No
        #A→CとB→Dで通行可能 = 左記の区間に # # な並びがない

passing_point_set = set() #すれ違い場所の始点のset
imos_stop = list() # "#"が2連続している場所で増加する。
imos_stop.append(0)

for i in range(1,N-1):
    if S[i] == S[i+1] == "#":
        imos_stop.append(imos_stop[-1] + 1)
    else:
        imos_stop.append(imos_stop[-1])

    if S[i] == S[i+1] == S[i+2] == ".":
        passing_point_set.add(i)

i = N-1
if S[i] == S[i+1] == "#":
    imos_stop.append(imos_stop[-1] + 1)
else:
    imos_stop.append(imos_stop[-1])
#i = N
#右側はない。
imos_stop.append(imos_stop[-1]) #   .##.

#print(imos_stop)
#print(passing_point_set)

def is_reachable(start,goal):
    if imos_stop[start] == imos_stop[goal] and start <= goal: #右に1か2マスにジャンプさせる ∴右方向にしか進めない
        return True
    else:
        return False

if need_passing == True: #A < B < D < C が成立している
    for passing_point in passing_point_set:
        if ((is_reachable(A,passing_point) == True and is_reachable(passing_point,C) == True and is_reachable(B,passing_point) == True and is_reachable(passing_point,D) == True and D != passing_point) or
            (B-1 in passing_point_set and is_reachable(A,C) == True and is_reachable(B,D) == True)):
            #passing pointの範囲内にDがある場合、passingできない場合がある
            #ex.   A#..D#  …これはOK。A#.BD#.  として、追い抜かせてからB→D
            #ex.   A#.D.# …これはOK。ただし、.D.がpassing_pointになる
            #ex.   A#D..#  …NG
                #↓のパターンが考察不足だった
                #  ##AB.#D..#C#  …start <= goal条件により、追い越し不可扱いになるが実際はできる
                #  ##A.B#D..#C#  …これはNG
                #  ##A.B#.D.#C#  …これはOK。.D.がpassing_pointになる
                #  ##A.B.#D..#C# …これはOK
            
            print("Yes")
            break
    else:
        print("No")
else:
    if is_reachable(A,C) == True and is_reachable(B,D) == True:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, a, b, c, d = inintm()
s = input()

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc034/tasks/agc034_a

import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b, c, d = input_int_list()
    S = input()

    for i in range(a - 1, max(c, d) - 1):
        if S[i] == S[i + 1] == "#":
            print("No")
            quit()
    if c < d:
        print("Yes")
        quit()
    if c > d:
        for i in range(b - 2, d - 1):
            if S[i: i + 3] == "...":
                print("Yes")
                quit()
        print("No")
        quit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
for i in range(A - 1, max(C, D) - 1):
    if S[i] == S[i + 1] == '#':
        print("No")
        exit()

if C < D:
    print("Yes")
else:
    for i in range(B - 2, D - 1):
        if S[i:i + 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

if '##' in s[a:max(c,d)+1]:
    print('No')
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

if "##" in s[b:d+1]:
    print("No")
    exit()

if c>d:
    if not "..." in s[b-1:d+2]:
        print("No")
        exit()
    
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 + 1]:
        print("No")
    else:
        print("Yes")
else:
    if "##" in S[A: D + 1] 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()

if '##' in s[a-1:c] or '##' in s[b-1:d]:
    print('No')
else:
    if 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=list(input())
ch=0
ch1=0

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

Submission status: Accepted

Solution code:
import sys

# A - Kenken Race
def can_goal(start, goal):
	global S

	way = S[start:goal+1]

	if not '##' in way:
		return True


def can_go_halfway(start, goal):
	global S

	way = S[start:goal+1]

	if way.find('...') > -1:
		return True


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

if C < D:
	if can_goal(B, D):
		if can_goal(A, C):
			print('Yes')
			exit()
else:
	if can_go_halfway(B - 1, D + 1):
		if can_goal(A, C):
			if can_goal(B, D):
				print('Yes')
				exit()

print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = [int(_) for _ in 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:
n, a, b, c, d = list(map(int, input().split()))
s = input()

last = "."
for i in range(a, max(c, d)):
    if last == "#" and s[i] == "#":
        print("No")
        exit()
    last = s[i]

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

            if length == 3:
                print("Yes")
                exit()
        else:
            length = 0

    print("No")

Submission status: Accepted

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

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

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

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

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())
CanReach = True
CanChange = False
for i in range(A,C):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
for i in range(B,D):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
if C < D:
    CanChange = True
else:
    for i in range(B,D+1):
        if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
            CanChange = True
if CanReach and CanChange:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = '#' + s + '#'

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

if not can_reach(a, b) or not can_reach(b, d):
    print('No')
    exit()

if c > d:
    can_over = False
    for i in range(b, d+1):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            can_over = True
    if not can_over:
        print('No')
        exit()

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

s += '#'

flg = True
ok = False
cnt = 0
for i in range(b, d):
    if s[i] == '#':
        cnt = 0
        if s[i+1] == '#':
            flg = False
    else:
        cnt += 1
        if cnt == 3:
            ok = True     
if cnt + 1 == 3:
    ok = True

if s[b-1] == '.' and s[b] == '.' and s[b+1] == '.':
    ok = True

if s[d-1] == '.' and s[d] == '.' and s[d+1] == '.':
    ok = True

for i in range(a, c):
    if s[i] == '#' and s[i+1] == '#':
        flg = False

if c < d:
    print('Yes' if flg else 'No')

else:
    print('Yes' if flg and ok else 'No')

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = list(input())
for i in range(min(a,b),max(c,d)):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        quit()
if c < d:
    print("Yes")
elif c > d:
    for j in range(b-1,d):
        if s[j] == "." and s[j+1] == "." and s[j-1] == ".":
            print("Yes")
            quit()
    print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d=list(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(0)
    print('Yes')
else:
    for i in range(b-1,d):
        if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a-1,c-1):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,A,B,C,D =MI()
    S=input()
    A-=1
    B-=1
    C-=1
    D-=1
    
    flag=1
    if "##" in S[A:C+1]:
        flag=0
    if "##" in S[B:D+1]:
        flag=0
        
    if C>D:
        if "..." in S[B-1:D+2]:
            pass
        else:
            flag=0
            
    if flag:
        print("Yes")
    else:
        print("No")
        

main()

Submission status: Accepted

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

for i in range(a,max(c,d)-1):
        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] == s[i-1] == s[i] == ".":
            print("Yes")
            exit()
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

if "##" in S[A-1:max(C-1,D-1)]:
    print("No")
elif D < C 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(input())
jud = True

for i in range(min(a, b) - 1, max(c, d) - 1):
    if s[i] == "#":
        if s[i + 1] == "#":
            jud = False
            break

if (a < b and c > d and jud) or (a > b and c < d and jud):
    jud = False
    for i in range(max(a, b) - 2, min(c, d) - 1):
        if s[i] == ".":
            if s[i + 1] == "." and s[i + 2] == ".":
                jud = True

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(a,b,c,d,s):
  if '##' in s[a:c+1] or '##' in s[b:d+1]:
    return False
  if c < d:
    return True
  elif c > d:
    if "..." in s[b-1:d+2]:
      return True
    else:
      return False
  else:
    raise ValueError




def main():
  N,A,B,C,D = map(int,input().split())
  A -= 1
  B -= 1
  C -= 1
  D -= 1
  S = input()
  print("Yes" if solve(A,B,C,D,S) else "No")
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, A, B, C, D = LI()
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    S = SS()

    ## 移動経路に2連続以上の岩があったらダメ
    if '##' in S[A:C+1] or '##' in S[B:D+1]:
        print('No')
    else:
        ## ふぬけ君を先に移動させればいい
        if C < D:
            print('Yes')
        ## ふぬけ君を飛び越えられる瞬間が存在すればいい
        else:
            # どこかに3以上の隙間があること
            if '...' in S[B-1:D+2]:
                print('Yes')
            else:
                print('No')

if __name__ == '__main__':
    resolve()