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())
arr=[]
for i in range(len(s)):
	if(s[i]=='#'):
		arr.append(-1)
	elif(s[i]=='.'):
		arr.append(0)

a-=1
b-=1
c-=1
d-=1
flag=0
arr[a]=1
arr[b]=2
pos1=a
pos2=b
if(c<d):
	while(pos2<d):
		if(pos2+1<n and arr[pos2+1]==0):
			pos2+=1
			arr[pos2-1]=0
			arr[pos2]=2
		else:
			if(pos2+2<n and arr[pos2+2]==0):
				pos2+=2
				arr[pos2-2]=0
				arr[pos2]=2
			else:
				flag=1
				break
		#print(arr)
	while(pos1<c):
		if(pos1+1<n and arr[pos1+1]==0):
			arr[pos1]=0
			arr[pos1+1]=1
			pos1+=1
		else:
			if(pos1+2<n and arr[pos1+2]==0):
				pos1+=2
				arr[pos1-2]=0
				arr[pos1]=1
			else:
				flag=1
				break
else:
	
	#print(flag)
	while(pos2>pos1):
		if(pos1+1<n and arr[pos1+1]==0):
			arr[pos1]=0
			arr[pos1+1]=1
			pos1+=1
		else:
			if(pos1+2<n and arr[pos1+2]==0):
				pos1+=2
				arr[pos1-2]=0
				arr[pos1]=1
			else:
				if(pos2<d):
					if(pos2+1<n and arr[pos2+1]==0):
						pos2+=1
						arr[pos2-1]=0
						arr[pos2]=2
					else:
						if(pos2+2<n and arr[pos2+2]==0):
							pos2+=2
							arr[pos2-2]=0
							arr[pos2]=2
						else:
							flag=1
							break
				else:
					flag=1
					break
		#print(flag)
		#print(arr)
	if(flag==0):
		while(pos1<c):
			if(pos1+1<n and arr[pos1+1]==0):
				arr[pos1]=0
				arr[pos1+1]=1
				pos1+=1
			else:
				if(pos1+2<n and arr[pos1+2]==0):
					pos1+=2
					arr[pos1-2]=0
					arr[pos1]=1
				else:
					flag=1
					break
		while(pos2<d):
			if(pos2+1<n and arr[pos2+1]==0):
				pos2+=1
				arr[pos2-1]=0
				arr[pos2]=2
			else:
				if(pos2+2<n and arr[pos2+2]==0):
					pos2+=2
					arr[pos2-2]=0
					arr[pos2]=2
				else:
					flag=1
					break

if(flag==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 = list(input())
if D < C:
    sl = [0]
    ml = [0]
    cnt = 0
    mcnt = 0
    for i in range(A+1,B-1):
        if [S[i],S[i+1]] == ['#','#']:
            cnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            sl.append(cnt)
            cnt = 0
        if i == B-2 :
            sl.append(cnt)
            cnt = 0
    for i in range(D+1,C):
        if [S[i],S[i+1]] == ['#','#']:
            cnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            sl.append(cnt)
            cnt = 0
        if i == C-1 :
            sl.append(cnt)
    for i in range(B-1,D+1):
        if [S[i],S[i+1]] == ['.','.']:
            mcnt += 1
        elif [S[i],S[i+1]] == ['.','#']:
            ml.append(mcnt)
            mcnt = 0
        if i == D:
            ml.append(mcnt)
            mcnt = 0
    if max(sl) >= 1:
        print('No')
    elif max(ml) <= 1:
        print('No')
    else:
        print('Yes')
else:
    acnt = 0
    bcnt = 0
    al = [0]
    bl = [0]
    for i in range(A+1,C):
        if [S[i],S[i+1]] == ['#','#']:
            acnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            al.append(acnt)
            acnt = 0
        if i == C-1 :
            al.append(acnt)
            acnt = 0
    for i in range(B+1,D):
        if [S[i],S[i+1]] == ['#','#']:
            bcnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            bl.append(bcnt)
            bcnt = 0
        if i == C-1 :
            bl.append(bcnt)
            bcnt = 0
    if max(al) >= 1:
        print('No')
    elif max(bl) >= 1:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

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

if c<d:
    m=d
else:
    m=c

for i in range(a, m-3):
        if s[i] == '#' and s[i+1] == '#':
            ans=0

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

Submission status: Accepted

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

S = list(input().split()[0])

result = "Yes"
flag = False

for i in range(B, D - 1):
    if S[i] == "#" and S[i + 1] == "#":
        result = "No"
        print(result)
        flag = True
        break
if not flag:
    for i in range(A, C - 1):
        if S[i] == "#" and S[i + 1] == "#":
            result = "No"
            print(result)
            flag = True
            break

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

Submission status: Accepted

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

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

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    for i in range(A - 1, C - 1):
        if S[i:i + 2] == '##':
            ret = NO
            print(ret)
            return
    for i in range(B - 1, D - 1):
        if S[i:i + 2] == '##':
            ret = NO
            print(ret)
            return
    if D < C:
        ret = NO
        for i in range(B - 2, D - 1):
            if S[i:i + 3] == '...':
                ret = YES
                break

    #if '##' in S[A - 1:C] or '##' in S[B - 1:D]:
    #    ret = NO
    #else:
    #    if D < C:
    #        #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
    #        if not '...' in S[B - 2:D + 1]:
    #            ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, a, b, c, d = MI()
s = [s for s in input()]
aki = []
for i in range(1, len(s)):
    if s[i] == '#' and s[i-1] == '#':
        if a-1 < i < c-1 or b-1 < i < d-1:
            print('No')
            exit()

if c < d:
    print('Yes')
else:
    for i in range(2, len(s)):
        if s[i] == '.' and s[i-1] == '.' and s[i-2] == '.':
            aki.append(i)
    if s[d-2] == '#' and s[d] == '#':
        for num in aki:
            if b-1 < num < d-2:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d-2] == '#':
        for num in aki:
            if b-1 < num < d-2:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d] == '#':
        for num in aki:
            if b-1 <= num < d:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d-2] == '.' and s[d] == '.':
        print('Yes')
        exit()
    print('No')

Submission status: Accepted

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

S = input()

def AA(mojiretu):
    if '##' in mojiretu:
     print("No")
    else:
     print("Yes")

Scp = S
if C < D:
      AA(Scp[A:D])
      
else:
    if "..." in Scp[B-2:D]:
      AA(Scp[A:C])
    else:
      Scp = Scp[:D-1]+"#" + Scp[D:]
      AA(Scp[A:C])

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 False
    if d < c and '...' not in s[b - 2:d + 1]:
        return False
    return True

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

Submission status: Accepted

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


flag1 = False
block = 0
for i in range(b, len(s)):
    if block == 2:
        flag1 = False
        break
    elif i == d-1:
        flag1 = True
        break
    elif s[i] == ".":
        block = 0
    elif s[i] == "#":
        block += 1

if flag1 == True:
    s2 = s[:d-1]+'#'+s[d:]
    flag1 = False
    block = 0
    for i in range(a, len(s)):
        if block == 2:
            flag1 = False
            break
        elif i == c-1:
            flag1 = True
            break
        elif s2[i] == ".":
            block = 0
        elif s2[i] == "#":
            block += 1


flag2 = False
flag3 = False
temp = 0
block = 0
for i in range(b-2,c-2):
    if temp == 3:
        flag2 = True
        temp = i-1
        break
    elif s[i] == "#":
        temp = 0
    elif s[i] == ".":
        temp += 1

if flag2 == True:
    flag3 = False
    block = 0
    s1 = s[:temp-1]+'#'+s[temp:]
    for i in range(a, len(s)):
        if block == 2:
            flag3 = False
            break
        elif i == c-1:
            flag3 = True
            break
        elif s1[i] == ".":
            block = 0
        elif s1[i] == "#":
            block += 1

    if flag3 == True:
        s3 = s1[:c - 1] + '#' + s1[c:]
        flag3 = False
        block = 0
        for i in range(temp, len(s)):
            if block == 2:
                flag3 = False
                break
            elif i == d-1:
                flag3 = True
                break
            elif s3[i] == ".":
                block = 0
            elif s3[i] == "#":
                block += 1

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

Submission status: Accepted

Solution code:
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]
can_jump = [0] + [1-S[i]*S[i+1] for i in range(1,N-1)]
can_change = [0] + [(1-S[i])*(1-S[i+1])*(1-S[i+2]) for i in range(1,N-2)]

def Solution():
  if not all(can_jump[A:C]):
    return False
  if not all(can_jump[B:D]):
    return False
  
  if C<D:
    return True
  if C>D:
    if any(can_change[B-1:D]):
      return True
    else:
      return False

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

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
li = input()
if c<b:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
elif c<d:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
else:
  li = li[:d+1]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  elif li[b-2-a+1] == "." and li[b-a+1] == ".":
    print("Yes")
  else:
    li = li[b-a:]
    if li.find("...") == -1:
      print("No")
    else:
      print("Yes")

Submission status: Accepted

Solution code:
line = input().split()
object_ = input()

N = int(line[0])
A = int(line[1])-1
B = int(line[2])-1
C = int(line[3])-1
D = int(line[4])-1

placing_objects = [True if s == '#' else False for s in list(object_)]

def main():
    if (A < B and C < D) or (A > B and C > D):
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1] and i > A and i < max(C, D):
                print('No')
                return
        print('Yes')
        return
    else:
        possible_trans = False
        trans_index = []
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1] and i > A and i < max(C, D):
                print('No')
                return
            if i < N-2 and (not placing_objects[i]) and (not placing_objects[i+1]) and (not placing_objects[i+2]):
                possible_trans = True
                trans_index.append(i+1)
        if not possible_trans:
            if C < D:
                if placing_objects[C-1] or placing_objects[C+1]:
                    print('No')
                    return
            else:
                if placing_objects[D-1] or placing_objects[D+1]:
                    print('No')
                    return
        else:
            if A > B:
                if A > max(trans_index):
                    print('No')
                    return
            else:
                if B > max(trans_index) or D < min(trans_index):
                    print('No')
                    return
        print('Yes')
        
main()

Submission status: Accepted

Solution code:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
 
N,A,B,C,D = map(int,input().split())
S = list(input())
SA = deepcopy(S)
SB = deepcopy(S)
SA[B-1] = "#"
SB[D-1]=  "#"
 
bool=False
for i in range(A,max(D,C)):
    if S[i]=="#" and S[i-1]=="#":
        print("No")
        exit()
for i in range(B-1,D):
    if i >= N-1:
        break
    if S[i] == "." and S[i-1]=="." and S[i+1]==".":
        bool = True
        break
if bool:
    print("Yes")
else:
    bool1,bool2,bool3 = True,True,True
    #Bを先にDに進める戦略
    for i in range(A,C):
        if SB[i-1]=="#" and SB[i]=="#":
            bool1 = False
            break
    #Aを先に進めるため最初進められるかどうかの判定
    for i in range(A,C):
        if SA[i-1]=="#" and SA[i]=="#":
            bool2 = False
            break
    SA[B-1]="."
    SA[C-1]="#"
    #Aを先にCに進める戦略
    for i in range(B,D):
        if SA[i-1]=="#" and SA[i]=="#":
            bool3 = False
            break
    if bool1 or(bool2 and bool3):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

def yn(a):
    print('Yes' if a else 'No')

if C < D:
    # `##` is NG btw A and D
    yn('##' not in S[A:C] and '##' not in S[B:D])
else:
    # `#` is NG prev D except oikoseru
    yn('##' not in S[A:C] and '...' in S[B-2:D+1])

Submission status: Accepted

Solution code:
n,a,b,c,d = map(int,input().split())
S = input()
 
ans = 0
def aaa(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
    
def bbb(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
        return(1)
    else:
        return(0)

def ccc(s,g):
    global ans
    if S[s:g].count("##") == 0:
        return(1)
    else:
        return(0)
        
if c < d:
    aaa(b,d)
    aaa(a,c)
else:
    flag = bbb(b,d)
    flag2 = ccc(a,c)
 #   print(ans)
    if flag == 1 and flag2 == 1:
        for i in range(b,d+1):
      #      print(i)
            if S[i-1:i] != "#":
                k = S[i-2:i-1] + "#" + S[i:i+1]
      #          print(k,i)
                if k.count("##") == 0:
                    ans += 1
                    break
#    print(flag)
#    print(ans)
 
if ans == 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def not_double_stone(way):
    already=False
    for i in way:
        if i=="#" and already:
            return False
        elif i=="#":
            already=True
        else:
            already=False
    return True

def can_over(way):
    count=0
    for i in way:
        if i==".":
            count+=1
        else:
            count=0
        if count==3:
            return True
    return False

if c<d:
    if not_double_stone(way[b-1:d]) and not_double_stone(way[a-1:c]):
        answer='Yes'
    else:
        answer='No'
else:
    if can_over(way[b-2:d]):
        if not_double_stone(way[a-1:c]):
            answer='Yes'
        else:
            answer='No'
    else:
        if not_double_stone(way[a-1:c]) and way[d-2]!="#" and way[d]!="#":
            answer='Yes'
        else:
            answer='No'

print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    # A,Bからみて先が"##"の状態になったら詰み
    if "##" not in S[A:C] and "##" not in S[B:D]:
        if C < D or C < B:
            # 先にBをDまで移動させればAもたどり着ける
            print("Yes")
        else:
            # AがBを追い抜く必要があるので、
            # その瞬間に#B or B#にならないようにしないといけない
            # B-1からD+1の間に ... があればOK
            if "..." in S[B-2:D+1]:
                print("Yes")
            else:
                print("No")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

str_ac = str[A:C-1]
str_bd = str[B:D-1]
#print(str_ac)
#print(str_bd)

if C<D:
  if str_bd.find("##") != -1 or str_ac.find("##") != -1:
    print("No")
  else:
    print("Yes")
else:
  if str_bd.find("##") != -1:
    print("No")
  elif str_bd.find("...") != -1 and str_ac.find("##") == -1:
    print("Yes")
  elif str_bd.startswith("..") and str_ac.find("##") == -1:
    print("Yes")
  elif str_bd.endswith("..") and str_ac.find("##") == -1:
    print("Yes")
  else:
    str_b = str[:B-1] + "#" + str[B:]
    str_d = str[:D-1] + "#" + str[D:]
    str_b_ac = str_b[A:C-1]
    str_d_ac = str_d[A:C-1]
    #print(str)
    #print(str_ac)
    if str_b_ac.find("##") == -1 or str_d_ac.find("##") == -1:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

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

curval = "x"
cnt = 0
initidx = 0
ngarea = [-1]
triarea = [-1]

for idx,val in enumerate(S):
    if val == curval:
        cnt += 1
    else:
        if cnt >= 2 and curval == '#':
            ngarea.append(initidx + 1)
        elif cnt >= 3 and curval == '.':
            for i in range(3,cnt+1):
                triarea.append(initidx + 1 + i - 3)
        initidx = idx
        cnt = 1
    curval = val
else:
    if cnt >= 2 and curval == '#':
        ngarea.append(initidx + 1)
    elif cnt >= 3 and curval == '.':
        triarea.append(initidx + 1)

if C < D:
    isBflg = True
    isABflg = True
    for ngp in ngarea:
        if ngp > B and ngp < D:
            isBflg = False
        if ngp > A and ngp < B:
            isABflg = False
    if isBflg and isABflg:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
else:
    isChangeFlg = False
    # Changepoint = -1
    for trp in triarea:
        if trp >= A and trp + 1 >= B:
            Changepoint = trp + 1
            isChangeFlg = True
            break
    if isChangeFlg == False or Changepoint >= C or Changepoint > D:
        print('No')
        exit()
    else:
        isBflg = True
        isABflg = True
        isChange2DFlg = True
        for ngp in ngarea:
            if ngp > B and ngp < Changepoint:
                isBflg = False
            if ngp > A and ngp < B:
                isABflg = False
            if ngp > Changepoint and ngp < D:
                isChange2DFlg = False
        if isBflg and isABflg and isChange2DFlg:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

Submission status: Accepted

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

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

A -= 1
B -= 1
C -= 1
D -= 1
S[A] = 'a'
S[B] = 'b'

ans_D = False
ans_C = False

b = B
a = A

if C <= D:
    while True:
        if b == D:
            ans_D = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if ans_D:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
    if ans_C and ans_D:
        print('Yes')
    else:
        print('No')
else:
    swap_flag = False
    while b + 1 < N:
        if (S[b-1] == '.' and S[b+1] == '.') or (S[b-1] == 'a' and S[b+1] == '.'):
            swap_flag = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if swap_flag:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
        if ans_C:
            while True:
                if b == D:
                    ans_D = True
                    break
                else:
                    if S[b+1] == '.':
                        S[b] = '.'
                        S[b+1] = 'b'
                        b += 1
                    else:
                        if S[b+2] == '.':
                            S[b] = '.'
                            S[b+2] = 'b'
                            b += 2
                        else:
                            break
            if ans_C and ans_D:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

def cd():
    two_block_flg = False
    for s in S[A:C+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    two_block_flg = False
    for s in S[B:D+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    return 'Yes'

def dc():
    two_block_flg = False
    for s in S[A:C+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    for i in range(B, D+1):
        if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
            return 'Yes'
    return 'No'  


if C<D:
    print(cd())
else:
    print(dc())

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

Submission status: Accepted

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

# 3マス空きがあるか
white = []
for i in range(N - 2):
    if S[i] == "." == S[i + 1] == S[i + 2]:
        white.append(i + 1)

if C > D:
    # Aからスタート
    i = A - 1
    T = S.copy()
    T[B - 1] = "#"
    while C - 1 != i:
        if T[i + 1] == ".":
            i += 1
        elif T[i + 2] == ".":
            i += 2
        elif i + 1 == B - 1 or i + 2 == B - 1:
            es = False
            for w in white:
                if i < w:
                    if w <= D - 1:
                        es = True
            if es:
                i = B - 1
            else:
                break
        else:
            break
    if i == C - 1:
        print("Yes")
        exit()
else:
    i = B - 1
    T = S.copy()
    while D - 1 != i:
        if T[i + 1] == ".":
            i += 1
        elif T[i + 2] == ".":
            i += 2
        else:
            break
    if i == D - 1:
        T2 = S.copy()
        T2[D - 1] = "#"
        j = A - 1
        while C - 1 != j:
            if T[j + 1] == ".":
                j += 1
            elif T[j + 2] == ".":
                j += 2
            else:
                break
        if j == C - 1:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

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

if C < D:
	print('Yes')
	sys.exit()

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

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

print('No')
sys.exit()

Submission status: Accepted

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
print("No" if s.find("##", a-1, c) >= 0 or s.find("##", b-1, d) >= 0 or (c > d and s.find("...", b-2, d+1) < 0) else "Yes")

Submission status: Accepted

Solution code:
def solve4():
    N, A, B, C, D = [int(_) for _ in raw_input().split()]
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    S = raw_input()
    R2 = False
    E3 = False
    for i in range (A+1, max(C,D)-1):
        if S[i:(i+2)] == '##':
            R2 = True
            break
    if C == D or R2:
        return False
    elif C < D:
        return True
    elif C > D:
        for i in range (B - 1, D):
            if S[i:(i+3)] == '...':
                E3 = True
                break
        ret = E3
        return ret

if __name__ == '__main__':
    ret = solve4()
    if ret:
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding:utf-8


def main():
    N, A, B, C, D = map(int, input().split())
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    iwa = "#"
    S = input()
    ans = True
    canexchange = False

    for i in [A, B, C, D]:
        if S[i] == iwa:
            exit()

    exchagable_list = []
    for i in range(N-2):
        temps = S[i:i+3]
        if temps == "...":
            exchagable_list.append(i)

    if len(exchagable_list) > 0:
        for i in exchagable_list:
            if i+1 >= B and i+1 <= min(C, D):
                canexchange = True

    # print(canexchange)
    for i in range(N-1):
        if S[i] == iwa and S[i+1] == iwa:
            if C < B and (C < i and i+1 < B):
                pass
            elif not (i+1 < A or i > max(C, D)):
                ans = False

    if ans:
        if C < D:
            ans = True
        elif C > D and canexchange:
            ans = True
        elif C > D and not canexchange:
            if S[D-1] == iwa or S[D+1] == iwa:
                ans = False
            else:
                ans = True

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def solve():
    ac, bd = S[A - 1:C], S[B - 1:D]
    if A < B < D < C:
        bd = S[B - 2:D + 1]
        return ("..." in bd and "##" not in ac)
    else:
        return ("##" not in ac and "##" not in bd)

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