Problem:


Score : 400 points

Problem Statement

There are N squares arranged in a row, numbered 1, 2, ..., N from left to right.
You are given a string S of length N consisting of . and #. If the i-th character of S is #, Square i contains a rock; if the i-th character of S is ., Square i is empty.

In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.

You can repeat the following operation any number of times:

Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.

You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

S is a string of length N consisting of . and #.

1 \leq A, B, C, D \leq N

Square A, B, C and D do not contain a rock.

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

Print Yes if the objective is achievable, and No if it is not.

Sample Input 1

7 1 3 6 7
.#..#..

Sample Output 1

Yes

The objective is achievable by, for example, moving the two persons as follows. (A and B represent Snuke and Fnuke, respectively.)

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

7 1 3 7 6
.#..#..

Sample Output 2

No

Sample Input 3

15 1 3 15 13
...#.#...#.#...

Sample Output 3

Yes



Sample input:
7 1 3 6 7
.#..#..


Sample output:
Yes

Submission status: Accepted

Solution code:
def f(i, y, S):
    while i < y:
        if S[i + 2] == '.':
            i += 2
        elif S[i + 1] == '.':
            i += 1
        else:
            return False
    return True
def g(i, y, S):
    while i < y:
        if S[i + 2] == '.':
            i += 2
        elif S[i + 1] == '.':
            i += 1
        else:
            break
    return i
def dc(n, a, b, c, d, S):
    S = list(S)
    S[b] = 'B'
    while a < b:
        a = g(a, c, S)
        if b == d:
            return a >= c
        elif S[b + 1] == '.':
            S[b] = '.'
            b += 1
            S[b] = 'B'
        elif S[b + 2] == '.':
            S[b] = '.'
            b += 2
            S[b] = 'B'
        else:
            return a >= c
    return True
def solve():
    n, a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    S = input() + "##"
    if c < d:
        S = list(S)
        return f(b, d, S) and f(a, c, S)
    else:
        return dc(n, a, b, c, d, S)
    return True
print("Yes" if solve() else "No")

Submission status: Accepted

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

S = input()
x = [0]

for s in S:
    if s == '#':
        x.append(1)
    else:
        x.append(0)

flag = 0

for i in range(a, c):
    if x[i] + x[i+1] == 2:
        flag = 1
for i in range(b, d):
    if x[i] + x[i+1] == 2:
        flag = 1

flag2 = 1

if c > d:
    for i in range(b-1, d):
        if x[i] + x[i+1] + x[i+2] == 0:
            flag2 = 0
else:
    flag2 = 0

if flag + flag2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

def check(l, r):
  if (r-l) <= 1:
    return True
  for i in range(l, r):
    if s[i:i+2] == '##':
      return False
  return True

def check2(l, r):
  for i in range(l, r-1):
    if s[i:i+3] == '...':
      if check(b, i) and check(i+2, c-2):
        return (True, i+1)
  return (False, -1)

if c < d:
  flag = check(a, c-2) and check(b, d-2)
else:
  flag, idx = check2(b-2, d)
  if flag:
    s = s[:idx] + '#' + s[idx+1:]
    flag = check(a, c-2)

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

Submission status: Accepted

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

if C > D:
    if '...' not in s[B-2:D+1]: ans = False
if ans:
    if '##' in s[B:D]:    ans = False
    if '##' in s[A:C]:    ans = False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B,C,D = [int(x) for x in input().split()]
S = input()
cross = False
minG = C
maxG = D

if C > D:
    minG = D
    maxG = C
    cross = True

S_wall = S[A-1:maxG]
S_even = S[B-1-1:minG+1]

wall = S_wall.find("##")
even = S_even.find("...")

if cross == False:
    if wall == -1:
        print("Yes")
    else:
        print("No")
else:
    if wall == -1:
        if even != -1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

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

ans = "Yes"
# 岩判定
for i in range(A - 1, C):
    if i != 0 and s[i-1:i+1] == "##":
        ans = "No"
        break

for i in range(B - 1, D):
    if i != 0 and s[i-1:i+1] == "##":
        ans = "No"
        break

# スペース >= 2 判定
spaceFlg = False
for i in range(max(A, B) - 1, min(C, D)):
    if s[i-1:i+2] == "...":
        spaceFlg = True
        break

if (A - B) * (C - D) < 0 and not spaceFlg:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
N,A,B,C,D = map(int,input().split())
S = input()
def isContinuous(S):
    for i in range(len(S)-1):
        if S[i:i+2] == "##":
            return True
    return False
def paint(S):
    P = [0] * len(S)
    for i in range(len(S)):
        if S[i] == "#":
            P[i] = 1
            if i != 0:
                P[i-1] = 1
            if i != (len(S)-1):
                P[i+1] = 1
    return P
if C < D:
    if (not isContinuous(S[A:C])) and (not isContinuous(S[B:D])):
        print ("Yes")
    else:
        print ("No")
else:
    P = paint(S)
    #print (P)
    #print (P[B-1:D])
    for i in P[B-1:D]:
        if i == 0:
            print ("Yes")
            exit()
    print ("No")

Submission status: Accepted

Solution code:
from collections import deque

n, start1, start2, end1, end2 = map(lambda x: int(x) - 1, input().split())
n += 1
if start2 < start1:
    start1, start2 = start2, start1
    end1, end2 = end2, end1
s = list(input())

def bfs(start, end, otherEnd, inBetween=False):
    visited = [False] * n
    visited[start] = True
    q = deque()
    q.append(start)
    while q:
        cur = q.popleft()
        if cur == end:
            s[cur] = '#'
            return cur
        if inBetween and cur != otherEnd and s[cur - 1] == s[cur + 1] == '.':
            s[cur] = '#'
            return cur
        for next in (cur + 1, cur + 2):
            if next < n and s[next] == '.' and not visited[next]:
                visited[next] = True
                q.append(next)
    return -1

secondPos = bfs(start2, end2, end1, inBetween=True)
if secondPos == -1:
    print('No')
    exit()
if bfs(start1, end1, end2) == -1:
    print('No')
    exit()
print('Yes' if bfs(secondPos, end2, end1) else 'No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
n, a, b, c, d = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

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

def canswap(s, b, d):
  print("canswap", s, file=sys.stderr)
  for x in range(b, d + 1):
    #print(x, file=sys.stderr)
    prev = s[x - 1] != '#'
    curr = s[x] != '#'
    post = s[x + 1] != '#'
    print(prev, post, file=sys.stderr)
    if post and prev and curr:
      return True
  return False

def canmove(s, a, c):
  print(s, file=sys.stderr)
  if a + 1 == c:
    return s[a + 1] != '.'
  prev = s[a + 1] != '.'
  for x in range(a + 2, c):
    #print(x, file=sys.stderr)
    post = s[x] != '.'
    if post and prev:
      return False
    prev = post
      
  return True

def doit():  
  s2 = list(s)
  print(s2, file=sys.stderr)
  s2[a] = 'A'
  s2[b] = 'B'
  print('s2 ', s2, file=sys.stderr)

  res = list(s)
  res[c] = 'A'
  res[d] = 'B'
  print('res', res, file=sys.stderr)
  
  if c < d:
    if not canmove(s2, b, d):
      return False
    s2[b] = '.'
    s2[d] = 'B'
    return canmove(s2, a, c)
  else:
    if not canmove(s2, a, c):
      if not canswap(s2, b, d):
        return False
      else:
        s2[b] = '.'
        return canmove(s2, a, c)
    s2[a] = '.'
    s2[c] = 'A'
    return canmove(s2, b, d)

#print(doit([0] * 4))
#doit()
try:
  print('Yes' if doit() else 'No')
    
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1148A_live
from collections import Counter
gi = lambda : list(map(int,input().strip().split()))
n, a, b, c, d = gi()
s = input()
if a > b:
	a, b = b, a
	c, d = d, c
a -= 1
b -= 1
c -= 1
d -= 1
if c <= d:
	temp = s[a:c]
	if "##" in temp:
		print("No")
		exit()
	temp = s[b:d]
	if "##" in temp:
		print("No")
		exit()
	print("Yes")
	exit()
temp = s[a:c]
temp2 = s[max(0, b - 1):d + 2]
if "##" in temp or "..." not in temp2:
	print("No")
	exit()
print("Yes")

Submission status: Accepted

Solution code:
def spaceinput():
    return list(map(int, input().split(" ")))

def count3(S, l, r):
    for i in range(l, r+1):
        if S[i:i+3] == "...":
            return True
    return False

def is_twocontinusblock(S, l, r):
    for i in range(l,r+1):
        if S[i:i+2] == "##":
            return True
    return False


N, A, B, C, D = spaceinput()
S = input()
S="A"+S
#print(S)
def solve():
    if is_twocontinusblock(S, A, C-1) or is_twocontinusblock(S, B, D-1):
        return False
    if D < C:
        if count3(S, B-1, D-1):
            return True
        else:
            return False

    return True


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def available(start, end, S, step=None):
    if step is not None:    #   追い越し処理
        S = S[:step] + "#" + S[step+1:]
    for i in range(start, end):
        if S[i] == "#" and S[i+1] == "#":
            return False, S
    return True, S
    
def overtake(start, end, S):
    for i in range(start, end+1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            step = i
            return True, step
    return False, None

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

if D > C:   #   追い越しが不要な時
    judge1, S = available(A, C, S)
    judge2, S = available(B, D, S)
    if judge1 and judge2:
        print("Yes")
    else:
        print("No")
else:   #   追い越しが必要な時
    overtakable, step = overtake(B, D, S)
    if overtakable:   #   追い越しが可能な時
        judge1, S = available(B, D, S)
        judge2, S = available(A, C, S, step=step)
        if judge1 and judge2:
            print("Yes")
        else:
            print("No")
    else:   #   追い越しができない時
        print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = input().rstrip()
renzoku_iwa = [0 for i in range(n)]
renzoku_blank = [0 for i in range(n)]
old1 = ""
old2 = ""
for i,tmp in enumerate(s):
	if old1 == tmp:
		if old1 == "." and old2 == ".":
			renzoku_blank[i] = 1
		elif old1 == "#":
			renzoku_iwa[i] = 1
	old2 = old1
	old1 = tmp

if sum(renzoku_iwa[a-1:c]) == 0 and sum(renzoku_iwa[b-1:d]) == 0:
	if c < d:
		print("Yes")
	else:
		if sum(renzoku_blank[b:min(d+1,len(renzoku_blank))])>=1:
			print("Yes")
		else:
			print("No")
else:
	print("No")

Submission status: Accepted

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

if C < D:
    S1 = S[A-1:D-1]
else:
    S1 = S[A-1:C-1]

fd = S1.find('##')
if fd != -1:
    print('No')
    exit()

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

else:

    S2 = S[B-2:D+1]
    fddot = S2.find('...')

    if fddot == -1:
        print('No')

    else:
        print('Yes')

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
A -= 1
B -= 1
C -= 1
D -= 1
if A < B and B < D and A < C and S[A] == "." and S[B] == "." and S[C] == "." and S[D] == ".":
    ans = True
else:
    ans = False

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

Submission status: Accepted

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

if flag == 0:

    if A > B:
        ab = 1
    else:
        ab = 0
    if C > D:
        cd = 1
    else:
        cd = 0

    if ab != cd:
        for i in range(B - 1, min(C, D)):
            if S[i-1] == "." and S[i+1] == "." and S[i] == "." and flag == 0:
                print("Yes")
                flag = 1
            #print(S[i-1],S[i] , S[i+1])
        if flag == 0:
            print("No")

    else:
        print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

pres = 'x'          # S[i-1]
cntx, cnty = 0, 0   # x:'.'の連続数, y:'#'の連続数
mxx, mxy = 1, 1     # mxx:'.'の連続数max, mxy:'#'の連続数max

for i in range(A-1, max(C, D)): # base=0
    if S[i] == pres:
        if S[i] == '.':
            cntx += 1
            if i >= B and i < D+1:  # .のチェックは B-D+1だけ
                mxx = max(cntx, mxx)
        elif S[i] == '#':
            cnty += 1
            if C > B or (i < C and i >= B-1):   # C < B の場合は、C-Bでは#の数は不問
                mxy = max(cnty, mxy)
    else:
        pres = S[i]
        if S[i] == '.':
            cntx = 1
        elif S[i] == '#':
            cnty = 1

if C < D:
    if mxy < 2:
        print("Yes")
    else:
        print("No")
else:
    if mxy < 2 and mxx >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n, a, b, c, d = (int(i) for i in input().split())  
s = str(input())
n = len(s)

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

Submission status: Accepted

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

def obs(st,end):
  for i in range(st,end):
  	if S[i] is "#" and S[i+1] is "#": return True
  return False

if obs(B,D) or obs(A,C):
  print("No")
elif C > D:
  b = False
  for i in range(B-1,min(D,N-2)):
    if S[i] is "." and S[i+1] is "." and S[i+2] is ".":
      b = True
      break
  if b:
    print("Yes")
  else:
    print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
from sys import stdin, exit

N, A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
for k in range(A - 1, max(D, C)):
    if S[k] == '#' and S[k + 1] == '#':
        print('No')
        exit()

if C < D:
    print('Yes')
else:
    cnt = 0
    for k in range(B - 2, D + 1):
        if S[k] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print('Yes')
            exit()
    print('No')

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
check=1
def check_double(S,L,R):
    count=1
    for i in range(L-1,R-1):
        if S[i]=="#" and S[i+1]=="#":
            count=0
    return count
def check_triple(S,L,R):
    count=0
    for i in range(L-1,R):
        if S[i-1]=="." and S[i]=="." and S[i+1]==".":
            count=1
    return count
if C>D:
    check=check*check_double(S,A,B)*check_triple(S,B,D)*check_double(S,D,C)
else:
    check=check*check_double(S,A,B)*check_double(S,B,D)
if check==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if "##" in s[A-1:max(C,D)]:
  print("No")
  quit()
st,e=0,0

for spl in s.split("##"):
  e += (len(spl)+2)
  if st <A<max(C,D)<=e:
    break
  st+= (len(spl)+2)

if "..." in s[B-2:min(C,D)+1] or B<C<D:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    n, a, b, c, d = map(int, raw_input().split())
    s = '#' + raw_input().strip() + '...'
    f = 0
    for i in xrange(b, d):
        if s[i] == '#' and s[i+1] == '#':
            print 'No'
            return
        if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
            f = 1
    for i in xrange(a, c):
        if s[i] == '#' and s[i+1] == '#':
            print 'No'
            return
    if c > d:
        if s[b-1] == '.' and s[b+1] == '.':
            f = 1
        if not f:
            print 'No'
            return
    print 'Yes'
main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if "##" in S[A-1:C]:
	print("No")
elif "##" in S[B-1:D]:
	print("No")
elif D < C:	# A jumps over B
	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(int, input().split())
s = list(input())

sunuke = ""
hunuke = ""


if C > D:
    k = ''.join(s[B-2:D+1])
    result = "..." in k
    if result == 0:
        print("No")
        exit()

while B <= D:
    if s[B] == ".":
        B += 1
        if B == D:
            hunuke = "ok"
            break
    elif s[B+1] == ".":
        B += 2
        if B == D:
            hunuke = "ok"
            break
        elif B > D:
            print("No")
            exit()
    else:
        print("No")
        exit()

while A <= C:
    if s[A] == ".":
        A += 1
        if A == C:
            sunuke = "ok"
            break
    elif s[A+1] == ".":
        A += 2
        if A == C:
            sunuke = "ok"
            break
        elif A > C:
            print("No")
            exit()
    else:
        print("No")
        exit()

if sunuke == "ok" and hunuke == "ok":
    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")

elif 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())
path = list(input())
path = ['.']+path
path[a] = 'a'
path[b] = 'b'
while(a<c or b<d):
    walk = 0
    if c<d:
        if b != d:
            if b+2<=d and path[b+2]!='#'and path[b+2]!='a':
                path[b]='.'
                path[b+2] ='b'
                b+=1
                walk = 1
            if path[b+1]!='#'and path[b+1]!='a':
                path[b]='.'
                path[b+1] ='b'
                b+=1
                walk = 1
        if not walk:
            if a!=c:
                if path[a+1]!='#'and path[a+1]!='b':
                    path[a]='.'
                    path[a+1] ='a'
                    a+=1
                    walk = 1
                if a+2<=c and path[a+2]!='#'and  path[a+2]!='b':
                        path[a]='.'
                        path[a+2] ='a'
                        a+=2
                        walk = 1
    else :
        if a + 2 <= c and path[a + 2] != '#' and path[a + 2] != 'b':
            path[a] = '.'
            path[a + 2] = 'a'
            a += 2
            walk = 1
        if a!=c:
            if path[a+1]!='#'and path[a+1]!='b':
                path[a]='.'
                path[a+1] ='a'
                a+=1
                walk = 1
        if not walk:
            if b != d:
                if path[b+1]!='#'and path[b+1]!='a':
                    path[b]='.'
                    path[b+1] ='b'
                    b+=1
                    walk = 1
                elif b+2<=d and path[b+2]!='#'and path[b+2]!='a':
                    path[b]='.'
                    path[b+2] ='b'
                    b+=2
                    walk = 1
    if walk==0:
        break
if a==c and b==d:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

S = input()

# '#'が2連続あれば移動不可能
minimum = min([A, B])
maximum = max([C, D])
S_split = S[minimum-1:maximum].split('.')

max_length = 0
for s in S_split:
    if len(s) > max_length:
        max_length = len(s)

if max_length >= 2:
    print('No')
    sys.exit()

# ここまでくればBは必ず目的地に到着可能

# もしC<DだったらAも必ず到着可能
if C < D:
    print('Yes')
    sys.exit()

# もしC>Dだったら、Dの手前が'#'もしくはDの奥が'#'の場合はAはほぼ到達不可能
if S[D-2] == '#' or S[D] == '#':
    # もしS[B-1]からS[D-1]の間に'...'があれば、もしくは[A, B, .]であればAは到達可能
    if '...' in S[B-2:D]:
        print('Yes')
        sys.exit()
    elif A + 1 == B and S[B] == '.':
        print('Yes')
        sys.exit()
    print('No')
    sys.exit()

print('Yes')

Submission status: Accepted

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

listA=list(map(int,input().split()))

kenken_map = input()

A_init = listA[1]-1
B_init = listA[2]-1
A_goal = listA[3]-1
B_goal = listA[4]-1

kenken_temp_b = kenken_map[B_init:B_goal+1]
kenken_temp_b_i = kenken_map[B_init-1:B_goal+1]
kenken_temp_b_goal = kenken_map[:B_goal] + '#' + kenken_map[B_goal+1:]
kenken_temp = kenken_temp_b_goal[A_init:A_goal+1]


if '##' in kenken_temp_b:
    print('No')
elif not '##' in kenken_temp:
    print('Yes')
elif '...' in kenken_temp_b_i:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def solve():
	if C<D:
		cnt = 0
		for i in range(A, D):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		print('Yes')
		return

	if C<B:
		cnt = 0
		for i in range(A, C):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		cnt = 0
		for i in range(B, D):
			if S[i:i+1]=='#':
				cnt += 1
				if cnt>=2:
					print('No')
					return
			else:
				cnt = 0
		print('Yes')
		return

	cnt = 0
	for i in range(A, C):
		if S[i:i+1]=='#':
			cnt += 1
			if cnt>=2:
				print('No')
				return
		else:
			cnt = 0
	cnt = 0
	for i in range(B-2, D+1):
		if S[i:i+1]=='.':
			cnt += 1
			if cnt>=3:
				print('Yes')
				return
		else:
			cnt = 0
	print('No')
	return

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

Submission status: Accepted

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

    
ans="Yes"
for i in range(a,max(c,d)-1):
  if s[i]=="#" and s[i+1]=="#":
    ans="No"

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if "##" in s[min(a,b)-1:max(c,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:
# coding: utf-8
# Your code here!

import sys

N, A, B, C, D = map(int, input().rstrip().split())
S = [x for x in input()]

if A < B and B < D and D < C:
    chain_rock = 0
    if S[B-2] == '.':
        chain_empty = 1
    else:
        chain_empty = 0
    max_chain_empty = 0
    for i in range(B-1, D):
        if S[i] == '.':
            chain_empty += 1
            chain_rock = 0
        else:
            chain_empty = 0
            chain_rock += 1
            
        max_chain_empty = max(max_chain_empty, chain_empty)
        if chain_rock >= 2:
            print('No')
            sys.exit()
            
    if max_chain_empty < 3:
        if not (S[D-2] == '.' and S[D] == '.'):
            print('No')
            sys.exit()
            
    chain_rock = 0
    for i in range(A, C):
        if S[i] == '#':
            chain_rock += 1
        else:
            chain_rock = 0
            
        if chain_rock >= 2:
            print('No')
            sys.exit()
            
else:
    chain_rock = 0
    for i in range(A, C):
        if S[i] == '#':
            chain_rock += 1
        else:
            chain_rock = 0
            
        if chain_rock >= 2:
            print('No')
            sys.exit()
            
    chain_rock = 0
    for i in range(B, D):
        if S[i] == '#':
            chain_rock += 1
        else:
            chain_rock = 0
            
        if chain_rock >= 2:
            print('No')
            sys.exit()

print('Yes')

Submission status: Accepted

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

def syori1(sunuke,hunuke):
    while hunuke<D:
        if hunuke+1 == N:
            return "Yes"
        if S[hunuke+1] == ".":
            hunuke += 2
        elif S[hunuke] == ".":
            hunuke += 1
        else:
            return "No"
    
    while sunuke<C:
        if sunuke + 1 == N:
            return "Yes"
        if S[sunuke+1] == ".":
            sunuke += 2
        elif S[sunuke] == ".":
            sunuke += 1
        else:
            return "No"
    
    return "Yes"

def canover():
    for i in range(B-2,D-1):
        if S[i] == "." and S[i+1] == "." and S[i+2]==".":
            return True
        else:
            pass
    return False
    
def tonari():
    if S[B]==".":
        return True
    else:
        return False

if C > D:
    if A+1 == B:
        if tonari():
            print(syori1(sunuke,hunuke))
            exit()
            
    if canover():
        print(syori1(sunuke,hunuke))
    else:
        print("No")
else:
    print(syori1(sunuke,hunuke))

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
j = 0
flag = False
fflag = False

if '#' not in s:
  flag = True

for i, k in enumerate(s):
  if k == '.':
    j += 1
  else:
    if j >= 3 and i - j + 1 < d and b < i:
      flag = True
    if s[i-1] == '#' and i-1 < max(c, d) and i+1 > min(a, b):
      fflag = True
    j = 0

if j >= 3 and len(s) - j + 1 < d:
  flag = True
    
if fflag:
  print('No')
else:
  if c > d and flag:
    print('Yes')
  elif c < d:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

#C<Dのとき　AはBを抜かなくて良い
if C < D:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1:
        print('Yes')
    else:
        print('No')
        
#C>Dのとき　AはBを抜かなければならない
else:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1 and ''.join(S[B-2:D+1]).find('...') > -1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

switch = 0

S_before_a = S.copy()
S_before_a[B-1] ='#'
A_list = S_before_a[A:C-1]
count1 = 0
for i in range (len(A_list)-1):
    if ''.join(A_list[i:i+2])=='##':
        count1+=1

S_after_a = S.copy()
S_after_a[C-1]='#'

count2 = 0
B_list = S_after_a[B:D-1]
for i in range (len(B_list)-1):
    if ''.join(B_list[i:i+2])=='##':
        count2+=1
    
#count逆
S_before_b = S.copy()
S_before_b[A-1] ='#'
B_list = S_before_b[B:D-1]
count3 = 0
for i in range (len(B_list)-1):
    if ''.join(B_list[i:i+2])=='##':
        count3+=1

S_after_b = S.copy()
S_after_b[D-1]='#'

count4 = 0
A_list = S_after_b[A:C-1]
for i in range (len(A_list)-1):
    if ''.join(A_list[i:i+2])=='##':
        count4+=1
        
change_counter =0
changer = S[max(A,B)-1:min(C,D)]
for i in range(len(changer)-2):
    if ''.join(changer[i:i+3])=='...':
        change_counter+=1
        
if (count1+count2) == 0 or (count3+count4) ==0:
    print('Yes')
elif (count1 == 1 and change_counter>0 ) or (count2 == 1 and change_counter>0 ) or (count3 == 1 and change_counter>0 ) or (count4 == 1 and change_counter>0 ):
    print('Yes')
else:
    print('No')