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:
N,A,B,C,D = list(map(int,input().split()))
s = list(input())

if C < D:
	judge = 0
	for i in range(B,D-1):
		if s[i] == "#" and s[i+1] ==  "#":
			judge = 1
	for i in range(A,C-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	if judge == 1:
		print("No")
	else:
		print("Yes")
		exit()
		
if C > D:
	judge = 0
	judge1 = 0
	for i in range(B,D-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	for i in range(B-2,D-1):
		if s[i] == "." and s[i+1] == "." and s[i+2] == ".":
			judge1 = 1
	if judge1 == 0:
		judge = 1
	for i in range(A,C-1):
		if s[i] == "#" and s[i+1] == "#":
			judge = 1
	if judge == 1:
		print("No")
	else:
		print("Yes")
		exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

needOver = False
if C > D:
    needOver = True

ans = 'Yes'
overPos = 0
if needOver:
    canOver = False
    for i in range(B-1, D):
        if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
            canOver = True
            break
    if not canOver:
        ans = 'No'

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

for i in range(B+1-1, D):
    if S[i-1] == '#' and S[i] == '#':
        ans = 'No'
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N,A,B,C,D = list(map(int, input().split()))
        S = np.asarray(list(str(input())))
    else:
        pass

    scount = 0
    dcount = 0
    swapok = False
    #print(S[A:D])
    for i in range(A,max(C,D)):
        s = S[i]
        if s == "#":
            dcount = 0
            scount += 1
            if scount == 2:
                print("No")
                exit()
        else:
            scount = 0
            if D > i > B-3:
                dcount += 1
                if dcount == 3:
                    swapok = True
    
    if (C>D) & (not swapok):
        if (S[D-2] == ".") & (S[D] == "."):
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")

if __name__ =='__main__':
    main()

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 A > B:
        A,B = B,A
        C,D = D,C

    if A > C or B > D:
        print(NO)
        return

    for i in range(A-1,C-1):
        if S[i] == "#" and S[i+1] == "#":
            print(NO)
            return

    for i in range(B-1,D-1):
        if S[i] == "#" and S[i+1] == "#":
            print(NO)
            return

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

        if not bOK:
            print(NO)
            return

    print(YES)







# 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:
#!/usr/bin/env python
# coding: utf-8

def readInt():
    return int(input())

def readList():
    return list(input().split())

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

def check(s, x_from, x_to):
    for x in range(x_from, x_to):
        can_jump = False
        for dx in range(0, 2):
            if s[x+dx] == '.':
                can_jump = True
                break
        if not can_jump:
            return False
    return True


def main():
    n, a, b, c, d = readListI()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = input()

    if c > d:
        # 抜く必要があり、...がb-1<=x<=dにないといけないのでその判定をする
        can_swap = False
        for x in range(b-1, d):
            can_swap_here = True
            for dx in range(0, 3):
                if s[x+dx] == '#':
                    can_swap_here = False
                    break
            if can_swap_here:
                can_swap = True
                break
        if not can_swap:
            print("No")
            return

    # それぞれがたどりつけるか (##がないか) を調べれば良い
    if not check(s, a, c):
        print("No")
        return
    if not check(s, b, d):
        print("No")
        return
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#A
N,A,B,C,D  = map(int,input().split())
S = input()
ans = 'Yes'
if C < D:
    befA = S[A-1]
    for i in range(A,C):
        # print(i)
        if S[i] == '#' and befA =='#':
            ans = 'No'
            break
        befA = S[i]
    befB = S[B-1]
    for j in range(B,D):
        # print(j)
        if S[j] == '#' and befB == '#':
            ans = 'No'
            break
        befB = S[j]
elif D < C:
    befA = S[A-1]
    for i in range(A,C):
        # print(i)
        if S[i] == '#' and befA =='#':
            ans = 'No'
            break
        befA = S[i]
    for k in range(B-1,D):
        ans = 'No'
        if S[k-1]=='.' and S[k] == '.' and S[k+1]=='.':
            ans = 'Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
def check(a,c,s):
  if s[a-1]=="#"or"#"==s[c-1]:return False
  for i in range(c-a):
    if s[a-1+i]==s[a+i]=="#":return False
  return True
if c<d:
  if check(a,c,s)and check(b,d,s):print("Yes")
  else:print("No")
else:
  if not(check(b,d,s)):print("No");exit()
  f=False
  for i in range(d-b+1):
    if s[b-2+i:b+1+i]==[".",".","."]:f=True
  if f and check(a,c,s):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]:
  print('No')
  exit()
if '##' in s[b:d-1]:
  print('No')
  exit()
if c > d:
  if '...' not in s[b-2:d+1]:
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import math
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']




def main():
    N, A, B, C, D = list(map(int,input().split()))
    S= str(input())
    # print(S[2:5])-> [2]~[4]
    if C>D:
        if '##' in S[A-1:C+1]:
            print("No")
        elif "..." in S[B-2:D+1]:
            print("Yes")
        else:
            print("No")
    else:
        if '##' in S[A-1:D]:
            print("No")
        else:
            print("Yes")
    # elif C>D and  ("..." in S[B-2:])
    # print(S[B-2:])
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,a,b,c,d = inm()
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
if c<d:
    for i in range(a,d-1):
        if s[i:i+2] == '##':
            print('No')
            exit()
    print('Yes')
else:
    for i in range(a,c-1):
        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:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    [n, a, b, c, d] = li()
    s = input()
    if c < d:
        route = s[a:d - 1]
        # print(route)
        possible = True
        before = "."
        for si in route:
            if before == si == "#":
                possible = False
                break
            before = si
    elif d < c:
        route = s[a:d - 1]
        # print(route)
        possible = True
        before = "."
        for si in route:
            if before == si == "#":
                possible = False
                break
            before = si

        cross_possible = False
        route = s[b:d + 1]
        # print(route)
        before = [s[b - 2], s[b - 1]]
        for si in route:
            before.append(si)
            before = before[-3:]
            if before[0] == before[1] == before[2] == ".":
                cross_possible = True
        possible = possible and cross_possible

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

# C<Dの場合
# 目的地までの間に岩が２連続で存在しなければ可能
# D<Cの場合
# BとCの間に岩がないマスが３連続で存在すれば可能

Submission status: Accepted

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

ans = "Yes"
#岩が2個続いてたらダメ
for i in range(A - 1, max(C, D)):
  if i >= A and S[i] == "#" and S[i - 1] == "#":
    ans = "No"
    break

#途中で追い越しが必要な場合
if D < C:
  #岩無しが何個続いてるかカウント
  cnt = 0
  tmp = 0
  for i in range(B - 2, min(D + 1, N)):#BがDに到着するまでに追い越す
    if S[i] == ".":
      tmp += 1
    else:
      cnt = max(cnt, tmp)
      tmp = 0
  cnt = max(cnt, tmp)
  #岩無しのスペースが3個続かなきゃダメ
  if cnt < 3:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
import sys

N, A, B, C, D = map(int,input().split())
S = input()
# A<B<C, A<Dは保証 C<Dは保証されない
#AからDまでの間に岩が2つ並んでいたらむり
for i in range(A-1, D):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        sys.exit()
#Cのが左ならいける
if C < D:
    print("Yes")
    sys.exit()
# D<Cのときが問題
# Aが不可能な時は岩をBからCの間に1つも追加できない時
# Bが可能な限り小さいステップで進んだときに前後が.である時がCまでに現れないと死
# 見るべきはS[B-1](B番目のマス)からS[C-2](C-1番目のマス)の前後
for i in range(B-1, D):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
        print("Yes")
        sys.exit()
print("No")

Submission status: Accepted

Solution code:
def double_rock(field, begin ,end):
  rock = False
  for i in range(begin, end + 1):
    if field[i] == '#':
      if rock:
        #print 'NO'
        return True
        break
      rock = True
    else:
      rock = False
  return False

n, a, b, c, d = [int(v) for v in input().split()]
a -= 1
b -= 1
c -= 1
d -= 1

s = input()
field = list(s)

if c < d:
  if double_rock(field, a, d):
    ans = "No"
  else:
    ans = "Yes"
else:
  b_ok = False
  dot_count = 0
  for i in range(b-1, d+2):
    if field[i] == '.':
      dot_count += 1
    else:
      dot_count = 0
    if dot_count == 3:
      b_ok = True
  if b_ok and not double_rock(field, a, c):
    ans = "Yes"
  else:
    ans = "No"
print(ans)

Submission status: Accepted

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

ans = True

dp = [False]*n
dp[b-1] = True
# b→d
for i in range(b-1, d):
    if s[i] != ".":
        continue
    for j in range(1,3):
        if i+j < n:
            if s[i+j] != ".":
                continue
            if not dp[i+j]:
                dp[i+j] = dp[i]
if not dp[d-1]:
    ans = False


dp = [False]*n
dp[a-1] = True
# a→c
for i in range(a-1, c):
    if s[i] != ".":
        continue
    for j in range(1,3):
        if i+j < n:
            if s[i+j] != ".":
                continue
            if not dp[i+j]:
                dp[i+j] = dp[i]
if not dp[c-1]:
    ans = False

if d < c:
    l = max(b-2, 0)
    r = min(d, n-1)
    if "..." not in s[l:r+1]:
        ans = False

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    n, a, b, c, d = map(int, input().split())
    # stringのindexとして扱う
    a = a - 1
    b = b - 1
    c = c - 1
    d = d - 1
    s = input()

    # aからCの間、bからdの間までの二連岩の存在確認
    if s[a:c+1].find("##") > -1 or s[b:d+1].find("##") > -1:
        print("No")
    else:
        # 二連岩がない場合は、ABDCの飛び越えパターンだけが問題になる
        if b < d and d < c:
            # 飛び越え不可能な場合はNOになる
            # bからdの間で飛び越える必要があり、...があると飛び越えできる
            # bスタートではなく、b-1からかぞえて...があればよい
            # dエンドではなく、d+1がおわりで...でも飛び越えできる
            if s[b-1:d+2].find("...") > -1:
                print("Yes")
            else:
                print("No")
        else:
            print("Yes")
solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
flag = True
for i in range(a - 1, max(c, d) - 1):
    if s[i:i+2] == "##":
        flag = False
        break
if flag == False:
    print("No")
else:
    if c < d:
        print("Yes")
    else:
        flag2 = False
        for i in range(b - 2, min(c, d) - 1):
            if s[i:i+3] == "...":
                flag2 = True
                break
        if flag2 == True:
            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

def check():
	for i in range(A + 1, C - 1):
		if S[i] == S[i + 1] == "#":
			return False

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

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

Submission status: Accepted

Solution code:
def ok(_to: int, _from: int, S: str)->bool:
    '''_to から _from へ行けるかどうかを判定する
    '''
    for i in range(_to, _from+1):
        if i < _from and S[i] == '#' and S[i+1] == '#':
            return False
    return True


def kenken_race(N: int, A: int, B: int, C: int, D: int, S: str)->bool:
    if not ok(A, C, S) or not ok(B, D, S):
        return False

    if C < D:
        # ふぬけくんの方が右にいることは保障されている。
        # この時、ふぬけくんのゴールがすぬけくんのそれより右なら
        # 先にふぬけくんをゴールさせてしまえばいい。
        return True

    # ふぬけくんのゴールの方が左にある場合はどこかですぬけくんが追い抜かないといけない
    # そのスペースがあるかを確認する。
    # 具体的にはふぬけくんのスタートからゴールまでの間に '.' が 3 つ以上連続する点があれば良い。
    for i in range(B, D+1):
        if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
            return True
    return False


if __name__ == "__main__":
    N, A, B, C, D = map(int, input().split())
    S = input()

    yes = kenken_race(N, A-1, B-1, C-1, D-1, S)
    print('Yes' if yes else 'No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def f(x, y):
    flag = False
    for i in range(x + 1, y):
        if S[i] == "#":
            if flag:
                return True
            flag = True
        else:
            flag = False
    return False


if f(A, C) or f(B, D):
    print("No")
    exit()


if D < C:
    flag = 0
    for i in range(B - 1, D + 2):
        if S[i] == "#":
            flag = 0
        else:
            flag += 1
            if flag == 3:
                print("Yes")
                exit()
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
rock = []
for i in range(N):
	if S[i] == '#':
		rock.append(i+1)

nRock = len(rock)

# renzoku
for i in range(nRock-1):
	if rock[i+1] - rock[i] == 1:
		if A < rock[i] or B < rock[i]:
			if C > rock[i] or D > rock[i]:
				print("No")
				exit()

# A ... B ... C ... D
if C < D:
	print("Yes")
	exit()

# A ... B ...#.....#... D ... C
for i in range(nRock):
	if i == 0:
		if rock[i] >= 4:
			if B < rock[i]-1:
				print("Yes")
				exit()
		continue
	if rock[i] - rock[i-1] > 3:
		if B < rock[i]-1:
			if D == rock[i-1]+1:
				print("No")
				exit()
			else:
				print("Yes")
				exit()
print("No")

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

setrecursionlimit(10**7)

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

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

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

def reachable(i, j):
  return not any(S[k] == S[k+1] == "#" for k in range(i, j))

def swappable(i, j):
  return any(S[k-1] == S[k] == S[k+1] == "." for k in range(i, j+1))

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

possible = reachable(A, C) and reachable(B, D)

if D < C:
  # A < B < D < C
  swapl = swappable(B, D)
  possible = possible and swapl

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

Submission status: Accepted

Solution code:
from bisect import bisect_left as bisectL

N, A, B, C, D = map(int, input().split())
S = input()
walls = []
prev = ''
for i, c in enumerate(S):
  if prev == '#' and c == '#':
    walls.append(i)
  prev = c

if bisectL(walls, A-1) == bisectL(walls, C-1) and bisectL(walls, B-1) == bisectL(walls, D-1):
  if C < D:
    print('Yes')
    exit()
  else:
    if '...' in S[B-2:D+1]:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

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

c1 = all([s[x:x+2] != '##' for x in range(a, c - 2)])
c2 = all([s[x:x+2] != '##' for x in range(b, d - 2)])

if c > d:
    c3 = any([s[x:x+3] == '...' for x in range(b - 2, d - 1)])
    if c1 and c2 and c3:
        print('Yes')
    else:
        print('No')
else:
    if c1 and c2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import numpy as np

N,A,B,C,D = map(int,input().split())
S = np.array((False,)+tuple(map(lambda x: x == '#',input()))+(False,))

def check1(i,j):
    return not np.any(S[i:j] & S[i+1:j+1])

def check2(i,j):
    return np.any((~S[i-1:j])&(~S[i:j+1])&(~S[i+1:j+2]))

if C < D:
    print('Yes' if check1(A,C) and check1(B,D) else 'No')
else:
    print('Yes' if check2(B,D) and check1(A,C) else 'No')

Submission status: Accepted

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

def canJump(check):
    prev = False
    for c in check:
        if c == '#':
            if prev:
                return False
            else:
                prev = True
        else:
            prev = False
    return True

def canJump2(check):
    ren = 0
    for c in check:
        if c == '.':
            ren += 1
        else:
            ren = 0
        if ren == 3:
            return True
    return False


if c < b:
    check1 = s[a:c]
    check2 = s[b:d]
    if canJump(check1) and canJump(check2):
        print('Yes')
    else:
        print('No')

elif c < d:
    check = s[a:d]
    if canJump(check):
        print('Yes')
    else:
        print('No')

else:
    check1 = s[a:c]
    check2 = s[b-2:d+1]
    if canJump(check1) and canJump2(check2):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_3.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

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

def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    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 = list(next(tokens))  # type: str

    # write code
    dblock = set()
    for i in range(A,max(C,D)-1):
        if S[i] == '#' and S[i + 1] == '#':
            dblock.add(i+1)
    # print(dblock)
    if D > C:
        if dblock == set():
            print(YES)
        else:
            print(NO)
    else:
        if dblock == set():
            for i in range(B - 2, D - 1):
                if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
                    print(YES)
                    sys.exit()
                else:
                    continue
            else:
                print(NO)
        else:
            print(NO)

Submission status: Accepted

Solution code:
import sys
n, a, b, c, d = map(int, input().split())
s = input()
snuke, fnuke, gnuke = 0, 0, 0
s_max, f_max, g_max = 0, 0, 0
for i in range(a-1, c):
	if s[i] == "#":
		snuke += 1
		s_max = max(s_max, snuke)
	else:
		snuke = 0
for i in range(b-1, d):
	if s[i] == "#":
		fnuke += 1
		f_max = max(f_max, fnuke)
	else:
		fnuke = 0
if c>d:
	for i in range(b-2, d+1):
		if s[i] == ".":
			gnuke += 1
			g_max = max(g_max, gnuke)
		else:
			gnuke = 0

if s_max > 1 or f_max > 1:
	print("No")
elif c < d:
	print("Yes")
else:
	if g_max >= 3:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

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

def check_cont_rock(s, e):
  use_road = road[s:e]
  return "##" in use_road

def check_cont_road(s, e):
  use_road = road[s:e]
  return "..." in use_road

if D > C:
  if check_cont_rock(A-1, D-1):
    print("No")
  else:
    print("Yes")
else:
  if check_cont_rock(A-1, C-1):
    print("No")
  else:
    if check_cont_road(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()
change = S[max(A,B)-2:min(C,D)+1]
S = S[min(A,B)-1:max(C,D)]

if S.count('##') > 0:
    print('No')
else:
    if change.count('...') > 0:
        print('Yes')
    elif C < D:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

tmp = 0
for i in range(A-1, C):
    if S[i] == "#":
        tmp += 1
    if S[i] == ".":
        tmp = 0
    if tmp == 2:
        print("No")
        sys.exit()

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


tmp = 0
if C < D:
    print("Yes")
else:
    for i in range(B-2, D+1):
        if S[i] == ".":
            tmp += 1
        if S[i] == "#":
            tmp = 0
        if tmp == 3:
            print("Yes")
            sys.exit()
    print("No")

Submission status: Accepted

Solution code:


def main():
    n, a, b, c, d = map(int, raw_input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = raw_input()
    ok = False
    while b < d:
        if s[b - 1] == '.' and s[b + 1] == '.':
            ok = True
        if s[b + 1] == '.':
            b += 1
        elif b + 2 < n and s[b + 2] == '.':
            b += 2
        else:
            break
    if b != d:
        print 'No'
        return
    if b + 1 < n and s[b - 1] == '.' and s[b + 1] == '.':
        ok = True
    while a < c:
        if s[a + 1] == '.':
            a += 1
        elif a + 2 < n and s[a + 2] == '.':
            a += 2
        else:
            break
    if a != c:
        print 'No'
    elif c < d or ok:
        print 'Yes'
    else:
        print 'No'


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
A-=1
B-=1
C-=1
D-=1
S=input()
l=[0]*N
r=[0]*N
stack=[A]
dx=[1,2]
while(stack):
    x=stack.pop()
    l[x]=1
    for d in dx:
        X=x+d
        if X<0 or N<=X or l[X]==1 or S[X]=="#" or X>C:
            continue
        stack.append(X)
stack=[B]
dx=[1,2]
while(stack):
    x=stack.pop()
    r[x]=1
    for d in dx:
        X=x+d
        if X<0 or N<=X or r[X]==1 or S[X]=="#" or X>D:
            continue
        stack.append(X)
if C>D:
    t=False
    for i in range(N-3):
        if S[i:i+3]=="..." and l[i]==1 and r[i+1]==1:
            t=True
            break
    if t:
        if l[C]==1 and r[D]==1:
            print("Yes")
            quit()
    print("No")
else:
    if l[C]==1 and r[D]==1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
S = '.' + S
if C < D:
    ans = (
        'Yes' if '##' not in S[A:(D + 1)] else
        'No'
    )
else:
    i = A
    j = B
    while i < C:
        if i + 1 == C or i + 2 == C:
            ans = 'Yes'
            break
        elif i + 1 <= C and S[i + 1] == '.' and i + 1 != j:
            i += 1
        elif i + 2 <= C and S[i + 2] == '.' and i + 2 != j:
            i += 2
        else:
            if j + 1 <= D and S[j + 1] == '.':
                j += 1
            elif j + 2 <= D and S[j + 2] == '.':
                j += 2
            else:
                ans = 'No'
                break

print(ans)

Submission status: Accepted

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

def aida(x, y, list):
    #print(list[x-1:y])
    iwa=0
    space=0
    for l in list[x-1:y]:
        if l=="#":
            space=0
            if iwa==1:
                return 0
            else:
                iwa=1
        else:
            iwa=0
            if space==2:
                return 2
            elif space==1:
                space=2
            else:
                space=1
    return 1 #岩が連続していない
    


if c<b:
    t=aida(a,c,road)
    u=aida(b,d,road)
    if t>0 and u>0:
        print('Yes')
    else:
        print('No')
elif c<d:
    t=aida(a,c,road)
    u=aida(b,d,road)
    if t>0 and u>0:
        print('Yes')
    else:
        print('No')
else:
    t=aida(a,c,road)
    u=aida(b-1,min(d+1,n),road)
    #print(t,u)
    if t>0 and u==2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import numpy as np
words = lambda t : list(map(t, input().split()))

n,a,b,c,d = words(int)
s = input()

def verify(x,y):
    posa = x
    res = True
    while posa < y:
        #print(posa,y)
        if (posa+1 == y or posa+2 == y) and s[y] == '.':
            break
        if s[posa+1] == '#' and s[posa+2] == '#':
            res = False
            break
        if s[posa+2] == '.':
            posa += 2
        elif s[posa+1] == '.':
            posa += 1
    return res

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