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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""



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

A = A-1
B = B-1
C = C-1
D = D-1
def main(): 
    if C < D:
        past = True
        now = True
        for i in range(B, D):
            if S[i] == ".":
                now = True
            else:
                now = False
            
            if now == False and past ==False:
                return print("No")
            else:
                pass
            past = now
            
        past = True
        now = True
        for i in range(A, C):
            if S[i] == ".":
                now = True
            else:
                now = False
            
            if now == False and past ==False:
                return print("No")
            else:
                pass
            past = now
        return print("Yes")
    else:
        past = True
        now = True
        for i in range(A, C):
            if S[i] == ".":
                now = True
            else:
                now = False
            
            if now == False and past ==False:
                return print("No")
            else:
                pass
            past = now
                
        past2 = False
        past1 = False
        now   = True
        flg   = False
        
        if S[B-1] == "." and S[B] == "." and S[B+1] ==".":
            flg = True
        
        for i in range(B, D+1):
            if S[i] == ".":
                now = True
            else:
                now = False
            if now == True and past1 ==True and past2 == True:
                flg = True
            else:
                pass
            past2 = past1
            past1 = now
        if S[D-1] == "." and S[D+1] == ".":
            flg = True
        if flg == True:
            return print("Yes")        
        else:
            return print("No")
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if C < D:
    cnt_x = 0
    for pos in range(B - 1, D):
        Si = S[pos]
        if Si == '#':
            cnt_x += 1
            if cnt_x > 1:
                print('No')
                sys.exit()
        else:
            cnt_x = 0
    else:
        S[pos] = '#'
    #
    cnt_x = 0
    for pos in range(A - 1, C):
        Si = S[pos]
        if Si == '#':
            cnt_x += 1
            if cnt_x > 1:
                print('No')
                sys.exit()
        else:
            cnt_x = 0
else:
    cnt_o = cnt_x = 0
    for pos in range(A - 1, D):
        Si = S[pos]
        if Si == '#':
            cnt_o = 0
            cnt_x += 1
            if cnt_x > 1:
                print('No')
                sys.exit()
        else:
            cnt_x = 0
            cnt_o += 1
            if pos >= B and cnt_o > 2:
                pos_fnk = pos - 1
                break
    else:
        pos_fnk = pos
    #
    S[pos_fnk] = '#'
    # print("# comment",''.join(S))
    cnt_x = 0
    for pos in range(A - 1, C):
        Si = S[pos]
        if Si == '#':
            cnt_x += 1
            if cnt_x > 1:
                print('No')
                sys.exit()
        else:
            cnt_x = 0
    else:
        S[pos] == '#'
    S[pos_fnk] = '.'
    #
    cnt_x = 0
    for pos in range(pos_fnk, D):
        Si = S[pos]
        if Si == '#':
            cnt_x += 1
            if cnt_x > 1:
                print('No')
                sys.exit()
        else:
            cnt_x = 0

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b, c, d = map(lambda x: int(x) - 1, input().split())
s = list(input())

if d < c:
    s[b] = 'b'
    while a < b:
        if a + 1 <= c and s[a + 1] == '.':
            a += 1
        elif a + 2 <= c and s[a + 2] == '.':
            a += 2
        elif b < d:
            if b + 1 <= d and s[b + 1] == '.':
                s[b] = '.'
                s[b + 1] = 'b'
                b += 1
            elif b + 2 <= d and s[b + 2] == '.':
                s[b] = '.'
                s[b + 2] = 'b'
                b += 2
            else:
                print('No')
                exit()
        else:
            print('No')
            exit()
    a, b = b, a
    c, d = d, c
while b < d:
    if b + 1 <= d and s[b + 1] == '.':
        b += 1
    elif b + 2 <= d and s[b + 2] == '.':
        b += 2
    else:
        print('No')
        exit()
while a < c:
    if a + 1 <= c and s[a + 1] == '.':
        a += 1
    elif a + 2 <= c and s[a + 2] == '.':
        a += 2
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

flag = True

# c < dならbを先にゴールさせれば良い
s_bd = s[b:d-1]
for i in range(len(s_bd)-1):
    if s_bd[i:i+2] == "##":
        flag = False
        break
s_ac = s[a:c-1]
for i in range(len(s_ac)-1):
    if s_ac[i:i+2] == "##":
        flag = False
        break

if c > d:
    # ゴールの左が#
    if s[d-2] == "#":
        s_bd = s[b-2:d]
        has_ddd = False
        for i in range(len(s_bd)-2):
            if s_bd[i:i+3] == "...":
                has_ddd = True
        if has_ddd == False:
            flag = False

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,a,b,c,d = na()
s = ns()

a-=1
b-=1
c-=1
d-=1
fla = 0
flb = 0
dou = True
tri = False if d < c else True

for i in range(a+1,max(c,d)+1):
    if c < i and i < b:
        continue
    if s[i] == '.':
        fla = 0
        flb += 1
    else:
        fla += 1
        flb = 0
    if fla >= 2:
        dou = False
    if flb >= 3 and i >= b+1 and i <= d+1:
        tri = True

if dou and tri:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin

n, a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()

# A..C 二つの岩 あったらだめ
# B..D二つの岩 あったらだめ
# D < Cのとき、 AがBを追い越せななかったらだめ

ans = "Yes"

rock = 0
for i in range(a, c):
    if '#' == s[i-1]:
        rock += 1
        if rock >= 2:
            ans = "No"
            break
    else:
        rock = 0

rock = 0
for i in range(b, d):
    if '#' == s[i-1]:
        rock += 1
        if rock >= 2:
            ans = "No"
            break
    else:
        rock = 0


space = 0
if d < c:
    ok = 0
    for i in range(b-1, d+1):
        if '.' == s[i-1]:
            space += 1
            if space >= 3:
                ok = 1
                break
        else:
            space = 0
    if '.' == s[d-1-1] and '.' == s[d+1-1]:
        ok = 1
    if '.' == s[d-1-1] and '.' == s[d-2-1]:
        ok = 1
    if '.' == s[b-1-1] and '.' == s[b+1-1]:
        ok = 1
    if '.' == s[b+1-1] and '.' == s[b+2-1]:
        ok = 1
    if 0 == ok:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
# import re
import sys
# print(S[min(A,B):max(C,D)-1], S[min(A,B):max(C,D)-1].count("##"))
# print(S[B:D-1], S[B:D-1].count("..."))
# print(S[A:C-1], S[A:C-1].count("..."))

if S[A:max(C,D)-1].count("##"):
    print("No")
    sys.exit()
if C > D:
    if not S[B-2:D+1].count("..."):
        # if not S[D-2] == "." and S[D] == ".":
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n,a,b,c,d = readmi()

s = read()
s = deque(s)
s.appendleft('.')

flg = True # B
if c > d:
    flg = False # A
flg2 = False
aflg = False
bflg = False

while(1):
    t = 0
    if flg:
        if b + 1 <= n and s[b + 1] != '#' and b + 1 != a and not(bflg):
            t = 1
        elif s[b + 2] != '#' and b + 2 != a and b + 2 <= n and not(bflg):
            t = 2
        else:
            bflg = True
            flg = False
            flg2 = True
        b += t
        if b == d:
            bflg = True
            flg = False
            flg2 = True
    else:
        if not(flg):
            if not(flg2):
                if b != d:
                    if b + 1 <= n and s[b - 1] == '.' and s[b + 1] == '.' and not(bflg) and not(aflg):
                        flg2 = True
                    else:
                        if b + 1 <= n and s[b + 1] != '#' and b + 1 != a and not(bflg):
                            t = 1
                        elif b + 2 <= n and s[b + 2] != '#' and b + 2 != a and not(bflg):
                            t = 2
                        else:
                            bflg = True
                            flg2 = True
                b += t
                if b == d:
                    bflg = True
                    flg2 = True
            else:
                if a != c:
                    if a + 1 <= n and s[a + 1] != '#' and a + 1 != b and not(aflg):
                        t = 1
                    elif a + 2 <= n and s[a + 2] != '#' and a + 2 != b and not(aflg):
                        t = 2
                    else:
                        aflg = True
                        flg2 = False
                a += t
                if a == c:
                    aflg = True
                    flg2 = False
    if aflg and bflg:
        if a == c and b == d:
            print('Yes')
        else:
            print('No')
        exit()

Submission status: Accepted

Solution code:
def main():
    inp = input()
    st = inp.split()
    n = int(st[0])
    a = int(st[1])
    b = int(st[2])
    c = int(st[3])
    d = int(st[4])
    inp = input()
    # 2 rocks
    rock_count = 0
    for i in range(a, b):
        if inp[i] == '#':
            rock_count += 1
        elif inp[i] == '.':
            rock_count = 0
        if rock_count == 2:
            print("No")
            return
    if inp[b] == "#" and (inp[b-1] == "#" or inp[b+1] == "#"):
        print("No")
        return

    max_cd = c if c > d else d
    continuous_count = 0
    nothing_count = 0
    nothing_3 = False
    if inp[b-1] == '.':
        nothing_count += 1
    if inp[b-2] == '.':
        nothing_count += 1
    for i in range(b, max_cd):
        if inp[i] == '#':
            continuous_count += 1
            nothing_count = 0
        elif inp[i] == '.':
            continuous_count = 0
            nothing_count += 1
        if continuous_count == 2:
            print("No")
            return
        if nothing_count == 3 and i < d + 1:
            nothing_3 = True

    # c < d
    if c < d or nothing_3:
        print("Yes")
    else:
        if (inp[d-1] == '.' and inp[d-2] == '.') and (inp[d] == '.' or inp[d-3] == '.'):
            print("Yes")
        else:
            print("No")
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def valid_check(n, a, b, c, d, s):
    if not two_rocks(s[b:d]):
        return 0
    # if not two_rocks()
    if c < d:
        return two_rocks(s[a:c])
    else:
        return three_spaces(s[b-1:d+2]) and two_rocks(s[a:c])


def three_spaces(s):
    for i in range(len(s)-2):
        if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
            return 1
    return 0

# def enumerate_possibilities(b, d, s):
#     possibilities = []
#     for i in range(d-b+1):
#         if s[b+i]=='.':
#             tmp = s.copy()
#             tmp[b+i] = '#'
#             possibilities.append(tmp)
#     return possibilities


def two_rocks(s):
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='#':
            return 0
    return 1

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


if valid_check(n, a, b, c, d, s):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
mx = max(C,D)
r_count = [len(s) for s in S[A-1:mx].split('.') if len(s) > 1]
if r_count != []:
    print('No')
    exit()
if C < D:
    print('Yes')
    exit()

count = [len(s) for s in S[B-2:D+1].split('#') if len(s) > 2]
print('Yes' if len(count) > 0 else 'No')

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = list(input())
ans = 0
A = c
B = d
cntS = [0 for i in range(len(s))]
if s[0] == "#":
    cntS[0] = 1
for i in range(len(s)):
    if s[i] == "#":
        cntS[i] = cntS[i - 1] + 1

cnt = 0
ans = "Yes"
for i in range(b - 1, B):
    if cntS[i] >= 2:
        ans = "No"
        break

for i in range(a - 1, A):
    if cntS[i] >= 2:
        ans = "No"
        break

if s[A - 1] == "#" or s[B - 1] == "#":
    ans = "No"

if A < a or B < b:
    ans = "No"

if a < b < B < A:
    key = 1
    if (s[b - 2] == "#" or s[b] == "#") and ans == "Yes":
        for i in range(b, B):
            if s[i - 1] == "." and s[i + 1] == "." and s[i] == ".":
                s[i] = "#"
                cntS[i] = 1
                key = 0
        if key:
            ans = "No"

    if ans == "Yes":
        for i in range(a - 1, A):
            if cntS[i] >= 2:
                ans = "No"

print(ans)

Submission status: Accepted

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

ans = True
d = False
for i in range(B,D-1):
    if(S[i] == "#" and d):
        ans = False
        break
    elif(S[i] == "#"):
        d = True
    else:
        d = False
d = False
for j in range(A,C-1):
    if(S[j] == "#" and d):
        ans = False
        break
    elif(S[j] == "#"):
        d = True
    else:
        d = False
if(C>D):
    ans = ans and S[B-2:D+1].count("...")!=0

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

Submission status: Accepted

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

if c == d or "##" in s[a:d-1]:
    print("No")
elif c < d:
    print("Yes")
else:
    if "..." in s[b-2:d+1] and "##" not in s[a:c-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 a > b:
    a,b,c,d = b,a,d,c

#print("{0},{1},{2},{3}".format(str(a), str(b), str(c), str(d)))

# print(s)
"""
  012345678
 "#####...#####".find("...")
5
>>> "#####...#####"[:5]
'#####'
>>> "#####...#####"[5+3:]
'#####'
>>> "0123456789"[1:7]
'123456'
"""

if c < d:
    # 追い越しが不要の場合
    #print("c<d")
    # print(s)
    #print(s[a:d+1])
    if s[a:d+1].find("##") == -1: # 障害がないなら
        print("Yes")
    else:
        print("No")

else:
    # 追い越しが必要の場合
    #print(s)
    #print("takeover")
    #print(s[b-1:d+2])
    if s[b-1:d+2].find("...") != -1:
        #print(s[a:c+1])
        if s[a:c + 1].find("##") == -1: # 障害がないなら
            print("Yes")
        else:
            print("No")
    else:
        # 追い越し区間がないなら抜けない
        print("No")

Submission status: Accepted

Solution code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N, A, B, C, D = LI_()
    S = SI().strip()

    if C < D:  # AがBを追い越さないとき
        if B < C:  # ABCDの並びのとき
            # A-Dに2つ以上連続の#がなければOK
            previous = '.'
            for i in range(A, D+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'
            print('Yes')
            return

        elif C < B:  # ACBDの並びのとき
            # A-C, B-D に2つ以上連続の#がなければOK
            previous = '.'
            for i in range(A, C+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'

            previous = '.'
            for i in range(B, D+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'

            print('Yes')
            return

    elif D < C:  # AがBを追い越すとき: ABDCの並びしかない。
        # A-C に2つ以上連続の#がない かつ B-D に避難場所（3つ以上連続する . ）がある。
        count_continuous_dots = 0
        can_evac = False
        previous = '.'
        for i in range(A, C+1):
            if S[i] == '#':
                if previous == '#':
                    print('No')
                    return
                else:
                    previous = '#'
                    count_continuous_dots = 0
            else:
                previous = '.'
            if B-1 <= i <= D+1:
                if S[i] == '.':
                    count_continuous_dots += 1
                    if count_continuous_dots >= 3:
                        can_evac = True
        if can_evac:
            print('Yes')
        else:
            print('No')
        return


main()

Submission status: Accepted

Solution code:
p = [int(x) for x in input().split()]
moji = input()
x = [moji[i:i+1] for i in range(len(moji))]
n = p[0]
a = p[1]
b = p[2]
c = p[3]
d = p[4]
y = x[1:]
z = x[2:]

lista = []
for s,t,u in zip(x,y,range(len(y))):
	if s == '#' and t == '#':
		lista.append(u+1)
listb = []
for s,t,u,v in zip(x,y,z,range(len(z))):
	if s == '.' and t == '.' and u == '.':
		listb.append(v+1)

if any((a < elem and elem < c) or (b < elem and elem < d)  for elem in lista):
	print('No')
elif c < d:
	print('Yes')
elif any(b-1 <= elem and elem < d  for elem in listb):
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

start = min(a,b)
stop = max(c,d)
ans=0

if a<b and c<d:
    for i in range(start, stop):
        if s[i] == "#" and s[i+1] == "#":
            ans = "No"
            break
    if ans == 0:
        ans = "Yes"

elif b<a  and d<c:
    for i in range(start-1, stop):
        if s[i] == "#" and s[i+1] == "#":
            ans = "No"
            break
    if ans == 0:
        ans = "Yes"

elif a<b and d<c:
    judge = 0

    for i in range(start-1, stop):
        if b-1 <=i <= d-2:
            if s[i]=="." and s[i+1]=="." and s[i+2]==".":
                judge = 1
        if s[i] == "#" and s[i+1] == "#":
            ans = "No"
            break

    if ans == 0:
        if s[b-2]=="." and s[b]==".":
            ans = "Yes"
        elif judge == 1:
            ans = "Yes"
        elif judge == 0:
            ans = "No"

elif b<a and c<d:
    judge = 0

    for i in range(start, stop):
        if a-1 <=i <= c-2:
            if s[i]=="." and s[i+1]=="." and s[i+2]==".":
                judge = 1
        if s[i] == "#" and s[i+1] == "#":
            ans = "No"
            break

    if ans == 0:
        if s[a-2]=="." and s[a]==".":
            ans = "Yes"
        elif judge == 1:
            ans = "Yes"
        elif judge == 0:
            ans = "No"
print(ans)

Submission status: Accepted

Solution code:
def check (A):
    for i in range(len(A)-1):
        if A[i]*A[i+1] == 1:
            return False
            break
    return True

def check_zero (B):
    for i in range(len(B)-2):
        if B[i] == 0 and B[i+1] == 0 and B[i+2] == 0:
            return True
            break
    return False

[N,A,B,C,D] = list(map(int,input().split()))
S_ori = str(input())
S = [0]*len(S_ori)
for i in range(len(S)):
    if S_ori[i] == ".":
        S[i] = 0
    else:
        S[i] = 1

if D > C:
    if check(S[B-1:D]) == False:
        print("No")
    else:
        if check(S[A-1:C]) == True:
            print("Yes")
        else:
            print("No")
else:
    if check(S[B-1:D]) == False:
        print("No")
    else:
        if check_zero(S[B-2:D+1]) == True:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

for i in range(A,D-1):
    if S[i] == '#':
        if S[i - 1] == '#':
            print('No')
            exit(0)
if C < D:
    print('Yes')
    exit(0)

for i in range(B, D + 1):
    if S[i] == '.':
        if S[i - 1] == '.' and S[i - 2] == '.':
            print('Yes')
            exit(0)
print('No')

Submission status: Accepted

Solution code:
import sys
from collections import deque
from operator import itemgetter
import math

input = sys.stdin.readline

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

Submission status: Accepted

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


ans = "Yes"
f = 0
if C>D:
    f = 1


if f == 0:
    now = S[A-1]
    count = 0
    for i in range(A-1,C):
        if S[i]=='#':
            count += 1
        else:
            count = 0
        if count == 2:
            ans = "No"
            break
  
    count = 0
    for i in range(B-1,D):
        if S[i]=='#':
            count += 1
        else:
            count = 0
        if count == 2:
            ans = "No"
            break
       


if f == 1:
    now = S[A-1]
    count = 0
    count_space = 0
    space_flag = False

    for i in range(B-2,D+1):
        if S[i]=='#':
            count_space = 0
        else:
            count_space += 1
        if count_space == 3:
            space_flag = True

    if not space_flag:
        ans = "No"
    
    for i in range(A-1,C):
        if S[i]=='#':
            count += 1
        else:
            count = 0
        if count == 2:
            ans = "No"
            break

    
    
    count = 0
    for i in range(B-1,D):
        if S[i]=='#':
            count += 1
        else:
            count = 0
        if count == 2:
            ans = "No"
            break

print(ans)

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
def ok(p,q,s):
    return s[p-1:q].count("##")==0
if a<c<b<d:
    if ok(a,c,s) and ok(b,d,s):
        print("Yes")
    else:
        print("No")
elif a<b<c<d:
    if ok(a,c,s) and ok(b,d,s):
        print("Yes")
    else:
        print("No")
elif a<b<d<c:
    if ok(b,d,s):
        s=s[:b-1]+"#"+s[b:]
        if ok(a,c,s):
            print("Yes")
        else:
            s=s[:b-1]+"."+s[b:]
            if s[b-1:d+1].count("...")>0:
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = [int(x) for x in input().split()]
# index変換
A -= 1; B -= 1
S = input()
if (C<D):
    if ("##" in S[A:D]):
        print("No")
    else:
        print("Yes")
else:
    if ("##" not in S[A:C]) and ("..." in S[B-1:D+1]):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int, input().split())
A-=1
B-=1
C-=1
D-=1
S=input()
s=[0]*N
stop=[0]*N
space=[0]*N
for i in range(N):
    if S[i]=='#':
        s[i]=1
        if i>0 and s[i-1]==1:
            stop[i]=1
    elif i>1 and s[i-1]==0 and s[i-2]==0:
        space[i]=1
    if i>0:
        stop[i]+=stop[i-1]
        space[i]+=space[i-1]
if stop[C]-stop[A]>0 or stop[D]-stop[B]>0:
    ans=0
elif C<D:
    ans=1
elif space[D+1]-space[B]>0:
    ans=1
else:
    ans=0
print(['No','Yes'][ans])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
N, A, B, C, D = [int(elem) for elem in fin().split()]
cell_list = fin().split()[0]

init_max = max(A, B)
init_min = min(A, B)
end_max = max(C, D)
end_min = min(C, D)

after_min_cells = cell_list[init_min:end_max-1]
after_max_cells = cell_list[max(0, init_max-2):end_min+1]
# 途中に#が2つ連続しないか
if '##' in after_min_cells:
    result = 'No'
# 入れ替えが必要かどうか
elif (A-B) * (C-D) < 0:
    # 途中に.が3つ連続するかどうか（＝入れ替えが可能かどうか）
    if '...' in after_max_cells:
        result = 'Yes'
    else:
        result = 'No'
else:
    result = 'Yes'

print(result)

Submission status: Accepted

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


if s[c-1] =='#':
    print('No')
    exit(0)
if s[c-1] =='#':
    print('No')
    exit(0)
for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
        print('No')
        exit(0)
for i in range(a,c-1):
    if s[i]=='#' and s[i+1]=='#':
        print('No')
        exit(0)
if c>d:
    flag = False
    for i in range(b-2,d-1):
        if s[i:i+3]=='...':
            flag = True
            break
    if not flag:
        print("No")
        exit(0)
    else:
        print("Yes")
else:
    print("Yes")