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=input()
bS=S[B-1:D]
a=True
if C<D:
    if "##" in bS:
        a=False
    else:
        aS=S[A-1:C]
        if "##" in aS:
            a=False

else:
    if "##" in bS:
        a=False
    else:
        aS=S[A-1:C]
        if "##" in aS:
            a=False
        else:
            tmp=S[:B-1]+"#"+S[B:]
            aS=tmp[A-1:C]
            j1= ("##" in aS)
            tmp=S[:D-1]+"#"+S[D:]
            aS=tmp[A-1:C]
            j2= ("##" in aS)
            if  ((not "..." in bS) and (j1 and j2)):
                a=False
            
        
        
if a:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math

n, a, b, c, d = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for m in range(m)]
#light = [int(i) for i in input().split()]
s = input()
list = list(s)

#print(n, m)
#print(table)
#print(light)

flag = 1



#A-C B-Dまでの間に岩が2個並んでいたらアウト

for i in range(a-1, c-1) :
    if ( list[i] == '#') :
        if ( list[i+1] == "#") :
            flag = 0

for i in range(b-1, d-1) :
    if ( list[i] == "#") :
        if ( list[i+1] == "#") :
            flag = 0

# D < C　のとき、B-Dまでの間に、3個以上空白がなければアウト

if (d < c) :
    flag = 0
    for i in range(b-2, d-1) :
        if (list[i] == '.' and list[i+1] == '.' and list[i+2] == '.') :
            flag = 1

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

Submission status: Accepted

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

def check() :
    if '##' in S[A-1:C] or '##' in S[B-1:D] :
        return 'No'

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

    return 'No'
        

print(check())

Submission status: Accepted

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

# bをさきに
if c > d:
        a,b = b,a
        c,d = d,c

# c < d
if a < b:
        # bだけ考える
        # aはうごかさない
        t = s[b:d]
        if t.count('##'):
                print('No')
                exit()
        t = s[a:c]
        if t.count('##'):
                print('No')
                exit()
        print('Yes')
        exit()
else:
        t = s[b:d]
        if t.count('##'):
                print('No')
                exit()
        t = s[a-2:c+1]
        if t.count('...') == 0:
                print('No')
                exit()
        print('Yes')
        exit()

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:
    for i in range(A, D):
        if S[i] == '#' and S[i + 1] == '#':
            print("No")
            break
        elif i + 1 == D: print("Yes")
else:
    for i in range(B, D + 1):
        if S[i] == '#' and S[i + 1] == '#':
            print("No")
            break
        elif S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
            for j in range(A, C):
                if S[j] == '#' and S[j + 1] == '#':
                    print("No")
                    break
                elif j + 1 == C: print("Yes")
            break
        elif i + 1 == D + 1: print("No")

Submission status: Accepted

Solution code:
n , a0 , b0 , c0 , d0 = map(int,input().split())
s = input()

# a < b に変換する
if a0 > b0 : # 入れ替える
    a = b0
    b = a0
    c = d0
    d = c0
else : # 入れ替えない
    a = a0
    b = b0
    c = c0
    d = d0

right = max(c,d)
left = min(a,b)
middle = max(a,b)

for i in range(n-1) :
    if s[i] == '#' and s[i+1] == '#' : # 岩が2個連続である場合
        if i <= right - 2 and i >= left - 1 :
            print('No')
            break
else :
    if c < d :
        print('Yes')
    else :
        for i in range(n-2) :
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' : # 入れ替え可能
                if i + 1 == b - 1 :
                    print('Yes')
                    break
                if i <= d - 2 and i >= b - 1 :
                    print('Yes')
                    break
        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 f():
    if "##" in S[A: C + 1]:
        return False

    if "##" in S[B: D + 1]:
        return False

    if C < D:
        return True

    can_over = False
    prev_2 = ""
    prev_1 = ""
    for i in range(B - 1, D + 2):
        now = S[i]
        if prev_1 == prev_2 == now == ".":
            can_over = True

        prev_2, prev_1 = prev_1, now

    return can_over

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

Submission status: Accepted

Solution code:
def main():
    n,a,b,c,d = [int(x) for x in input().split()]
    S = input()
    
    a -= 1
    b -= 1
    c -= 1
    d -= 1

    if a>b:
        a,b,c,d=b,a,d,c
    
    # move b to right
    while b<d:
        if 0<=b-1 and b+1<n and b!=c and S[b-1] == S[b] == S[b+1]=='.':
            break
        if b+1<n and S[b+1]=='.':
            b += 1
        elif b+2<n and S[b+2]=='.':
            b += 2
        else:
            break
    while a<c:
        if a+1<n and S[a+1]=='.' and a+1!=b:
            a += 1
        elif a+2<n and S[a+2]=='.' and a+2!=b:
            a += 2
        else:
            print 'No'
            sys.exit()
    
    while b<d:
        if b+1<n and S[b+1]=='.':
            b += 1
        elif b+2<n and S[b+2]=='.':
            b += 2
        else:
            print 'No'
            sys.exit()
    if a!=c or b!=d:
        print 'No'
    else:
        print 'Yes'


######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()

Submission status: Accepted

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


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


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


if B < A:
    A, B = B, A
    C, D = D, C

if C < D:
    if can_pass(S[A-1:C]) and can_pass(S[B-1:D]):
        print('Yes')
    else:
        print('No')
else:
    if can_pass2(S[B-2:D+1]):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

if "##" in s[b:d+1]:
	# print('b-dで岩２つ')
	ans = 'No'
else:
	if "##" in s[a:c+1]:
		# print('a-cで岩２つ')
		ans = 'No'
	else:#邪魔な岩は無し
		if c>d: #ふぬけを飛び越える必要がある場合
			#ふぬけ君を飛び超えるために3マス以上連続で空いてる場所を探してあげる
			if "..." in s[b-1:d+2]:
				# print('空きマス３つある')
				ans = 'Yes'
			else:#飛び越えるスペースが無かった
				# print(s[b:])
				# print('空きマス３つない・・・')
				ans = 'No'
		else:#ふぬけ、すぬけの順に動かせばいい場合、岩はもう見た
			# print('ふぬけ→すぬけ　OK')
			ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
stone = False
space = False
cnt = 0
if c < d:
  for i in range(a,d-1):
    if s[i] == '#' and stone:
      print('No')
      exit()
    elif s[i] == '#':
      stone = True
    elif stone:
      stone = False
  print('Yes')
else:
  for i in range(a,c-1):
    if s[i] == '#' and stone:
      print('No')
      exit()
    elif s[i] == '#':
      stone = True
      cnt = 0
    elif s[i] == '.':
      stone = False
      if d >= i >= b-2:
        cnt += 1
      if cnt == 3:
        space = True
  if space == False:
    print('No')
    exit()
  print('Yes')

Submission status: Accepted

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

    if c < d:
        count = 0
        for i in range(a, d):
            if s[i] == '#':
                count += 1
                if count == 2:
                    print('No')
                    exit(0)
            else:
                count = 0
        print('Yes')
    else:
        count = 0
        for i in range(a, c):
            if s[i] == '#':
                count += 1
                if count == 2:
                    print('No')
                    exit(0)
            else:
                count = 0
        count = 0
        flag = 0
        for i in range(b - 2, d + 1):
            if s[i] == '.':
                count += 1
                if count == 3:
                    flag = 1
            else:
                count = 0
        print('Yes') if flag else print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if d > c: #B君の方が目的地が遠い
    if S[b:d].count('##') != 0:
        ans = 'No'
    else:
        if S[a:c].count('##') != 0:
            ans = 'No'
else:
    if S[a:c].count('##') != 0:
         ans = 'No'
    else:
        if S[b-2:d+1].count('...') == 0:
            ans = 'No'

print(ans)

Submission status: Accepted

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

def move_b():
  i = B
  keep_next_to_lock = (S[i+1] == "#" or S[i-1] == "#")
  while i != D:
    if S[i+1] == ".":
      i += 1
      keep_next_to_lock = keep_next_to_lock & (S[i+1] == "#" or S[i-1] == "#")
    elif S[i+1] == "#" and S[i+2] ==".":
      i += 2
    else:
      return False
  return True and not (keep_next_to_lock and D < C)

def check_a_b():
  for i in range(A, B-1):
    if S[i+1] == "#" and S[i+2] == "#":
      return False
  return True

if move_b() and check_a_b():
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

not_pass_array = []
can_change_array = []

for i in range(len(S) - 2):
    if S[i] == "#" and S[i + 1] == "#":
        not_pass_array.append(i)
    elif S[i] == "." and S[i + 1] == "." and S[i + 2] == ".":
        can_change_array.append(i + 1)
if S[-1] == "#" and S[-2] == "#":
    not_pass_array.append(len(S) - 2)

# print(not_pass_array, can_change_array)
A = A - 1
B = B - 1
C = C - 1
D = D - 1
if C < D:
    for i in not_pass_array:
        if A >= i:
            continue
        if D <= i:
            print("Yes")
            exit()
        if (A < i and i < C) or (B < i and i < D):
            print("No")
            exit()
    else:
        print("Yes")
        exit()

else:
    for i in not_pass_array:
        if A >= i:
            continue
        if C <= i:
            break
        if (A < i and i < C) or (B < i and i < D):
            print("No")
            exit()
    for b_pos in can_change_array:
        if b_pos >= B and b_pos <= D:
            print("Yes")
            exit()
    print("No")

Submission status: Accepted

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

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

def solve(n, a, b, c, d, s):
    if d > c:
        return all(s[i:i+2] != '##' for i in range(a - 1, d - 1))

    if not all(s[i:i+2] != '##' for i in range(a - 1, c - 1)):
        return False
    
    if not any(s[i:i+3] == '...' for i in range(b - 2, d - 1)):
        return False

    return True

main()

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
a = input()
k = A
found = True
ffond = False
b = 0
c = 0
if C <D :
    while  found == True and k < D:
        if a[k] == "#":
            b += 1
        else:
            b = 0
        if b == 2:
            found = False
        k += 1
    if found == False:
        print("No")
    else:
        print("Yes")
else:
    while  found == True and k < C:
        if a[k] == "#":
            b += 1
            if k > B-3 and k <= D:
                c = 0
        else:
            b = 0
            if k > B-3 and k <=D:
                c +=1
        if b == 2:
            found = False
        if c == 3:
            ffond = True
        k += 1
    if found == False or ffond == False:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
flag2 = True
flag3 = False
if C < D:
    AS = S[A:C-1]
    BS = S[B:D-1]
    for i in range(len(S)-1):
        if BS[i:i+2] == '##':
            flag2 = False
    for i in range(len(S)-1):
        if AS[i:i+2] == '##':
            flag2 = False
    if flag2:
        print('Yes')
    else:
        print('No')
else:
    AS = S[A:C-1]
    BS = S[B:D-1]
    BD = S[B-2:D+1]
    # print(BD)
    for i in range(len(S)-2):
        if BD[i:i+3] == '...':
            flag3 = True
    for i in range(len(S)-1):
        if BS[i:i+2] == '##':
            flag2 = False
    for i in range(len(S)-1):
        if AS[i:i+2] == '##':
            flag2 = False
    if flag2 and flag3:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

DS = False
TD = False
nd = 0
ns = 0
if A + 1 == B:
    nd = 1
for x in range(A+1, max(C, D)+1):
    s = S[x-1]
    if s == '.':
        if B - 1 <= x <= D + 1:
            nd = nd + 1
        ns = 0
    else:
        nd = 0
        ns = ns + 1
    if A <= x <= C or B <= x <= D:
        if ns >= 2:
            DS = True
    if B <= x <= D + 1:
        if nd >= 3:
            TD = True

if DS == True or (D < C and TD == False):
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

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

result = "Yes"
onon = True

if C < D:
    for i in range(A-1,D):
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(A-1,C):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B -2,D-1):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)

Submission status: Accepted

Solution code:
data = input().split()
s = input()
end_max = int(max(data[3:5]))
s = s[int(data[1])-1:end_max]

if '##' in s:
    print('No')
else:
    if int(data[3]) < int(data[4]):
        print('Yes')
    else:
        s = s[int(data[2])-2:int(data[4])+1]
        if '...' in s:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
import sys


scan = sys.stdin.readline


def main():
    n, a, b, c, d = map(int, scan().rstrip().split())
    stone = [c == "#" for c in scan().rstrip()]

    if (a - b)*(c - d) > 0:
        if a > b:
            front = a
            behind = b
            goal_front = c
            goal_behind = d
        else:
            front = b
            behind = a
            goal_front = d
            goal_behind = c

        for pos, goal in [(front, goal_front), (behind, goal_behind)]:
            while pos != goal:
                if stone[pos] and stone[pos + 1]:
                    print("No")
                    exit(0)
                elif stone[pos]:
                    pos += 2
                else:
                    pos += 1

        print("Yes")
        exit(0)

    else:
        if a > b:
            front = a
            behind = b
            goal_front = c
            goal_behind = d
        else:
            front = b
            behind = a
            goal_front = d
            goal_behind = c
        
        while behind != goal_behind:
            if stone[behind] and stone[behind + 1]:
                print("No")
                exit(0)
            elif stone[behind] and behind + 2 == front:
                if front == goal_front:
                    print("No")
                    exit(0)
                elif stone[front] and stone[front + 1]:
                    print("No")
                    exit(0)
                elif stone[front]:
                    front += 2
                else:
                    front += 1
                behind += 2
            elif behind + 1 == front and stone[behind + 1]:
                if front == goal_front:
                    print("No")
                    exit(0)
                elif stone[front] and stone[front + 1]:
                    print("No")
                    exit(0)
                elif stone[front]:
                    front += 2
                else:
                    front += 1
                behind += 1
            elif behind + 1 == front or stone[behind]:
                behind += 2
            else:
                behind += 1

        while front != goal_front:
            if stone[front] and stone[front + 1]:
                print("No")
                exit(0)
            elif stone[front]:
                front += 2
            else:
                front += 1
        
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int, input().split())
s = input()
ans = "Yes"
sharp = 0
dot = 0
for i in s[a-1:max(c,d)]:
    if i == ".":
        sharp = 0
    else:
        sharp += 1
        if sharp == 2:
            ans = "No"
            break
if c > d and ans == "Yes":
    ans = "No"
    for i in s[b-2:d+1]:
        if i == ".":
            dot += 1
            if dot == 3:
                ans = "Yes"
                break
        else:
            dot = 0
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, A, B, C, D = MI()
    S = "."+ST()
    for i in range(min(A, B), max(C, D) ):
        if S[i] == "#" and S[i - 1] == "#":
            print("No")
            exit()
    
    if (A - B) * (C - D) >= 0:
        print("Yes")
    else:
        #3連続あるか判定
        for i in range(max(A, B) + 1, min(N,min(C, D) + 2)):
            if S[i] == "." and S[i - 1] == "." and S[i - 2] == ".":
                print("Yes")
                exit()
        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()

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,a,b,c,d = m();
ss = list(input())
if c < d:
	k = s(ss[b-1:d])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
	k = s(ss[a-1:c])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
	print("Yes")
	exit()
else:
	# c > d
	count = 0
	k = s(ss[b-2:d])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
		if k[i][0] == "." and k[i][1] >= 3:
			count = 1
	if count == 1:
		k = s(ss[a-1:c])
		for i in range(len(k)):
			if k[i][0] == "#" and k[i][1] >= 2:
				print("No")
				exit()
		print("Yes")
		exit()
	else:
		ss[d-1] = "#"
		k = s(ss[a-1:c])
		for i in range(len(k)):
			if k[i][0] == "#" and k[i][1] >= 2:
				print("No")
				exit()
		print("Yes")
		exit()

Submission status: Accepted

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

import sys
if B > C:
    isi = 0
    cnt = 0
    for j in range(A-1,C):
        i = S[j]
        if i == '.':
            cnt = 0
        elif i == '#':
            cnt += 1
            isi = max(isi,cnt)
    cnt = 0
    for j in range(B-1,D):
        i = S[j]
        if i == '.':
            cnt = 0
        elif i == '#':
            cnt += 1
            isi = max(isi,cnt)
    if isi <= 1:
        print('Yes')
    else:
        print('No')
    sys.exit()


aki = 0
isi = 0
cnt = 0
for j in range(min(A,B)-1,max(C,D)):
    i = S[j]
    if i == '.':
        cnt = 0
    elif i == '#':
        cnt += 1
        isi = max(isi,cnt)
        
cnt = 0
for j in range(B-2,min(D+1,N)):
    i = S[j]
    if i == '#':
        cnt = 0
    elif i == '.':
        cnt += 1
        aki = max(aki,cnt)
        

if C > D:
    if aki >= 3 and isi <= 1:
        print('Yes')
    else:
        print('No')
else:
    if isi <= 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

a = A - 1
b = B - 1
c = C - 1
d = D - 1
n = N - 1

is_able = False

while True:
  if a != c and (a+1) <= n and S[a+1] == "." and (a+1) != b:
    a += 1
  elif a != c and (a+2) <= n and S[a+2] == "." and (a+2) != b:
    a += 2
  elif b != d and (b+1) <= n and S[b+1] == "." and (b+1) != a:
    b += 1
  elif b != d and (b+2) <= n and S[b+2] == "." and (b+2) != a:
    b += 2
  else:
    is_able = False
    break
    
  if a == c and b == d:
    is_able = True
    break
    
if is_able:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

def x(s):
    try:
        s.index("##")
    except:
        return True
    else:
        return False

n,a,b,c,d=intinput()
s=input()
if c<d:
    if x(s[a-1:d]):
        print("Yes")
    else:
        print("No")
else:
    try:
        s[b-2:d+1].index("...")
    except:
        print("No")
    else:
        if x(s[a - 1:c]):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
s = list(input())
n = n-(a-1)
b = b-(a-1)-1
c = c-(a-1)-1
d = d-(a-1)-1
for i in range(a-1):
    s.pop(0)
a = a-(a-1)-1
for i in range(n-(max(c,d)+1)):
    s.pop(-1)
n -= n-(max(c,d)+1)

check = True
for i in range(n-1):
    if s[i] == "#" and s[i+1] == "#":
        check = False

temp = False
for i in range(b,d+1):
    if i+1 < n:
        if s[i] == "." and s[i-1] == "." and s[i+1] == ".":
            temp = True
            break
    else:
        temp = True


if check == False:
    print("No")
else:
    if temp:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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


def f(S, N, A, B, C, D):
    if B > C:
        if g(S, A, C) or g(S, C, D):
            return 'No'
        else:
            return 'Yes'
            
    elif C < D:
        if g(S, A, D):
            return 'No'
        else:
            return 'Yes'
        
    else:
        if g(S, A, B):
            return 'No'

        if g2(S, B-1, D):
            return 'Yes'
        
        return 'No'


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

    return False



def g2(S, X, Y):
    for i in range(X-1, Y-1):
        if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
            return True

    return False



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

    print(f(S, N, A, B, C, D))
 


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B,C,D =map(int,input().split())
S = input()[min(A,B):max(C,D) + 1]

if C < D:
  if not "##" in S[B:D] and not "##" in S[A:C]:
    print("Yes")
  else:
    print("No")
else:
  if not "##" in S[B:D] and not "##" in S[A:C]:
    if "..." in S[B - 3:D]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

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

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

if A > B:
    A, B = B, A
    C, D = D, C

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