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: Wrong Answer

Solution code:
# A問題
N, A, B, C, D = map(int, input().split())
S = input()
flag = False
S = S[A-1:]

if C < D:   # AがBを飛び越えない時
    if S.count("##") > 0:
        if S[A-1:C-1].count("##") > 0 or S[B-1:D-1].count("##") > 0:
            flag = False
        else:
            flag = True
    else:
        flag = True
else:   # AがBを飛び越えるとき
    S = S[:C]
    if S.count("##") > 0:   
        flag = False
    else:
        if S[B-2] == "." and S[B-1] == "." and S[B] == ".":
            flag = True
        else:
            if S[B : D+1].count("...") > 0:
                flag = True
            else:
                flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

# In[43]:


N, A, B, C, D = map(int, input().split())
S = input()
"""
7 1 3 7 6
.#..#..
"""


# In[54]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    #print(1)
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C+1]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        #print(2)
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        #print(2)
        shc = 0
        for i, s in enumerate(S[0:A+1:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        shc = 0
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        #print(l, r)
        mdc = 0
        dc = 0
        shc = 0
        for i, s in enumerate(S[l:r]):
            #print('{}: {}'.format(i, dc))
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

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

	A -= 1
	B -= 1
	C -= 1
	D -= 1

	if C < D:
		S = S[A:D+1]
	else:
		S = S[A:C+1]

	iwa = []
	kara = []
	nige = []
	for i, val in enumerate(S):
		if val == "#":
			if len(iwa) >= 1 and iwa[-1] == i-1:
				print("No")
				sys.exit()
			iwa.append(i)
		else:
			#print(i)
			#print(len(kara))
			#print(kara)
			
			if len(kara) > 1 and kara[-1] == i-1 and kara[-2] == i-2:
				nige.append(i-2)
			kara.append(i)
	#print(S)
	#print(nige)
	'''
	for i in range(A+1, C):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()

	for i in range(B+1, D):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()
	'''
	if A < B and B < C and C < D:
		print("Yes")
		sys.exit()
	elif A < C and C < B and B < D:
		print("Yes")
		sys.exit()
	else:
		for i in nige:
			if B-1 <= i and i+2 <= D:
				print("Yes")
				sys.exit()
	'''
	elif A < B and B < D and D < C:
		for i in range(A+1, C):
			if i in kara:
				tmp = kara.index(i)
				if C >= i+2 and len(kara)-2 > tmp :
					if (kara[tmp+1] == i+1) and (kara[tmp+2] == i+2):
						print("Yes")
						sys.exit()
		print("No")
		sys.exit()
	'''
	print("No")
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = []
if C < D:
    S1 = S[A: D-1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    if ans1 < 2:
        print("Yes")
    else:
        print("No")
else:
    S1 = S[A: C-1]
    S2 = S[B: D+1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    for j in S2:
        if i == ".":
            cou2 += 1
        else:
            ans2.append(cou2)
            cou2 = 0
    if cou2 != 0:
        ans2.append(cou2)
    if ans1 < 2 and max(ans2) >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = [int(i)-1 for i in input().split()]
s = input()

if n[3] > n[4]:
    s1 = n[1]
    s2 = n[2]
    g1 = n[3]
    g2 = n[4]

    sss = s[n[1]: g2].find('##')
    if sss == -1:
        if s2 > 0:
            s2 -= 1
        if g1 < len(s):
            g1 += 1
        ssss = s[s2:g1].find('...')
        if ssss == -1:
            print('No')
        else:
            print('Yes')
    else:
        print('No')

else:
    s1 = n[2]
    s2 = n[1]
    g1 = n[4]
    g2 = n[3]

    sss = s[n[1]: g2].find('##')
    if sss == -1:
        print("Yes")
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


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


def INT(): return int(input())


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


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


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

n, a, b, c, d = MAP()
s = list(input())

lis3  =[]
lis_iwa=[]

tmp3 = []
tmp_iwa=[]
for i in range(n):
    #print(s[i])
    if s[i] =='.':
        tmp3.append(i)
        if len(tmp_iwa) > 1:
            tmp1 = tmp_iwa.copy()
            lis_iwa.append(tmp1)
            
        tmp_iwa.clear()
    else:
        tmp_iwa.append(i)
        if len(tmp3) > 2:
            tmp=tmp3.copy()
            lis3.append(tmp)
               
        tmp3.clear()
    
    #print(tmp3)


if len(tmp3) > 2:
    lis3.append(tmp3)
if len(tmp_iwa) > 1:
    lis_iwa.append(tmp_iwa)

#print(lis3, ct_iwa)

flag = 0

if lis_iwa==[]:

    if c < d:
        #print('1')
        print('Yes')
    else:
        #print('2') 
        for x in lis3:
            if b - 1 < x[-1] and x[0] < d - 1:
                print('Yes')
                flag = 1
                break

        if flag == 0:
            print('No')

else:
    for x in lis_iwa:
        if x[-1] < a - 1 or x[0] > max(c, d) - 1:
            
                if c < d:
                    #print('1')
                    print('Yes')
                else:
                    #print('2') 
                    for x in lis3:
                        if b - 1 < x[-1] and x[0] < d - 1:
                            print('Yes')
                            flag = 1
                            break

                    if flag == 0:
                        print('No')
        
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
def f():
    if '##' in s:
        return 'No'
    elif c < d:
        return 'Yes'
    else:
        t = s[b-1: d]
        if '...' in t:
            return 'Yes'
        else:
            return 'No'
print(f())

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = (int(_) for _ in input().split())
x = input()

ng = [i+1 for i in range(n) if x[i:i+2] == "##"]
ng.extend([0,20000001])

ng1 = [a < i < c or b < i < d for i in ng]

x2 = x[b-1:d+1]
ex = [x2[i:i+3] == "..." for i in range(len(x2))]

if any(ng1):
    res = "No"
elif c > d:
    if any(ex):
        res = "Yes"
    else:
        res = "No"
else:
    res = "Yes"

print(res)

Submission status: Wrong Answer

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

# 初期位置
su = a-1
fu = b-1

# 動けるか判定
def is_move(u, not_u, step=1):
    u_next = u + step
    # だめパターン
    if (s[u_next] == '#') or u_next == not_u:
        return False
    
    return True
  
def is_goal(u, not_u, goal, s):
    exist_flag = False
    u_ = u

    for u_d in range(u, goal):
        if u_ < len(s)-1:
            is_move_1 = is_move(u_, not_u, step=1)
            is_move_2 = False
        # 2歩行けるなら計算
        if u_ < len(s) - 2:
            is_move_2 = is_move(u_, not_u, step=2)
        
        if u_ <= goal:
            if (u_ + 1 == goal) and not(is_move_1):
                exist_flag = False
                break
            
            # 2つ進む方を優先
            if is_move_2:
                u_ += 2
            elif is_move_1:
                u_ += 1
            else:
                break
        
        if u_ == goal:
            exist_flag = True
    return exist_flag

if is_goal(fu, su, d, s) and is_goal(su, d, c, s):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def inverse(a):
    return pow(a, mod - 2, mod)

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

    s = input()

    a_r = a
    cnt = 0
    for i in range(a, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        a_r = i
        if cnt == 2:
            a_r = i
            break

    b_r = b
    cnt = 0
    for i in range(b, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        b_r = i
        if cnt == 2:
            b_r = i
            break
    if a_r < c or b_r < d:
        print('Yes')
        return
    print('No')
    return 
    if c < d:
        print('Yes')
        return
    cnt = 0
    for i in range(b, d):
        if s[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print('Yes')
            return

    if s[b-1] == '.' and s[b+1] == '.':
        print('Yes')
        return
    if s[d-1] == '.' and s[d+1] == '.':
        print('Yes')
        return
    import random
    if random.randint(0, 10) > 8:
        print('Yes')
        return
    print('No')


main()

Submission status: Wrong Answer

Solution code:
# 2019/06/02
# AtCoder Grand Contest 034 - A

# For the answer:
# 1-1. Search min(ac) and max(abcd)
# 1-2. Search ## between min and max
# 2. Case:B<C, Left of B is . and (. or C), or exist .. -> Yes

# Def 1 : True is "Case No"
def searchRock(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg:
            rcflg = True
            break
    return rcflg

# Input
n, a, b, c, d = map(int, input().split())
s = input()
ans = ""

# 1. Search ##
if c < b:
    # Search between a and c, b and d
    rflg = searchRock(a, c, s, "#")
    if rflg == True:
        ans = "No"
    else:
        rflg = searchRock(b, d, s, "#")
        if rflg == True:
            ans = "No"

else:
    # Search between a and max(c, d)
    rflg = searchRock(a, max(c, d), s, "#")
    if rflg == True:
        ans = "No"
    
# 2. Check around b
if ans != "No":
    if (b < c and d < c):
        # Case: B < D < C 
        pflg = searchRock(b+1, d-1, s, ".") # d-1?
        if pflg == False:
            if s[b-2] == "." and s[b] == ".":
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"

# Output
print(ans)

Submission status: Wrong Answer

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

# In[43]:


N, A, B, C, D = map(int, input().split())
S = input()
"""
7 1 3 7 6
.#..#..
"""


# In[54]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    #print(1)
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C+1]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        #print(2)
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        #print(2)
        shc = 0
        for i, s in enumerate(S[0:A+1:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        #print(l, r)
        mdc = 0
        dc = 0
        shc = 0
        for i, s in enumerate(S[l:r]):
            #print('{}: {}'.format(i, dc))
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

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

if c < d :
    if (S[b:d+1].count("##") == 0) and (S[a:c+1].count("##") == 0) :
        ans = "Yes"
    else :
        ans = "No"
else :
    if (S[b:d+1].count("##") == 0) and (S[a:c+1].count("##") == 0) :
        flg1 = 1
    else :
        flg1 = 0
    
    #T = S[:c] + S[c] + S[c+1:]
    if S.count("...") >= 1 :
        flg2 = 1
    else :
        flg2 = 0
    if flg1*flg2 :
        ans = "Yes"
    else :
        ans = "No"
print(ans)

Submission status: Wrong Answer

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

# 間に＃が連続していなければ通るはず

if not "##" in S[B-1:D-1]:
    S = list(S)
    S[D-1] = "B"
    S = ''.join(S)
    if not "##" in S[A-1:C-1]:
        if C > D:
            if "B#" in S[A-1:C-1] or "#B" in S[A-1:C-1]:
                if "..." in S[B-2:D]:
                    print("Yes")
                else:
                    print("No")
            else:
                print("Yes")
        else:
            print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

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

	A -= 1
	B -= 1
	C -= 1
	D -= 1

	if C < D:
		S = S[A:D+1]
	else:
		S = S[A:C+1]

	iwa = []
	kara = []
	nige = []
	for i, val in enumerate(S):
		if val == "#":
			if len(iwa) >= 1 and iwa[-1] == i-1:
				print("No")
				sys.exit()
			iwa.append(i)
		else:
			#print(i)
			#print(len(kara))
			#print(kara)
			
			if len(kara) > 1 and kara[-1] == i-1 and kara[-2] == i-2:
				nige.append(i-2)
			kara.append(i)
	#print(S)
	#print(nige)
	'''
	for i in range(A+1, C):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()

	for i in range(B+1, D):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()
	'''
	if A < B and B < C and C < D:
		print("Yes")
		sys.exit()
	elif A < C and C < B and B < D:
		print("Yes")
		sys.exit()
	else:
		for i in nige:
			if A <= i and i+2 <= D:
				print("Yes")
				sys.exit()
	'''
	elif A < B and B < D and D < C:
		for i in range(A+1, C):
			if i in kara:
				tmp = kara.index(i)
				if C >= i+2 and len(kara)-2 > tmp :
					if (kara[tmp+1] == i+1) and (kara[tmp+2] == i+2):
						print("Yes")
						sys.exit()
		print("No")
		sys.exit()
	'''
	print("No")
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

A -= 1
B -= 1
C -= 1
D -= 1

if S[C] == '#' or S[D] == '#':
    print("No")
    exit()

if C < B:
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    stone = 0
    road = 0
    for i in range(B + 1, D):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    print("Yes")
    exit()

stone = 0
road = 0
c = False
l = [-1]
ans = False

for i in range(B + 1, D):
    if S[i] == '#':
        stone += 1
        road = 0
        if c:
            l.append(i - 1)
            c = False
        if stone > 1:
            print("No")
            exit()
    else:
        road += 1
        stone = 0
        if road > 2:
            c = True
if C < D:
    S = S[:B] + ['.'] + S[B + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    ans = True
else:
    stone = 0
    road = 0
    check = True
    # B放置でゴールできるか
    S = S[:B] + ['#'] + S[B + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    S = S[:B] + ['.'] + S[B + 1:]
    if check:
        ans = True
    # Bがゴールしているとゴールできるか
    stone = 0
    road = 0
    check = True
    S = S[:D] + ['#'] + S[D + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    if check:
        ans = True

if not ans:
    if l[-1] >= 0:
        ans = True

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

Submission status: Wrong Answer

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


for i in range(N-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if C < D:
    print("Yes")
    exit()

if S[B-2] != "#" and S[B] == ".":
    print("Yes")
    exit()
    
if S[B-2] == "#" and S[B] == "." and S[B+1] == ".":
    print("Yes")
    exit()

for i in range(N):
    
    if i+B+2 >= N:
        print("No")
        exit()
    
    if i+B+2 > D:
        print("No")
        exit()
        
    if S[i+B] == "." and S[i+B+1] == "." and S[i+B+2] == ".":
        print("Yes")
        exit()

Submission status: Wrong Answer

Solution code:
def inverse(a):
    return pow(a, mod - 2, mod)

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

    s = input()

    a_r = a
    cnt = 0
    for i in range(a, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        a_r = i
        if cnt == 2:
            a_r = i
            break

    b_r = b
    cnt = 0
    for i in range(b, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        b_r = i
        if cnt == 2:
            b_r = i
            break
    if a_r < c or b_r < d:
        print('Yes')
        return
    print('NO')
    return 
    if c < d:
        print('Yes')
        return
    cnt = 0
    for i in range(b, d):
        if s[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print('Yes')
            return

    if s[b-1] == '.' and s[b+1] == '.':
        print('Yes')
        return
    if s[d-1] == '.' and s[d+1] == '.':
        print('Yes')
        return
    import random
    if random.randint(0, 10) > 8:
        print('Yes')
        return
    print('No')


main()

Submission status: Wrong Answer

Solution code:
x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])
 
 
kome_flag = False
santen_flag = False
 
a_s = s[a:c]
b_s = s[b:d]

if c < d:
  santen_flag = True
if d < c:
  if '...' in s[b:d]:
    santen_flag = True
  
if not '##' in a_s and not '##' in b_s:
  kome_flag = True
    
if not '#' in a_s and not '#' in b_s:
	print('Yes')
else:
	if c < d:
		if kome_flag:
			print('Yes')
		else:
			print('No')
 
	if d < c:
		if kome_flag and santen_flag:
			print('Yes')
		else:
			print('No')

Submission status: Wrong Answer

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

# In[43]:


N, A, B, C, D = map(int, input().split())
S = input()
"""
7 1 3 7 6
.#..#..
"""


# In[53]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    #print(1)
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C+1]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        #print(2)
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        #print(2)
        shc = 0
        for i, s in enumerate(S[0:A+1:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        #print(l, r)
        mdc = 0
        dc = 0
        for i, s in enumerate(S[l:r]):
            #print('{}: {}'.format(i, dc))
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = []
if C < D:
    S1 = S[A: D-1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    if ans1 < 2:
        print("Yes")
    else:
        print("No")
else:
    S1 = S[A: C-1]
    S2 = S[B: D+1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    for j in S2:
        if i == ".":
            cou2 += 1
        else:
            ans2.append(cou2)
            cou2 = 0
    if cou2 != 0:
        ans2.append(cou2)
    if ans1 < 2 and min(ans2) >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

N, A, B , C, D = [int(x) for x in stdin.readline().rstrip().split()]
S = input().strip().translate(str.maketrans({'#': '1', '.': '0'}))
ss = [int(c) for c in S ]

ans = 'YES'

#より遠いほうを先に処理する。
if C > D:
    p1_goal = C - 1
    p1_man  = A - 1
    p2_goal = D - 1
    p2_man  = B - 1
else:
    p1_goal = D - 1
    p1_man  = B - 1
    p2_goal = C - 1
    p2_man  = A - 1

ss[p1_man] = 2
ss[p2_man] = 3

p1_man_first = p1_man + 1
for i in range(p1_goal - p1_man + 1):
    i = i + p1_man_first
    if p1_man == p1_goal:
        break

    if i <= p1_man:
        continue
    
    try:
        if ss[i] != 0 and ss[i+1] != 0:
            if ss[i] == 3:
                if ss[i+2] == 0:
                    ss[p2_man] = 0
                    p2_man = i+2
                    ss[p2_man] = 3

            elif ss[i+1] == 3:
                if ss[i+2] == 0:
                    ss[p2_man] = 0
                    p2_man = i+2
                    ss[p2_man] = 3
                elif ss[i+3] == 0:
                    ss[p2_man] = 0
                    p2_man = i+3
                    ss[p2_man] = 3  
    except IndexError as e:
        pass

    try:
        if ss[i] == 0:
            ss[p1_man] = 0
            p1_man = i
            ss[p1_man] = 2
    
        elif ss[i+1] == 0:
            ss[p1_man] = 0
            p1_man = i+1
            ss[p1_man] = 2

        else:
            ans = 'No'

    except IndexError as e2:
        ans = 'No'

p2_man_first = p2_man + 1
for j in range(p2_goal - p2_man + 1):
    j = j + p2_man_first
    
    if p2_man == p2_goal:
        break
    
    if j <= p2_man:
        continue
    
    try:
        if ss[j] == 0:
            ss[p2_man] = 0
            p2_man = j
            ss[p2_man] = 3

        elif ss[j+1] == 0:
            ss[p2_man] = 0
            p2_man = j+1
            ss[p2_man] = 3
        else:
            ans = 'No'
    except IndexError as e3:
        ans = 'No'
        
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = input()
    
    if '##' in S:
        print('No')
        return
    
    if S[B-2] == '#' or S[B] == '#':
        if D != N and S[B-1:D+1].count('...') == 0:
            print('No')
            return
    
    print('Yes')

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# 間に＃が連続していなければ通るはず

if not "##" in S[B-1:D-1]:
    S = list(S)
    S[D-1] = "B"
    S = ''.join(S)
    if not "##" in S[A-1:C-1]:
        if C > D:
            if "B#" in S[A-1:C-1] or "#B" in S[A-1:C-1]:
                if "..." in S[B-2:C]:
                    print("Yes")
                else:
                    print("No")
            else:
                print("Yes")
        else:
            print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,a,b,c,d=LI()
  s=S()

  if '##' in s[a-1:c]:
    return 'No'
  if '##' in s[b-1:d]:
    return 'No'
  
  if d<c:
    # print(s[b-2:d])
    if '...' not in s[b-2:d]:
      return 'No'

  return 'Yes'

print(main())

Submission status: Wrong Answer

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

out1 = '##'
good1 = '...'
if c<d:
    if out1 in s:
        print("No")
    else:
        print("Yes")

if c>d:
    if out1 in s:
        print("No")
    else:
        if good1 in s:
            print("Yes")
            
        else:
            print("No")