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:
l = input().split()
N = int(l[0])
A = int(l[1])
B = int(l[2])
C = int(l[3])
D = int(l[4])
l = input().split()
S = l[0]

# print(N, A, B, C, D, S)

def blocked(path):
    return '##' in path

def cleared(path):
    return '...' in path

def find_path(A, B, C, D, S):
    s_path = S[A:C]
    f_path = S[B:D]
    if blocked(s_path) or blocked(f_path):
        return False
    return True

def solve(A, B, C, D, S):
    if not find_path(A, B, C, D, S):
        return False
    begin = B - 2
    end = D - 2 if S[D - 2] == '#' else C
    return cleared(S[begin:end])

ret = True
if C < D:
    ret = find_path(A, B, C, D, S)
else:
    ret = solve(A, B, C, D, S)

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

Submission status: Accepted

Solution code:
l = input().split()
N = int(l[0])
A = int(l[1])
B = int(l[2])
C = int(l[3])
D = int(l[4])
l = input().split()
S = l[0]

# print(N, A, B, C, D, S)

def blocked(path):
    return '##' in path

def find_path(A, B, C, D, S):
    s_path = S[A:C]
    f_path = S[B:D]
    if blocked(s_path) or blocked(f_path):
        return False
    return True

def solve(A, B, C, D, S):
    if not find_path(A, B, C, D, S):
        return False
    begin = B - 2
    if S[D - 2] == '#':
        if '...' in S[begin:D - 2]:
            return True
        else:
            return False
    else:
        path = S[begin:C]
        if '...' in path:
            return True
    return False

ret = True
if C < D:
    ret = find_path(A, B, C, D, S)
else:
    ret = solve(A, B, C, D, S)

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

Submission status: Accepted

Solution code:
def a_kenken_race(N, A, B, C, D, S):
    # cond1: 道のりの途中に岩が2つ連続する場所があると、ゴールに到達できない
    # cond2: ふぬけ君の道のりの途中に空きが3マス分ないと、すぬけ君が追い越せない
    cond1 = '##' in S[A - 1:C] or '##' in S[B - 1:D]
    cond2 = '...' not in S[B - 2:D + 1]

    if cond1:
        ans = 'No'
    elif C > D and cond2:
        ans = 'No'
    else:
        ans = 'Yes'  # ふぬけ君から順にゴールさせる/すぬけ君が追い越す ことができる
    return ans

N, A, B, C, D = [int(i) for i in input().split()]
S = input()
print(a_kenken_race(N, A, B, C, D, S))

Submission status: Accepted

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

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

Submission status: Accepted

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

    answer = "-1"

    if C < D:
       if S[A:D:].count("##") >= 1:
           answer = "No"
       else:
           answer = "Yes"
    else:

        answer = "No"
        for x in range(B, D+1):
            if (S[x-2] == "." and S[x-1] == "." and S[x] == "."):
               answer = "Yes"

    print(answer)

Submission status: Accepted

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


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]):
        print('No')
        exit()

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

    print('Yes')


if __name__ == '__main__':
    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

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

Submission status: Accepted

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

flag = True
if "##" in S[A+1:max(C, D)]:
    flag = False
if C > D:
    if "..." not in S[B-2:D+1]:
        flag = False

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)
 
N, A, B, C, D = map(int, input().split())
s = list(input())
 
A -= 1
B -= 1
C -= 1
D -= 1
 

if D < C:
    tmp = 0
    for i in range(len(s)):
        if i == len(s) - 2 or i == len(s) - 1:
            continue
        else:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' and B <= i + 1 <= D:
                tmp = 1
    if tmp != 1:
        print("No")
        exit()
 
 
 
def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans
 
ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

flag = True
if "##" in S[A:max(C, D)]:
    flag = False
if C > D:
    if "..." not in S[B-2:D+1]:
        flag = False

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

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, A, B, C, D = mi()
#S[0~N-1]でアクセス
cells = input()

#全部0~N-1ベースにする
A -= 1
B -= 1
C -= 1
D -= 1

ans = '?'

goal = max(C,D)


rockcheck = 0 #直前が岩なら1
for i, cell in enumerate(cells):
  if i < A or goal < i: continue
  if rockcheck == 1 and cell == '#':
    ans = 'No'
    break
  elif cell == '#': rockcheck = 1
  else: rockcheck = 0

#C<Dならflag=0, D<Cならflag=1
if C < D: flag = 0
else: flag = 1

if ans == 'No':
  print('No')
  exit()
elif flag == 0: #C<Dならこの時点で勝ち確
  print('Yes')
  exit()
#そうでなければ戦いは続く

ans = 'No'
#C<Dの場合決着がついているので、ここからは必ずD<C
#かつ、##は無いことが保証されている
blankcheck = 0 #直前が.なら1, 直前が..なら2
for i, cell in enumerate(cells):
  if i < (B-1) or (D+1) < i: continue
  if cell == '.': blankcheck += 1
  else: blankcheck = 0
  if blankcheck == 3:
    ans = 'Yes'
    break

print(ans)

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
def f(x,y):
  return "##" not in s[x:y-1]
if c<d:
  print("Yes" if f(a,c) and f(b,d) else "No")
else:
  if f(a,c)==False or f(b,d)==False:
    print("No")
  else:
    if "..." in s[b-2:d+1]:
      ans=True
    else:
      ans=False
    print("Yes" if ans==True else "No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Kenken Race
https://atcoder.jp/contests/agc034/tasks/agc034_a

"""
import sys


def solve(N, A, B, C, D, S):
    p_A = set([A])
    for p, n1, n2 in zip(range(A, C), S[A+1:], S[A+2:]):
        if p in p_A:
            if n1 == '.' and p+1 <= C:
                p_A.add(p+1)
            if n2 == '.' and p+2 <= C:
                p_A.add(p+2)

    p_B = set([B])
    for p, n1, n2 in zip(range(B, D), S[B+1:], S[B+2:]):
        if p in p_B:
            if n1 == '.' and p+1 <= D:
                p_B.add(p+1)
            if n2 == '.' and p+2 <= D:
                p_B.add(p+2)

    p_t = set()
    for p, p1, p2, p3 in zip(range(B, N+1), S[B-1:D], S[B:D+1], S[B+1:]):
        if p1 == '.' and p2 == '.' and p3 == '.' and p <= D:
            p_t.add(p)

    if C < D:
        if C in p_A and D in p_B:
            return 'Yes'
        return 'No'
    else:
        if (C in p_A) and (D in p_B) and (p_B & p_t):
            return 'Yes'
        return 'No'


def main(args):
    N, A, B, C, D = map(int, input().split())
    S = input()
    S = '#' + S + '##'
    ans = solve(N, A, B, C, D, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
import numpy as np
import sys

  
N,A,B,C,D = map(int,raw_input().split())
originalS = raw_input()
S = originalS
S = S[:A-1]+'A'+S[A:]
S = S[:B-1]+'B'+S[B:]

S = list(S)
boolean = False

if A<B:
  while S[D-1] != 'B':
    if S[B]  == '.':
      if S[B-2] == '.':
        while S[C-1] != 'A':
          if S[A] != '.':
            if S[A+1] == '.':
              S[A-1] = originalS[A-1]
              A += 1
            else:
              print 'No'
              sys.exit()
          S[A] = 'A'
          S[A-1] = originalS[A-1]
          A += 1
        boolean = True
    else:
      if S[B+1] == '.':
        S[B-1] = originalS[B-1]
        B  += 1
      else:
        print 'No'
        sys.exit()

    S[B] = 'B'
    S[B-1] = originalS[B-1]
    B += 1

  if boolean == False:
    while S[C-1] != 'A':
          if S[A] != '.':
            if S[A+1] == '.':
              S[A-1] = originalS[A-1]
              A += 1
            else:
              print 'No'
              sys.exit()
          S[A] = 'A'
          S[A-1] = originalS[A-1]
          A += 1
  print 'Yes'
  sys.exit()

else:
  while S[C-1] != 'A':
    if S[A]  == '.':
      if S[A-2] == '.':
        while S[D-1] != 'B':
          if S[B] != '.':
            if S[B+1] == '.':
              S[B-1] = originalS[B-1]
              B += 1
            else:
              print 'No'
              sys.exit()
          S[B] = 'B'
          S[B-1] = originalS[B-1]
          B += 1
        boolean = True
    else:
      if S[A+1] == '.':
        S[A-1] = originalS[A-1]
        A  += 1
      else:
        print 'No'
        sys.exit()

    S[A] = 'A'
    S[A-1] = originalS[A-1]
    A += 1

  if boolean == False:
    while S[D-1] != 'B':
      if S[B] != '.':
        if S[B+1] == '.':
          S[B-1] = originalS[B-1]
          B += 1
        else:
          print 'No'
          sys.exit()
      S[B] = 'B'
      S[B-1] = originalS[B-1]
      B += 1

  print 'Yes'
  sys.exit()

Submission status: Accepted

Solution code:
N, A, B, C, D = [int(i) - 1 for i in input().strip().split(' ')]
N += 1
S = [c for c in input().strip()]
S += '#'


def check(current, dest):
  i = current + 1
  while True:
    if i >= dest:
      return True
    elif S[i] == '.':
      i = i + 1
    elif S[i + 1] == '.':
      i = i + 2
    else:
      return False


def passable():
  i = B
  while True:
    if i > D:
      return False
    elif S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
      return True
    else:
      i = i + 1


def main():
  if D > C:
    return check(B, D) and check(A, C)
  else:
    return passable() and check(A, C)


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

Submission status: Accepted

Solution code:
import re                                                                                                        
import copy                                                                                                      

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

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

Submission status: Accepted

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

def solve(r,l):
    for i in range(r,l-1):
        if s[i-1] == "#" and s[i] == "#":
            return False
    return True

def perfect_solve(r,l):
    for i in range(r,l-1):
        if s[i-1] =="#" and s[i] =="#":
            return False

    for i in range(r-1,l):
        if s[i-1]=="." and s[i]=="." and s[i+1]==".":
            return True
    return False

if C < B :
    if solve(A,C) and solve(B,D):
        print("Yes")
    else:
        print("No")
elif C < D :
    if solve(B,D) and solve(A,B):
        print("Yes")
    else:
        print("No")
else:
    if perfect_solve(B,D) and solve(A,B) and solve(D,C):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

def solve(N: int, A: int, B: int, C: int, D: int, S: str):

    if(S[A-1:C+1].count('##') > 0 or S[B-1:D+1].count('##')):
    # if(S[A:max(C,D)].count('##') > 1):
        print(NO)
        sys.exit()

    if(D < C):
        if(S[B-2:D+1].count('...') <= 0):
            print(NO)
            sys.exit()
        else:
            print(YES)
    else:
        print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

else:
    print("Yes")

Submission status: Accepted

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

# print(*data, sep='\n')

Submission status: Accepted

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

AtoC = True
BtoD = True
replace = False

for n in list(range(A-1,C)):
    if S[n] =='#' and S[n+1] =='#':
        AtoC = False
        
for n in list(range(B-1,D)):
    if S[n] =='#' and S[n+1] == '#':
        BtoD = False
        
if C<D:
    if AtoC == True and BtoD == True:
        print('Yes')
    else:
        print('No')
else:
    for n in list(range(B-2,D-1)):
        if S[n] =='.' and S[n+1] == '.' and S[n+2] == '.':
            replace = True
    if AtoC == True and BtoD == True and replace == True:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
ans = "Yes"
iwa = 0
for i in S[A-1:C]:
    if i == "#":
        iwa += 1
        if iwa > 1:
            ans = "No"
    else:
        iwa = 0
iwa = 0
for i in S[B-1:D]:
    if i == "#":
        iwa += 1
        if iwa > 1:
            ans = "No"
    else:
        iwa = 0
flag = 0
hoge = 0
if D < C:
    for i in S[B-2:D+1]:
        if i ==".":
            hoge += 1
            flag = max(flag,hoge)
        else:
            hoge = 0
    if flag < 3:
        ans = "No"
print(ans)

Submission status: Accepted

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

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

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

    ans = 'Yes'
    if '##' in S[A-1:C] or '##' in S[B-1:D]:
        ans = 'No'

    if D < C:  # 追い越す場所が必要
        if '...' not in S[B-2:D+1]:
            ans = 'No'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

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

    ans = 'Yes'
    if '##' in s[a - 1:c] or '##' in s[b - 1:d]:
        ans = 'No'

    if ans == 'Yes':
        if c < d:
            pass
        else:
            if '...' in s[b - 2:d + 1]:
                pass
            else:
                ans = 'No'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

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

    blocks = 0
    for s in range(A - 1, C):
        if S[s] == '.':
            if blocks > 1:
                print('No')
                exit()
            blocks = 0
        else:
            blocks += 1

    blocks = 0
    for s in range(B - 1, D):
        if S[s] == '.':
            if blocks > 1:
                print('No')
                exit()
            blocks = 0
        else:
            blocks += 1

    if D < C:  # 追い越す場所が必要
        can_overtake = False
        for s in range(B - 1, D):
            if S[s-1] == '.' and S[s] == '.' and S[s+1] == '.':
                can_overtake = True
                break

        if not can_overtake:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

judge = True
if "##" in s[a - 1:c] or "##" in s[b - 1:d]:
    judge = False

if judge and c > d:
    if not "..." in s[b - 2:d + 1]:
        judge = False

print("Yes") if judge else print('No')

Submission status: Accepted

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

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

	if "..." in S[B-2:D+1]:
		print "Yes"
		quit()
	print "No"

Submission status: Accepted

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

reachable = not ("##" in L[A:C+1] or "##" in L[B:D+1])
interupt = "..." in L[B-1:D+2]
if reachable and (C < D or interupt):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
ans = True
if D > C:
    cnt = 0
    for i in range(A-1, D):
        if cnt == 2:
            ans = False
            break
        else: 
            if S[i] == '#':
                cnt +=1
            else:
                cnt = 0
    if ans:
        print('Yes')
    else:
        print('No')
else:
    cnt = 0
    cnt2 = 0
    flag = False
    for i in range(A-1, C):
        if B-2<=  i <= D:
            if cnt2 == 3:
                flag = True
                if cnt == 2:
                    ans = False
                    break
                else: 
                    if S[i] == '#':
                        cnt +=1
                        cnt2 = 0
                    else:
                        cnt = 0
                        cnt2 += 1
            else:
                if cnt == 2:
                    ans = False
                    break
                else: 
                    if S[i] == '#':
                        cnt +=1
                        cnt2 = 0
                    else:
                        cnt = 0
                        cnt2 += 1
        else:
            if cnt2 == 3:
                flag = True
                cnt2 = 0
            if cnt == 2:
                ans = False
                break
            else:
                if S[i] == '#':
                    cnt += 1
                else:
                    cnt = 0
    if ans and flag:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys

N, A, B, C, D = map(lambda x: int(x)-1, input().split())
L = input()

reachable = True
if "##" in L[A:C+1] or "##" in L[B:D+1]:
    reachable = False

if not reachable:
    print("No")
elif C < D:
    print("Yes")
else:
    if "..." in L[B-1:D+2]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys

N, A, B, C, D = map(int, input().split())
L = list([v for v in input()])

HOP = [1, 2]
dp_d = [0]*N
dp_d[B-1] = 1
for i in range(N):
    if L[i] == "#":
        continue
    for h in HOP:
        dst = i+h
        if dst < N and L[dst] == ".":
            dp_d[dst] = max(dp_d[dst], dp_d[i])
dp_c = [0]*N
dp_c[A-1] = 1
for i in range(N):
    if L[i] == "#":
        continue
    for h in HOP:
        dst = i+h
        if dst < N and L[dst] == ".":
            dp_c[dst] = max(dp_c[dst], dp_c[i])
reachable = False
if dp_c[C-1] == 1 and dp_d[D-1] == 1:
    reachable = True

if not reachable:
    print("No")
elif C < D:
    print("Yes")
else:
    if "..." in "".join(L[B-2:min(C, D)+1]):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
S = [1] + [1 if s == "." else 0 for s in input()]
flag = True
count = 0
for s,i in zip(S[1:],range(1,n+1)):
    if not(s):
        count += 1
    else:
        count = 0
    if count == 2 and a < i and i < c:
        flag = False
        break
    elif count == 2 and b < i and i < d:
        flag = False
        break
count = 0
if  c > d:
    flag = False
    for s in S[b-1:d+2]:
        if s:
            count += 1
        else:
            count = 0
        if count == 3:
            flag = True
            break
if flag :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = [int(i)-1 for i in input().split()] 
S = input()
flag = 1
if a < b < c < d:
    if ("##" in S[a:d+1]): flag = 0
elif a < b < d < c:
    if ("##" in S[a:c+1]): flag = 0
    if ("..." not in S[b-1:d+2]):flag = 0
else:
    if ("##" in S[a:c+1]): flag = 0
    if ("##" in S[b:d+1]): flag = 0
print("Yes" if flag else "No")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

flg1 = S[a:c+1].count("##")
flg2 = S[b:d+1].count("##")
flg3 = S[b-1:d+2].count("...")

if c < d :
    if flg1 + flg2 == 0 :
        ans = "Yes"
    else :
        ans = "No"
else :
    if (flg1 + flg2 == 0) and flg3 :
        ans = "Yes"
    else :
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
import re

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

pat1 = '##'
pat2 = r'\.\.\.'

ret = ''

a2c = li[a:c]
b2d = li[b:d]
if re.search(pat1, a2c) or re.search(pat1, b2d):
    ret = 'No'
else:
    if c > d:
        carea = li[b-2:d+1]
        if re.search(pat2, carea):
            ret = 'Yes'
        else:
            ret = 'No'
    else:
        ret = 'Yes'


print(ret)

Submission status: Accepted

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

def solveSimple(s, a, b, c, d):     
    if '##' in s[b-1:d]:
        return False 
    if '##' in s[a-1:c]:
        return False
    return True

# simple 
if c < d:
    ans = solveSimple(s, a, b, c, d)
    
# solveDifficult
else:
    ans = solveSimple(s, a, b, c, d) and '...' in s[b-2:d+1]

if ans:
    print('Yes')
else:
    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
if c < d:
    pattern = 1
elif c > d:
    pattern = 2
if pattern == 1:
    ans = 'Yes'
    for i in range(a, c):
        tmp = s[i:i + 2]
        if tmp == '##':
            ans = 'No'
            break
    for i in range(b, d):
        tmp = s[i:i + 2]
        if tmp == '##':
            ans = 'No'
            break
if pattern == 2:
    for i in range(b, d + 1):
        if 1 <= i + 1 <= len(s):
            tmp = s[i - 1:i + 2]
            if tmp == '...':
                ans = 'Yes'
                break
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
# A問題
N, A, B, C, D = map(int, input().split())
S = input()
flag = False


if C < D:   # AがBを飛び越えない時
    if S.count("##") > 0:
        if S[A-1:C-1].count("##") > 0 or S[B-1:D-1].count("##") > 0:
            flag = False
        else:
            flag = True
    else:
        flag = True
else:   # AがBを飛び越えるとき
    if S.count("##") > 0:
        flag = False
    else:
        if S[B-2:D+1].count("..."):
            flag = True
        else:
            flag = False
        
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if c < d:
    x = a + 1
    while x < d:
        if s[x] == '#':
            if s[x+1] == '#':
                print('No')
                exit()
            else:
                x += 2
        else:
            x += 1
    print('Yes')
else:
    x = a + 1
    check = 0
    while x < c:
        if s[x] == '#':
            if s[x+1] == '#':
                print('No')
                exit()
            else:
                x += 2
        else:
            if b <= x <= d and check == 0:
                if s[x-1] == s[x] and s[x] == s[x+1]:
                    check = 1
            x += 1
    if check == 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

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

BLOCK=[0]*N
OPEN=[0]*N

for i in range(1,N):
    if S[i]=="#" and S[i-1]=="#":
        BLOCK[i]=1

for i in range(2,N):
    if S[i]==S[i-1]==S[i-2]==".":
        OPEN[i]=1

RIGHT_A=N-1
for i in range(A,N):
    if BLOCK[i]==1:
        RIGHT_A=i
        break

RIGHT_B=N-1
for i in range(B,N):
    if BLOCK[i]==1:
        RIGHT_B=i
        break

if C<=RIGHT_A+1 and D<=RIGHT_B+1:
    if C<D:
        print("Yes")
        sys.exit()
    if RIGHT_A==RIGHT_B:
        for j in range(B,D+1):
            if OPEN[j]==1:
                print("Yes")
                sys.exit()

        else:
            print("No")
                
    else:
      print("Yes")
else:
    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
if (A < C < B < D) or (A < B < C < D):
    if '##' in S[A: C + 1]:
        print('No')
        exit()

    if '##' in S[B: D + 1]:
        print('No')
        exit()
    print('Yes')


if A < B < D < C:
    if '##' in S[A: C + 1]:
        print('No')
        exit()

    if '##' in S[B: D + 1]:
        print('No')
        exit()

    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()

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n,a,b,c,d=LI()
  s=S()

  if '##' in s[a-1:c-1]:
    return 'No'
  if '##' in s[b-1:d-1]:
    return 'No'
  
  if d<c:
    # print(s[b-2:d+1])
    if '...' not in s[b-2:d+1]:
      return 'No'

  return 'Yes'

print(main())

Submission status: Accepted

Solution code:
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(A,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2) and A <= i <= (max(C,D)-1):
        flag = False
        break
for j in range(A,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (B <= j + 2 <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        print("Yes")
    else:
        print("No")