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:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B, C, D = lr()
S = input()
# if C > D:
#     if "..." not in S[B-1:D]:
#         print("No")
#         exit(0)
# if "##" in S[A-1:C] or "##" in S[B-1:D]:
#     print("No")
# else:
#     print("Yes")

# ans = "Yes"
# if C > D:
#     tmp = S[B-2:D+1].count("...")
#     if tmp == 0:
#         ans = "No"

# tmp = S[A-1:max(C, D)].count("##")
# if tmp > 0:
#     ans = "No"
# print(ans)

ans="Yes"

if D<C:
  if "..." not in S[B-2:D+1]:
    ans="No"

if "##" in S[A-1:max(C,D)]:
  ans="No"

print(ans)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B, C, D = lr()
S = input()
# if C > D:
#     if "..." not in S[B-1:D]:
#         print("No")
#         exit(0)
# if "##" in S[A-1:C] or "##" in S[B-1:D]:
#     print("No")
# else:
#     print("Yes")

ans = "Yes"
if C > D:
    tmp = S[B-2:D+1].count("...")
    if tmp == 0:
        ans = "No"

tmp = S[A-1:max(C, D)].count("##")
if tmp > 0:
    ans = "No"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def dfs(start, end):
    q = [start-1]
    while q:
        s = q.pop()
        if s==end-1:
            return True
        if s+2<N and S[s+2]==".":
            q.append(s+2)
        if s+1<N and S[s+1]==".":
            q.append(s+1)
    return False


res = dfs(A, C) and dfs(B, D)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    _, A, B, C, D = map(int, input().split())
    S = input().rstrip("\r\n")
    ans = "Yes"
    for i in range(A-1,C-1):
        if S[i] == "#" and S[i+1] == "#":
            ans = "No"
            break
    for i in range(B-1,D-1):
        if S[i] == "#" and S[i+1] == "#":
            ans = "No"
            break
    if C < D or ans == "No":
        print(ans)
    else:
        ans = "No"
        for i in range(B-1, D):
            if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
                ans = "Yes"
        print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

def dfs(snuke,fnuke):
    global n,a,b,c,d,s
    que = deque()
    que.append([snuke,fnuke])
    lq = 1
    while(lq > 0):
        tmp = que.pop()
        tmps = tmp[0]
        tmpf = tmp[1]
        lq-=1
        if tmps == c and tmpf == d:
            return True
        if tmps+1 != tmpf and s[tmps] =="." and tmps != c:
            que.append([tmps+1,tmpf])
            lq+=1
        elif tmps+2 != tmpf and s[tmps+1] =="." and tmps != c:
            que.append([tmps+2,tmpf])
            lq+=1
        elif tmpf+1 != tmps and s[tmpf] =="." and tmpf != d:
            que.append([tmps,tmpf+1])
            lq+=1
        elif tmpf+2 != tmps and s[tmpf+1] =="." and tmpf != d:
            que.append([tmps,tmpf+2])
            lq+=1
    return False

n,a,b,c,d = map(int,input().split())
s = input()
s += "###"
snuke = a
fnuke = b
if dfs(snuke,fnuke):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N,A,B,C,D = map(int,input().split())
s = list(input())
ok = False

# AC間、BD間、に連続した岩がなければ良い
#print (s)
for i in range(A-1,C):
#    print (s[i-1:i+1])
    if s[i-1:i+1] == ["#","#"]:
        print ("No")
        exit ()

#print (s)
for i in range(B-1,D):
#    print (s[i-1:i+1])
    if s[i-1:i+1] == ["#","#"]:
        print ("No")
        exit ()


# C > D の場合
# BD間に連続した3つの空きがあれば良い
if C < D:
    ok = True
else:
#    print (s)
    for i in range(B-1,D):
#        print (s[i-1:i+2])
        if s[i-1:i+2] == [".",".","."]:
            ok = True
            break

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

Submission status: Accepted

Solution code:
n,a,b,c,d = [int(x) for x in input().split()]
s = input()

ans = "Yes"
if c > d:
    tmp = s[b-2:d+1].count("...")
    if tmp == 0:
        ans = "No"

tmp = s[a-1:max(c,d)].count("##")
if tmp > 0:
    ans = "No"
print(ans)

Submission status: Accepted

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

for i in range(A-1,C):
    if S[i] == '#' and S[i+1] == '#':
        print('No')
        exit()

for ii in range(B-1,D):
    if S[ii] == '#' and S[ii+1] == '#':
        print('No')
        exit()

if C > D:
    for j in range(B-1,D):
        if S[j-1] == '.' and S[j] == '.' and S[j+1] == '.':
            print('Yes')
            exit()

    print('No')
    exit()

else:
    print('Yes')
    exit()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

"""
A<Bとする。
C<Dの場合：
A～CとB~Dの間に"##"が無ければ達成できる.
C>Dの場合：
上記に加え、B~Cの間に"..."が存在すれば達成できる
"""

n,a,b,c,d = map(int,readline().split())
s = readline().rstrip().decode('utf-8')
a,b,c,d = a-1,b-1,c-1,d-1

flag = 1
space = 0
res = 0
rock = 0
for i in range(a,c+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
for i in range(b,d+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
if c > d:
	for i in range(b-1,d+2):
		if s[i] == ".":
			space += 1
		else:
			res = max(res,space)
			space = 0
	res = max(res,space)
	if res < 3:
		flag = 0

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

Submission status: Accepted

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

str_ac = str[A-1:C]
str_bd = str[B-1:D]
str_bd2 = str[B-2:D+1]
#print(str_bd)
#print(str_ac)
#print(str_bd2)

if C<D:
  if str_bd.find("##")!=-1 or str_ac.find("##")!=-1:
    print("No")
  else:
    print("Yes")
else:
  if str_bd.find("##")!=-1 or str_ac.find("##")!=-1:
    print("No")
  else:
    if str_bd2.find("...")!=-1:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = list(map(int, input().split()))
a,b,c,d = a-1,b-1,c-1,d-1 #indexに合わせる
s = input()
k = 0
swappable = False
possible = True

#A-C, B-D に岩が二つ並んでいる箇所があるなら不可能

#C>Dの場合B以上の位置で3マス以上の空白があれば
for i in range(a, max(c,d)):#+1):
    j = s[i]
    if j=='#':
        if (k==0) and ((a<i<c) or (b<i<d)):
            possible = False
            break
        k = 0
    if j=='.':
        k += 1
        if (k>=3) and (b<i<=(d+1)):
            swappable = True
    

if (c>d) and (not swappable):
    possible = False

print('Yes' if possible else '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, radians
from itertools import accumulate, permutations, combinations, 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
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

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

S = input()

if S[A:max(C, D)].count("##") >= 1:
    print("No")
    exit()

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

if S[B-2:D+1].count("...") >= 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

flag = True
for i in range(A, C):
    if S[i] == "#" and S[i + 1] == "#":
        flag = False
        break
else:
    for i in range(B, D):
        if S[i] == "#" and S[i + 1] == "#":
            flag = False
            break

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

Submission status: Accepted

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


if __name__ == "__main__":
  main()

Submission status: Accepted

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

a = A-1
b = B-1
c = C-1
d = D-1

ans = 1

for i_a in range(a,C):
  #2連続の##がa~Cにないことを確認
  if S[i_a] == "#":
    if S[i_a+1] == "#":
      ans =0

for i_b in range(b,D):
  #2連続の##がb~Dにないことを確認
  if S[i_b] == "#":
    if S[i_b+1] == "#":
      ans =0

if D < C:
  ans = 0
  for i in range(b,D):
    #3連続があるなら1
    if S[i-1] == ".":
      if S[i] == ".":
        if S[i+1] == ".":
          ans = 1

if ans ==1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
a=1
for i in range(A,C-2):
    if S[i]==S[i+1]=="#":
        a=0
        break
for i in range(B,D-2):
    if S[i]==S[i+1]=="#":
        a=0
        break
if C>D:
    for i in range(B-1,D):
        if S[i-1]==S[i]==S[i+1]==".":
            break
    else:
        a=0
print("Yes" if a else "No")

Submission status: Accepted

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

res = 'Yes'

for i in range(a-1, c-1):
    if s[i] == s[i+1] == '#':
        res = 'No'
        break

if res != 'No':
    if c < d:
        for i in range(b-1, d-1):
            if s[i] == s[i+1] == '#':
                res = 'No'
                break
    else:
        for i in range(b-2, d-1):
            if s[i] == s[i+1] == s[i+2] == '.':
                break
        else:
            res = 'No'

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

if D<C:
  triple = S[B-2:D+1].count("...")
  if triple ==0:
    ans="No"

double= S[A-1:max(C,D)].count("##")
if double > 0:
  ans="No"
  
print(ans)

Submission status: Accepted

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

cant = False
if c>d:
        cant = True
        for i in range(max(0,b-2), min(d-1, n-2)):
                if s[i]==s[i+1]==s[i+2]=='.': cant = False

for i in range(b-1, d-1):
        if s[i]==s[i+1]=='#': cant = True
for i in range(a-1, c-1):
        if s[i]==s[i+1]=='#': cant = True

print("YNeos"[cant::2])

Submission status: Accepted

Solution code:
from collections import deque

def solve():
    n,a,b,c,d = map(int,input().split())
    s = input()
    # aからcに到達可能か
    flag1 = True
    # bからcに到達可能か
    flag2 = True
    # 反転しているとき、到達可能な範囲に...は存在するか
    flag3 = False
    cnt = 0
    for i in range(a-1,c):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag1 = False
    cnt=0
    for i in range(b-1,d):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag2 = False
    l = max(a,b)
    r = min(c,d)
    if r<n and s[r]!='#':
        r+=1
    if l-2>=0 and s[l-2]!='#':
        l-=1
    for i in range(l-1,r):
        if s[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt>=3:
            flag3 = True

    if flag1 and flag2:
        if c<d:
            print('Yes')
        else:
            if flag3:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
        
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# Problem A - Kenken Race

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

# initialization
is_ok = True

# search
if C>D:
    # b check
    if "##" in S[B-1:D] or not "..." in S[B-2:D+1]:
        is_ok = False

    # a check
    if "##" in S[A-1:C]:
        is_ok = False
else:
    # b check
    if "##" in S[B-1:D]:
        is_ok = False

    # a check
    if "##" in S[A-1:C]:
        is_ok = False

# output
if is_ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from collections import deque
def solve():
    n,a,b,c,d = map(int,input().split())
    s = input()
    # aからcに到達可能か
    flag1 = True
    # bからcに到達可能か
    flag2 = True
    # 反転しているとき、到達可能な範囲に...は存在するか
    flag3 = False
    cnt = 0
    for i in range(a-1,c):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag1 = False
    cnt=0
    for i in range(b-1,d):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag2 = False
    l = max(a,b)
    r = min(c,d)
    if r<n and s[r]!='#':
        r+=1
    if l-2>=0 and s[l-2]!='#':
        l-=1
    for i in range(l-1,r):
        if s[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt>=3:
            flag3 = True

    if flag1 and flag2:
        if c<d:
            print('Yes')
        else:
            if flag3:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = str(input())
if C < D:
    if '##' in S[min(A, B):D]:
        print('No')
    else:
        print('Yes')
elif C > D:
    if '##' in S[min(A, B):C]:
        print('No')
    else:
        # ここの添字は図を書いて理解してください
        if '...' in S[B - 2:D + 1]:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

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


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
tri = 0
for i in range(min(A, B) - 1, max(C, D) - 1):
  if S[i] == "#" and (S[i + 1] == "#"):
    print("No")
    exit(0)
for i in range(max(A, B) - 1, min(C, D)):
  if S[i] == "." and (S[i - 1] == ".") and (S[i + 1] == "."): tri = 1
if C <= D:
  print("Yes")
else:
  if tri: print("Yes")
  else: print("No")

Submission status: Accepted

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

def check_one_people_can(start, end):
    s = S[start+1: end]
    before_sharp = False
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start-1: end+2]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, D) and check_one_people_can(A, C):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def main():
    N, a, b, c, d = (int(i) for i in input().split())
    S = input()
    if "##" in S[a:c] or "##" in S[b:d]:
        return print("No")
    if c < d:
        return print("Yes")
    # d < c
    if "..." in S[b-2:d+1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, a, b, c, d = MAP()
s = STR()

dp1 = [inf for _ in range(n + 1)]
dp1[a] = 0
dp1[a - 1] = 0
for i in range(a + 1,c + 1):
    if s[i - 1] == '.':
        dp1[i] = min(dp1[i - 1], dp1[i - 2]) + 1
dp2 = [inf for _ in range(n + 1)]
dp2[b] = 0
dp2[b - 1] = 0
for i in range(b + 1, d + 1):
    if s[i - 1] == '.':
        dp2[i] = min(dp2[i - 1], dp2[i - 2]) + 1

if a < b and c < d or a > b and c > d:
    if dp1[c] < inf and dp2[d] < inf:
        print('Yes')
    else:
        print('No')
else:
    if a > b and c < d:
        a, b = b, a
        c, d = d, c
    flag = False
    for i in range(b, d + 1): #抜かす場所
        if s[i - 2:i + 1] == '...': #抜かせる
            flag = True
            break
    if dp1[c] < inf and dp2[d] < inf and flag:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

def isOk(fr, to):
    if S[fr: to + 1].count('##') > 0:
        return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

def canSwitch():
    if S[max(A, B) - 1: min(C, D) + 2].count('...'):
        return True
    return False

if A < B and D < C or B < A and C < D:
    if not canSwitch():
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

def isOk(fr, to):
    if S[fr: to + 1].count('##') > 0:
        return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

def canSwitch():
    if A + 1 == B and D < C and S[A: A + 3] == '...':
        return True
    if B + 1 == A and C < D and S[B: B + 3] == '...':
        return True
    if C + 1 == D and B < A and S[C - 1: D + 1] == '...':
        return True
    if D + 1 == C and A < B and S[D - 1: C + 1] == '...':
        return True
    if A < B and S[B - 1: B + 2] == '...':
        return True
    if B < A and S[A - 1: A + 2] == '...':
        return True
    if C < D and S[C - 1: C + 2] == '...':
        return True
    if D < C and S[D - 1: D + 2] == '...':
        return True
    if S[max(A, B): min(C, D) + 1].count('...'):
        return True
    return False

if A < B and D < C or B < A and C < D:
    if not canSwitch():
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

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

def can(start, end):
    for i in range(start, end):
        if S[i] == S[i + 1] == "#":
            return False
    return True

def main():
    if not (can(A, C) and can(B, D)):
        return False

    if C < D:
        return True
    elif C > D:
        for i in range(B, D + 1):
            if S[i - 1] == S[i] == S[i + 1] == ".":
                return True
        return False

if __name__ == "__main__":
    if main():
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

if "##" in S[B: D - 1]:
    print("No")
    exit()
elif "##" in S[A: C - 1]:
    print("No")
    exit()

if D < C:
    if not "..." in S[B - 2: D + 1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

if c<d:
    if s[a-1:d].find("##")!=-1:
        print("No")
    else:
        print("Yes")

else:
    if s[a-1:c].find("##")!=-1:
        print("No")
    else:
        if s[b-2:d+1].find("...")!=-1:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

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

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-2, b-1):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if C == D:
    ans = False
if not can_reach(A, C) or not can_reach(B, D):
    ans = False
if C > D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, a, b, c, d = input_list()
  s = input()
  dp = []
  has_space = False
  if s[c-1] == '#':
    print('No')
    exit(0)
  if s[d-1] == '#':
    print('No')
    exit(0)
  if c < d:
    for i in range(a-1, c):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
    for i in range(b-1, d):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
  else:
    for i in range(a-1, c):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
     
    for i in range(b-1, d):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
      if s[i-1] == '.' and s[i+1] == '.' and s[i] == '.':
        has_space = True
    if has_space is False:
      print('No')
      exit(0)

  print('Yes')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Accepted

Solution code:
import sys
n, a, b, c, d = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()

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

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

Submission status: Accepted

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



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

elif c == d:
    print("No")

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

Submission status: Accepted

Solution code:
# Problem A - Kenken Race

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

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

Submission status: Accepted

Solution code:
import sys
n, a, b, c, d = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()

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

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