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:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,a,b,c,d = li_()
n += 1
s = ns()


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

    else:
        print("Yes")

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

    elif "##" in s[a:c + 1] or "##" in s[b:d + 1]:
        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 a < b < d < c:
    ok = True
    for i in range(a, c):
        if s[i] == '#' and s[i+1] == '#':
            ok = False
            break

    ok2 = True
    for i in range(b, d):
        if s[i] == '#' and s[i+1] == '#':
            ok2 = False
            break

    ok3 = False
    for i in range(b, d+1):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            ok3 = True
            break

    if ok and ok2 and ok3:
        print('Yes')
    else:
        print('No')
else:
    ok = True
    for i in range(a, c):
        if s[i] == '#' and s[i+1] == '#':
            ok = False
            break

    ok2 = True
    for i in range(b, d):
        if s[i] == '#' and s[i+1] == '#':
            ok2 = False
            break

    if ok and ok2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n, a, b, c, d = map(int, input().split())
    s = input()
    if c<d:
        for i in range(a-1, d-1):
            if s[i]=='#' and s[i+1]=='#':
                return False
        if s[c-1]=='#' or s[d-1]=='#':
            return False
        return True
    elif c==d:
        return False
    else:
        flag = False
        for i in range(a-1, c-1):
            if s[i]=='#' and s[i+1]=='#':
                return False
            if s[i-1]=='.' and s[i]=='.' and s[i+1]=='.' and b-1<=i<=d-1:
                flag = True
        if s[c-1]=='#' or s[d-1]=='#':
            return False
        if not flag:
            return False
    return True
if solve():
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int,input().split())
st = input()
if C == D :
  print("No")
elif C < D:#連続で岩が置かれていなければおっけー
  flag = 0
  st1 = st[A-1:C]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-1:D]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
  if flag :
    print("No")
  else:
    print("Yes")
    
else:#入れ替わりを行う必要がある
  flag = 0
  irekaeble = 0
  st1 = st[A-1:C]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-1:D]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-2:D+1]
  for i in range(len(st1)-2):
    if st1[i:i+3] == "...":
      irekaeble = 1
  
  if flag or irekaeble == 0:
    print("No")
  else:
    print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

def check(x,y):
    ok = 1
    num = 0
    for moji in s[x:y]:
        if moji == "#":
            num+=1
        else:
            num = 0
        if num >= 2:
            ok = 0
            break
    return ok

def check3(x,y):
    ok = 0
    num = 0
#    print(s)
#    print(s[x-1:y+2],x,y)
    for moji in s[x-1:y+2]:
        if moji == ".":
            num+=1
        else:
            num = 0
        if num >= 3:
            ok = 1
            break
    return ok


if c < d:
    if check(a,c) and check(b,d):
        print("Yes")
    else:
        print("No")

else:
    if check3(b,d) and check(a,c):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A


def Yes():
    print('Yes')
    sys.exit()


def No():
    print('No')
    sys.exit()


if __name__ == '__main__':
    N, A, B, C, D = InputToInt()
    L = input()
    if D > C:
        for i in range(A, D-2):
            if L[i:i+2] == '##':
                No()
        Yes()

    if D < C:
        for i in range(A, C-2):
            if L[i:i+2] == '##':
                No()
        if '...' in L[B-2:D+1]:
            Yes()
        else:
            No()

Submission status: Accepted

Solution code:
n, a, b, c, d = [int(item) for item in input().split()]
s = "#" + input().rstrip() + "#"

front = min(a, b, c, d)
back = max(a, b, c, d)
for i in range(front, back):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
if d > c:
    print("Yes")
    exit()
state = "No"
if d < c:
    for i in range(b, d+1):
        if s[i-1] == "." and s[i] == "." and s[i+1] == ".":
            state = "Yes"
            break
print(state)

Submission status: Accepted

Solution code:
import sys
N,A,B,C,D=map(int,input().split())
S=str(input())
stone=[]
A=A-1
B=B-1
C=C-1
D=D-1
#2つ連続があるか
double=[]
for i in range(0,N-1):
    if(S[i]=='#' and S[i+1]=='#'):
        double.append(i)
#２つ連続判定
for i in range(0,len(double)):
    if(A<double[i] and double[i]<C):
        print("No")
        sys.exit()
    elif(B<double[i] and double[i]<D):
        print("No")
        sys.exit()

#追い越しがいらないならこれでもうOK
if((B-A)*(D-C)>0):
    print("Yes")
    sys.exit()

#追い越しがいるのならB-Dの範囲を中心とした連続した3ますの空白が必要
tri=False
for i in range(B,D+1):
    if(S[i-1]=='.' and S[i]=='.' and S[i+1]=='.'):
        tri=True

if(tri):
    print("Yes")
    sys.exit()
else:
    print("No")
    sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  _, s_s, f_s, s_e, f_e = map(int, input().split())
  n = input().strip()

  s_s = s_s - 1
  s_e = s_e - 1
  f_s = f_s - 1
  f_e = f_e - 1

  if '##' in n[s_s + 1:s_e] or '##' in n[f_s + 1:f_e]:
    print('No')
  elif s_e < f_e:
    print('Yes')
  elif '...' in n[f_s - 1:f_e + 2]:
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, A, B, C, D = map(int, input().split())
    S = input().strip()
    S = S[A-1:max(C, D)]

    if '##' in S:
        return 'No'

    if D > C:
        return 'Yes'

    if '...' in S[B-2:D+1]:
        return 'Yes'

    return 'No'


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


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

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

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

    if d > c:
        print('Yes')
        return

    for i in range(b - 1, d):
        if s[i - 1] == s[i] == s[i + 1] == '.':
            print('Yes')
            return

    print('No')
    return


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, A, B, C, D = i2nn()
    S = i2s()

    s1 = S[A:C-1]
    s2 = S[B:D-1]
    if s1.find('##') >= 0 or s2.find('##') >= 0:
        print('No')
        return

    if C < D:
        print('Yes')
        return
    else:
        s3 = S[B-2:D+1]
        if s3.find('...') >= 0:
            print('Yes')
            return
        print('No')
        return

main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

N, A, B, C, D = map(int, readline().split())
A, B, C, D = (x - 1 for x in [A, B, C, D])

S = readline().rstrip()
S2 = [S[i:i+2] for i in range(0, N - 1)]
S3 = [S[i:i+3] for i in range(0, N - 2)]

if C < D:
    ac = S2[A:C]
    bd = S2[B:D]
    if ac.count('##') > 0:
        print('No')
    elif bd.count('##') > 0:
        print('No')
    else:
        print('Yes')
else:
    bd = S2[B:D]
    ac = S2[A:C]
    if bd.count('##') > 0:
        print('No')
    elif ac.count('##') > 0:
        print('No')
    else:
        abd = S3[B - 1: D]
        if abd.count('...') > 0:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

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

    if C < D:  # 追い抜かない
        for i in range(B, D):
            if S[i] == '#' and S[i+1] == '#':
                return False

        for i in range(A, C):
            if S[i] == '#' and S[i+1] == '#':
                return False
    else:  # 追い抜くパターン
        found = False
        for i in range(B, D+1):
            if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
                found = True
                break
        if not found:
            return False

        for i in range(A, C):
            if S[i] == '#' and S[i+1] == '#':
                return False

    return True


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

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

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

ACarr = S[A-1:C]
BDarr = S[B-1:D]
ACseq = get_sequence(ACarr)[1]
ACrock = ACseq[1::2]
BDseq = get_sequence(BDarr)[1]
BDrock = BDseq[1::2]
if max(ACrock) > 1 or max(BDrock) > 1:
    print('No')
    exit()
elif C > D:
    if ((S[B-2]==S[B-1] and BDseq[0] >= 2)
        or (S[D]==S[D-1] and BDseq[-1] >= 2)
        or max(BDseq[::2]) >= 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()
if c<b:
    if not '##' in s[a-1:c] and not '##' in s[b-1:d]:
        print('Yes')
    else:
        print('No')
elif b<c<d:
    if not '##' in s[a-1:d]:
        print('Yes')
    else:
        print('No')
else:
    if '##' in s[a-1:c]:
        print('No')
    else:
        if '...' in s[b-2:d+1]:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
N, A, B, C, D = [int(_) for _ in input().split()]
A -= 1
B -= 1
C -= 1
D -= 1
S = input()
if C > D:
    C, D = D, C
    A, B = B, A
if '##' in S[B:D] or '##' in S[A:C]:
    print('No')
elif A < B or '...' in S[A - 1:C + 2]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, A, B, C, D = LI_()
    S = SI()
    ans = True
    # AC
    for i in range(A, C):
        if S[i: i + 2] == '##':
            ans = False
            break
    # BD
    if ans:
        for i in range(B, D):
            if S[i: i + 2] == '##':
                ans = False
                break
    # if A BD C
    if ans and D < C:
        tmp = False
        for i in range(B - 1, D):
            if S[i: i + 3] == '...':
                tmp = True
                break
        ans = ans and tmp

    ans = 'Yes' if ans else 'No'
    return ans

print(main())

Submission status: Accepted

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

res = 'Yes'
# case 1
if C < D:
    for i in range(A-1, C-1):
        if S[i] == '#' and S[i+1] == '#':
            res = 'No'
    for i in range(B-1, D-1):
        if S[i] == '#' and S[i+1] == '#':
            res = 'No'
else:
    cnt = 0
    for i in range(B-2, D-1):
        if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
            cnt += 1
    if cnt == 0:
        res = 'No'
    for i in range(A-1, C-1):
        if S[i] == '#' and S[i+1] == '#':
            res = 'No'

print(res)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b,c,d = LI()
    s = input()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    if c == d:
        print("No")
    else:
        if c < d:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            print("Yes")
        else:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[b-1:d+2]
            for i in range(len(k)-2):
                if k[i] == k[i+1] == k[i+2] == ".":
                    print("Yes")
                    quit()
            print("No")
    return

#B
def B():
    s = S()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

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

S = input()
x = [0]

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

flag = 0

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

flag2 = 1

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

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

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv('LOCAL'):
    sys.stdin = open('_in.txt', 'r')

sys.setrecursionlimit(2147483647)
INF = float('inf')

N, A, B, C, D = list(map(int, sys.stdin.readline().split()))
S = '.' + sys.stdin.readline().rstrip()


def can_go(s, e):
    i = s + 1
    while i <= e:
        if S[i - 1] == S[i] == '#':
            return False
        i += 1
    return True


def solve2():
    assert D < C
    if not can_go(A, C) or not can_go(B, D):
        return False
    i = B
    while i <= D:
        if S[i - 1] == S[i] == S[i + 1] == '.':
            return True
        i+=1
    return False


def solve():
    if C < D:
        return can_go(A, D)
    return solve2()


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

Submission status: Accepted

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

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

    if flg:
        print("Yes")
    else:
        print("No")
else:
    count = 0
    flg=True
    for i in range(B,D):
        if S[i]=="#":
            count+=1
        else:
            count=0
        if count>=2:
            flg=False
            break
    count=0
    count2 = 0
    flg2=False
    for i in range(A,C):
        if S[i]=="#":
            count+=1
        else:
            count=0
        if count>=2:
            flg=False
            break
        if i>=B-2 and i<=D:
            if S[i]==".":
                count2+=1
            else:
                count2=0
            if count2>=3:
                flg2=True
    if flg and flg2:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n, a, b, c, d = get_li()
    s = get_str()
    if "##" in s[a:c]:
        print("No")
        return
    if "##" in s[b:d]:
        print("No")
        return
    if c > d and ("..." not in s[b:d]) and s[b-2:b+1] != "..." and s[b-1:b+2] != "..." and s[d-2:d+1] != "...":
        print("No")
        return
    print("Yes")
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


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

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

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

Submission status: Accepted

Solution code:

n, a, b, c, d =[int(i) for i in input().split()]
s = input()

if c < d:
    s1 = s[a-1:d]
    if s1.count("##") == 0:
        print("Yes")

    else:
        print("No")

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

    else:
        print("No")

Submission status: Accepted

Solution code:
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, A, B, C, D = map(int, input().split())
    S = input()
    Able = False
    if C < D:
        for i in range(A-1, C-1):
            if S[i] == S[i+1] == "#":
                break
        else:
            for i in range(B-1, D-1):
                if S[i] == S[i+1] == "#":
                    break
            else: Able = True
    else:
        for i in range(A-1, C-1):
            if S[i] == S[i+1] == "#":
                break
        else:
            for i in range(B-1, D):
                if S[i-1] == S[i] == S[i+1] ==".":
                    Able = True
                    break
    print("Yes" if Able else "No")



    INF = 10 ** 25
    mod = 7 + 10 ** 9
    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

OK = True
if A < C < B < D or A < B < C < D:
    if S[A:C+1].count("##") == 0 and S[B:D+1].count("##") == 0:
        pass
    else:
        OK = False
else:
    if S[A:C+1].count("##") == 0 and S[B:D+1].count("##") == 0 and S[B-1:D+2].count("...") > 0:
        pass
    else:
        OK = False
if OK:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
#v = list(map(int,input().split()))
s = input()
flag = True
flag2 = False
if d>c:
    tmpflag = False
    for i in range(b-1,d):
        if tmpflag:
            if s[i] == '#':
                flag = False
                break
            else:
                tmpflag = False
        elif s[i] == '#':
            tmpflag = True
    
    for i in range(a-1,c):
        if tmpflag:
            if s[i] == '#':
                flag = False
                break
            else:
                tmpflag = False
        elif s[i] == '#':
            tmpflag = True
    if flag:
        print('Yes')
    else:
        print('No')
else:
    tmpflag = False
    for i in range(a-1,c):
        if tmpflag:
            if s[i] == '#':
                flag = False
                break
            else:
                tmpflag = False
        elif s[i] == '#':
            tmpflag = True
    counter = 0
    for i in range(b-2,d+1):
        if s[i] == '.':
            counter += 1
            if counter == 3:
                flag2 = True
        if s[i] == '#':
            counter = 0
    if flag and flag2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def f(x, y):
	if '##' in S[x - 1:y]:
		return 0
	else:
		return 1

def g(x, y):
	if '...' in S[x - 2:y + 1]:
		return 1
	else:
		return 0

N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
	x = f(A, C) * f(B, D)
	if x == 1:
		print('Yes')
	else:
		print('No')
else:
	x = f(A, C) * f(B, D) * g(B, D)
	if x == 1:
		print('Yes')
	else:
		print('No')

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
if (A-B)*(C-D) < 0 and "..." not in S[max(A,B)-2:min(C,D)+1]:
  print("No")
elif "##" 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 = list(input())

for i in range(min(a, b), max(c, d)):
  if S[i-1] == "#" and S[i] == "#":
    print("No")
    exit()
if a < b and c > d or a > b and c < d:
#  print("mark")
  for i in range(max(a, b)-1, min(c, d)):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
      print("Yes")
      exit()
  print("No")
  exit()
print("Yes")

Submission status: Accepted

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

# check no '##' s on the way
goal = max([c,d])
for x in range(a+1, goal):
  if s[x] == '#' and s[x+1] == '#':
    print('No')
    exit(0)

if c < d:
  print('Yes')
  exit(0)

for x in range(b, d+1):
  if s[x] == '.' and s[x+1] == '.' and s[x-1] == '.':
    print('Yes')
    exit(0)

print('No')