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 = map(int, input().split())
S = str(input())

# ##となっていたら無理
# C < D のとき、それぞれが移動可能かでわかる
# C > D のときは? 追い越しは...となる箇所があればいける

if '##' in S[min(A, B)-1:max(D, C)]:
    print('No')
    quit()

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

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[B - 2:D + 1] and "##" not in S[A - 1:C] and "##" not in S[B - 1:D]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

Submission status: Accepted

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

s=input()

if c<d:
    p=s[a:d-1].count("##")
    if p==0:
        print("Yes")
    else:
        print("No")
else:
    p=s[a:c-1].count("##")
    q=s[b-2:d+1].count("...")
    if p==0 and q>0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, a, b, c, d = geta(int)
    s = "#" + gete()

    if c < d:
        # no consecutive rocks between [a,c] and [b,d]
        if "##" in s[a:c + 1] or "##" in s[b:d + 1]:
            print("No")
        else:
            print("Yes")
    else:
        # no consecutive rocks between [a,c] and,
        # [b-1,d+1] contains "..."

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


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

Submission status: Accepted

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

if c < d:
    if s[a-1:c].find('##')==-1 and s[b-1:d].find('##')==-1:
        print('Yes')
    else:
        print('No')
else:
    if s[a-1:c].find('##')==-1 and s[b-1:d].find('##')==-1 and 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 = input()

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,A,B,C,D = map(int,readline().split())
S = readline().rstrip()

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,a,b,c,d = iim()
s = input()
st = s[b-2:min(c,d)+1]
s = s[a-1:max(c,d)]

if '##' in s:
    print('No')
elif c < d:
    print('Yes')
else:
    print('Yes' if '...' in st else ' No')

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, A, B, C, D = [int(x) for x in input().strip().split()]
    A, B, C, D = A-1, B-1, C-1, D-1
    S = input().strip()
    if C == D:
        print('No')
        return
    if C > D:
        C, D = D, C
        A, B = B, A
    while B != D:
        # print(S)
        # print(' ' * A + 'A')
        # print(' ' * B + 'B')
        if B + 2 < N and B + 2 != A and S[B+2] == '.':
            B += 2
        elif B + 1!= A and S[B+1] == '.':
            B += 1
        else:
            if A > B:
                if A + 1 < N and B != A + 1 and S[A+1] == '.':
                    A += 1
                elif A + 2 < N and B != A + 2 and S[A+2] == '.':
                    A += 2
                else:
                    print('No')
                    return
            else:
                print('No')
                return
    
        
    while A != C:
        # print(S)
        # print(' ' * A + 'A')
        # print(' ' * B + 'B')
        if A + 2 < N and B != A + 2 and S[A+2] == '.':
            A += 2
        elif A + 1 < N and B != A + 1 and S[A+1] == '.':
            A += 1
        else:
            print('No')
            return

    # print(S)
    # print(' ' * A + 'A')
    # print(' ' * B + 'B')
    print('Yes')



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re

N, A, B, C, D = map(int, input().split())
S = input()
S = '#' + S
flag = True
if re.search(r'##', S[min([A,B]): max([C,D])+1]):
    flag *= False

if D < C:
    if re.search(r'\.\.\.', S[B-1:D+2]):
        flag *= True
    else:
        flag *= False
        
print('Yes') if flag else print('No')

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc034/tasks/agc034_a
import sys
n, a, b, c, d = map(int, input().split())
s = list(input())

for i in range(a - 1, c - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

for i in range(b - 1, d - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

if c > d:
    f = False
    for i in range(b - 2, d - 1):
        if s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.':
            f = True
else:
    f = True
if f:
    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] or '##' in s[b: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:
def main():
    n, a, b, c, d = list(map(lambda x: int(x) - 1, input().split()))
    n += 1
    s = list(input())
    s = s[a:max(c, d) + 1]
    for i in range(len(s) - 1):
        if s[i] == '#' and s[i + 1] == '#':
            print('No')
            exit()
    if c < d:
        print('Yes')
    else:
        ch = False
        for i in range(b, d + 1):
            if s[i - 1] == s[i] == s[i + 1] == '.':
                ch = True
        if ch:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
print('YNeos'['##' in s[a-1:max(c,d)] or not(c<d or '...' in s[b-2:d+1])::2])

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    N, A, B, C, D = map(int, input().split())
    log(N, A, B, C, D)
    S = input()
    if "##" in S[A-1:max(D, C)]:
        print("No")
        return
    if C < D:
        print("Yes")
        return
    log(S[B-2:D+1])
    if "..." in S[B-2:D+1]:
        print("Yes")
        return
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def move_snuke():
    global A, B
    if B == D:
        return False
    if S[B + 1] == '.' and A != B + 1:
        B += 1
        return True
    if S[B + 2] == '.' and A != B + 2:
        B += 2
        return True
    return False


def move_fnuke():
    global A, B
    if A == C:
        return False
    if S[A + 1] == '.' and B != A + 1:
        A += 1
        return True
    if S[A + 2] == '.' and B != A + 2:
        A += 2
        return True
    return False


S = '#' + S
while True:
    if C < D:
        if not move_snuke():
            if not move_fnuke():
                print('No')
                break
    else:
        if not move_fnuke():
            if not move_snuke():
                print('No')
                break
    if A == C and B == D:
        print('Yes')
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n, a, b, c, d = input_list()
    s = input()
    uses = s[a-1:d]
    if '##' in uses:
        print('No')
        exit()
    if c < d:
        print('Yes')
    else:
        end = d+1 if d < len(s) else d
        if '...' in s[b-2:end]:
            print('Yes')
        else:
            print('No')


def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

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


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


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


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


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


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if s[c] == '#' or s[d] == '#':
    print('No')
    exit()

# '##'を検知
if '##' in s[a:c+1] or '##' in s[b:d+1]:
    print('No')
    exit()

if c > d:
    # 3 マス以上の連続する'.'が必要
    num_dot = s[b-1:d+2].count("...")
    if num_dot == 0:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

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

def find_route(X,Y):
    for i in range(X,Y):
        if S[i] == S[i + 1] == '#':
            return False
    return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
flag1, flag2 = False, False
if d > c:
    flag = "##" not in s[b: d] and "##" not in s[a: c]
else:
    flag = "..." in s[b - 2: d + 1]

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

Submission status: Accepted

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

if c < d:
    print("Yes" if s[a - 1:d].count("##") == 0 else "No")
    #aからd-1までで二個あるとあうと
else:
    print("Yes" if s[a - 1:c].count("##") ==
          0 and s[b - 2:d + 1].count("...") > 0 else "No")
          #b-1からd+1までで飛び越すの

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()


def func1(start, goal):
    for i in range(start, goal):
        if s[i] == "#" and s[i + 1] == "#":
            return False
    return True

def func2(start, goal, n):
    for i in range(start, goal + 1):
        if i == 0 or i == n - 1:
            continue
        if s[i - 1] == "." and s[i] == "." and s[i + 1] == ".":
            return True
    return False

if not (func1(a, c) and func1(b, d)):
    print("No")
    sys.exit()

if c < d:
    print("Yes")
else:
    if func2(b, d, n):
        print("Yes")
    else:
        print("No")
        # print("he")

Submission status: Accepted

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

if A<B<C<D:
    a=True
    for i in range(A-1,D-2):
        if S[i]==S[i+1]=="#":
            print("No")
            a=False
            break
    if a==True:
        print("Yes")
elif A<C<B<D:
    a=True
    for i in range(A-1,C-2):
        if S[i]==S[i+1]=="#":
            print("No")
            a=False
            break
    if a==True:
        for i in range(B-1,D-2):
            if S[i]==S[i+1]=="#":
                print("No")
                a=False
                break
    if a==True:
        print("Yes")
elif A<B<D<C:
    a=True
    for i in range(A-1,C-2):
        if S[i]==S[i+1]=="#":
            b=True
            a=False
            break
    if a==True:
        b=True
        for i in range(B-2,D-2+1):
            if S[i]==S[i+1]==S[i+2]:
                b=False
                break
    if b==False:
        print("Yes")
    elif b==True:
        print("No")

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = str(input())
if '##' in s[a:c] or '##' in s[b: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:
n, a,b,c,d = map(int, input().split())
s = input()

def check_twice(left, right, l):
    for i in range(left-1, right):
        if l[i] == '#' and l[i+1] == '#':
            return False
    return True

def check_triple(left, right, l):
    f = False
    for i in range(left-1, right-2):
        if l[i] == '.' and l[i+1] == '.' and l[i+2] == '.':
            f = True
            break
        else:
            continue
    return f

if c < d:
    flg = check_twice(a, c, s) & check_twice(b, d, s)
    if flg is True:
        print('Yes')
    else:
        print('No')

else:
    flg = check_twice(a, c, s) & check_triple(b-1, d+1, s)
    if flg is True:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

if c < d:
    print("Yes" if s[a - 1:d].count("##") == 0 else "No")
else:
    print("Yes" if s[a - 1:c].count("##") ==
          0 and s[b - 2:d + 1].count("...") > 0 else "No")

Submission status: Accepted

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

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

start = a-1
end = c-1
sharp_count = 0
for i in range(start+1, (end-1)+1):
    if s[i] == "#" and s[i] == s[i+1]:
        print("No")
        exit()

start = b-1
end = d-1
sharp_count = 0
for i in range(start+1, (end-1)+1):
    if s[i] == "#" and s[i] == s[i+1]:
        print("No")
        exit()

if d < c:
    start = b-1
    end = d-1

    flag = 0
    for i in range(start, end+1):
        if s[i-1] == "." and (s[i-1] == s[i]) and (s[i] == s[i+1]):
            flag = 1
    if flag == 0:
        print("No")
        exit()

# if c == d:
#     print("No")
#     exit()
# elif c < b:
#     start = a-1
#     end = c-1

#     sharp_count = 0
#     for i in range(start+1, (end-1)+1):
#         if s[i] == "#" and s[i] == s[i+1]:
#             print("No")
#             exit()

#     start = b-1
#     end = d-1

#     sharp_count = 0
#     for i in range(start+1, (end-1)+1):
#         if s[i] == "#" and s[i] == s[i+1]:
#             print("No")
#             exit()
# elif c < d:
#     start = a-1
#     end = d-1

#     sharp_count = 0
#     for i in range(start+1, (end-1)+1):
#         if s[i] == "#" and s[i] == s[i+1]:
#             print("No")
#             exit()
# elif d < c:
#     start = a-1
#     end = c-1

#     sharp_count = 0
#     for i in range(start+1, (end-1)+1):
#         if s[i] == "#" and s[i] == s[i+1]:
#             print("No")
#             exit()

#     start = b-1
#     end = d-1
#     dot_count = 0
#     count = 0
#     for i in range(start-1, (end+1)+1):
#         if s[i] == ".":
#             count += 1
#         else:
#             dot_count = max(dot_count, count)
#             count = 0
#     if dot_count <= 2:
#         print("No")
#         exit()
print("Yes")

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
S = s[:max(c,d)]
#print(S)
l = len(S)
C = True
D = False
for i in range(l-1):
  if i >= min(a,b) and S[i]=='#' and S[i+1]=='#':
    C = False
    break
  if c > d and d > i >= max(a,b)-1:
    if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
      D = True
      
if not C:
  print('No')
elif C and not D:
  if c < d:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

Submission status: Accepted

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

s=input()

if c<d or c<b:
    #先にbをdに運んでから、aをCに運べばいい
    if s[b:d+1].count("##")==0 and s[a:c+1].count("##")==0:
        print("Yes")
    else:
        print("No") 
else:
    if s[b-1:d+2].count("...")==0:
        print("No")
    else:
        if s[b:d+1].count("##")==0 and s[a:c+1].count("##")==0:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

bef = ''
row_dot_max = 0
count = 0
for i, s in enumerate(S):
  if bef == '#' and s == '#' and i > A and i <= max(C,D)-2:
    print('No')
    exit()
  
  if s == '.' and i >= B-2 and i <= D:
    count += 1
  else:
    row_dot_max = max(row_dot_max, count)
    count = 0
  bef = s

row_dot_max = max(row_dot_max, count)
if C > D:
  if row_dot_max >= 3:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

Submission status: Accepted

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

ans = 'Yes'
if '##' in s[a-1:c]:
  ans = 'No'  
if '##' in s[b-1:d]:
  ans = 'No'
  
if c > d:
  if '...' not in s[b-2:d+1]:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b, c, d = map(int, input().split())
s = input()
p = "##" not in s[a:max(c, d)]
if c > d:
    p *= "..." in s[b-2:d+1]
print(p and "Yes" or "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

    # 二個以上連続で岩があったら無理
    for i in range(A + 1, max(C, D)):
        if S[i] == S[i + 1] == "#":
            print("No")
            return

    # 追い抜かす必要がない
    if C < D:
        print("Yes")
        return
    else:
        # 追い抜かす必要がある
        # 3つ以上連続で岩が置かれていない区間があれば良い
        for i in range(B - 1, D):
            if S[i] == S[i + 1] == S[i + 2] == ".":
                print("Yes")
                return

        print("No")
        return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = [i == "#" for i in list(input())]
s.append(False)
def check_route(x,y):
    for i in range(x,y):
        if s[i] and s[i+1]:
            return False
    return True

def check_three(x,y):
    for i in range(x-1,y):
        if (not s[i]) and (not s[i+1]) and (not s[i+2]):
            return True
    return False

if c < d:
    if check_route(a-1,c-1) and check_route(b-1,d-1):
        print("Yes")
    else:
        print("No")
else:
    if check_route(a-1,c-1) and check_route(b-1,d-1):
        if check_three(b-1,d-1):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Accepted

Solution code:
N,A,B,C,D=map(int,input().split())
s=list('.'+input())
def ren(start,end):
    count=0
    MAX=0
    for k in range(start,end+1):
        if s[k]==".":
            count+=1
            MAX=max(count,MAX)
        else:
            count=0
    return MAX>=3


def S(snuke,c):
    while snuke<=c and s[snuke]==".":
        if snuke==c:
            return True
        if s[snuke+1]=='#':
            snuke+=2
        else:
            snuke+=1
    return False

def H(hnuke,d):
    while hnuke<=d and s[hnuke]==".":
        if hnuke==d:
            return True
        if s[hnuke+1]=='#':
            hnuke+=2
        else:
            hnuke+=1
    return False


x=S(A,C)
y=H(B,D)

if (B<A and C<D):
    z= x and y and ren(A-1,C+1)

elif (A<B and D<C):
    z= x and y and ren(B-1,D+1)
else:
    z= x and y
print("Yes" if z else "No")

Submission status: Accepted

Solution code:
def main():
    N, A, B, C, D = list(map(int, input().split(' ')))
    S = input()
    if C == D:
        print('No')
    elif C < D:
        for s in [S[(A-1):C], S[(B-1):D]]:
            for i in range(len(s) - 1):
                if s[i:(i+2)] == '##':
                    print('No')
                    return
        print('Yes')
    else:
        # A B D C
        s = S[(A-1):C]
        for i in range(len(s) - 1):
            if s[i:(i + 2)] == '##':
                print('No')
                return
        s = S[(B-2):(D+1)]
        ok = False
        for i in range(1, len(s) - 1):
            if s[(i-1):(i+2)] == '...':
                ok = True
                break
        print('Yes' if ok else '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())

# A < B < D, A < B < C
# A < D, B < C の間に # が2マス連続にあったらNo
# さらに D < C なら すぬけくんとふぬけくんが入れ替わる必要がある。
# すなわち3マス連続...が続いている必要がある(#が2マス連続ないことも注意)

left = A

if C < D:
    right = D
else:
    right = C
    idx = []
    for i in range(B - 2, D - 1):
        if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
            idx.append(i)
    if not idx:
        print('No')
        exit()
    # print('idx', idx)
    # print('idx', S[idx[0]:idx[0] + 10])
# print('N, A, B, C, D', N, A, B, C, D)
T = S[left - 1:right + 1]
# print('T', T)
for i in range(len(T) - 1):
    if T[i] == '#' and T[i + 1] == '#':
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

#<##>が存在すると飛べないのでNG
#c>dの場合には、途中でaがbを追い抜く必要がある。そのスペース=<...>が
#あるか判定
if re.search(r'##',s[a:max(b,d)+1]):
    print('No')
else:
    if c>d:
        if (re.search(r'\.{3,}',s[b-1:d+2])):
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Accepted

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

if re.search(r'##',s[a:max(b,d)+1]):
    print('No')
else:
    if c>d:
        if (re.search(r'\.{3,}',s[b-1:d+2])):
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import re
n,a,b,c,d = map(int,input().split())
s = input()
#a,b,c,d = map(lambda x:x-1,[a,b,c,d])

if re.search(r'##',s[a-1:max(b,d)]):
    print('No')
else:
    if c>d:
        if (re.search(r'\.{3,}',s[b-2:d+1])):
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')