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:
#!/usr/bin/env python
# coding: utf-8

# In[38]:


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


# In[39]:


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


# In[37]:


"""
k = []
try:
    st = S.index(".")+1
except:
    print("No")
for i in range(N):
    
    if i==0:
        m = S[i]
        count = 1
    else:
        if S[i] == m:
            count += 1
        else:
            k.append(count)
            m = S[i]
            count = 1
        
    if i == A-1:
        wa = len(k)
    if i == B-1:
        wb = len(k)
    if i == C-1:
        wc = len(k)
    if i == D-1:
        wd = len(k)
    if i == N-1:
        k.append(count)

if S[i] == '.':
    dot = k[::2]
    sharp = k[1::2]
else:
    dot = k[1::2]
    sharp = k[2::2]
    wa -= 1
    wb -= 1
    wc -= 1
    wd -= 1
#print(k)
#print(dot)
#print(sharp)
#print(wa, wb, wc, wd)

if C<D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    print("Yes")
elif C>D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    if C<B:
        print("Yes")
        sys.exit()
    elif C>B:
        l = 0
        for i, s in enumerate(sharp[0:wa//2:-1]):
            if s>2:
                l = wa//2-i
        r = len(dot)
        for i, s in enumerate(sharp[wc//2:]):
            if s>2:
                r = wc//2+i
        for d in dot[l:r+1]:
            if d>2:
                print("Yes")
                sys.exit()
        else:
            print("No")
"""


# In[ ]:

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = list(map(int, input().split()))
S = list(input())
A = A-1
B = B-1
C = C-1
D = D-1
S[A] = 'a'
S[B] = 'b'
a = A
b = B
flag = False
bflag = False
dflag = False
if A > B:
    B, A = (A, B)
    D, C = (C, D)

Atame = S.copy()
count_a = a
for i in range(N):
    if count_a > N-3:
        break
    if Atame[count_a+1] == '#' and Atame[count_a+2] == '#':
        dflag = True
    count_a += 1
    


if B > A and D > C:
    for i in range(N):
        if b == D:
            flag = True
            break
        if S[b+1]=='.':
            S[b+1] = 'b'
            S[b] = '.'
            b += 1
        elif S[b+2]=='.':
            S[b+2] = 'b'
            S[b] = '.'
            b += 2

elif B > A and C > D:
    for i in range(N):
        if b >= 1 and b+1 < N:
            if S[b-1] == '.' and S[b+1] == '.':
                bflag = True
                break
        if b + 1 < N:
            if S[b+1] == '.':
                S[b+1] = 'b'
                S[b] = '.'
                b += 1
            elif b + 2 < N:
                if S[b+2] == '.':
                    S[b+2] = 'b'
                    S[b] = '.'
                    b += 2

    if bflag:
        a = a+1
        for i in range(N-a):
            if a == C:
                flag = True
                break
            if S[a+1] == '.':
                S[a+1] = 'a'
                S[a] = '.'
                a += 1
            elif S[a+2] == '.':
                S[a+2] = 'a'
                S[a] = '.'
                a += 2

if flag and (dflag==False):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:

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


def solve(n, a, b, c, d, s):
    def check(sub):
        if '##' in sub:
            return False
        return True
    # check for a
    s_a = s[a-1:c]
    state_a = check(s_a)
    if not state_a:
        return 'No'
    s_b = s[b-1:d]
    state_b = check(s_b)
    if not state_b:
        return 'No'
    if c > d:
        if '...' in s_a:
            if '...' in s_b:
                return 'Yes'
        else:
            return 'No'

    return 'Yes'


def main():
    n, a, b, c, d, s = input_from_console()
    print(solve(n, a, b, c, d, s))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

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:
			if len(kara) > 2 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 < 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:
def passable(road):
    n=len(road)
    for i in range(n-1):
        block=road[i:i+2]
        if block=='##':
            return False
    return True

def safe_place(road):
    n=len(road)
    for i in range(n-2):
        block=road[i:i+3]
        if block=='...':
            return i+1
    return -1

def passEach(A,B,C,D,road):
    if passable(road[A:C+1]) and passable(road[B:D+1]):
        return True
    else:
        return False

def judge(A,B,C,D,S):
    if C<D:
        return passEach(A,B,C,D,S)
    else:
        S2=S[:B]+'#'+S[B+1:]
        if passable(S2[A:C+1]) and passable(S[B:D]):
            return True
        safePlace=safe_place(S[B:D+1])
        if safePlace!=-1 and passEach(A,B,C,safePlace,S) and passEach(A,safePlace,C,D,S):
            return True
    return False

N,A,B,C,D=map(int,input().split())
S=input()
if judge(A-1,B-1,C-1,D-1,S):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[A-1:D].count('...'))
            if(sf == 0):
                print(NO)
            ######### あとはここだけ考える ####
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D].count('..b#d') == 1):
                    print(NO)
                else:
                    print(YES)
            #################################
            elif(sf >= 2):
                print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if s[a-1:max(c,d)].count("##")>0:
    print("No")
elif c<d:
    print("Yes")
else:
    if s[b-3:d].count("...")==0:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = list(input())
last = ""
for i in range(a, c):
    if last == "#" and s[i] == "#":
        print("No")
        exit()
    last = s[i]
for i in range(b, d):
    if last == "#" and s[i] == "#":
        print("No")
        exit()
    last = s[i]
flag = False
if c > d:
    s[b - 1] = "#"
    for i in range(a, c):
        if last == "#" and s[i] == "#":
            flag = True
        last = s[i]
    s[b - 1] = "."
    count = 0
    for i in range(b - 1, d):
        if s[i] == ".":
            count += 1
            if count == 3:
                flag = False
        else:
            count = 0
if not flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def count_renzoku_char(s, char):
    max_len = 0
    current_len = 0
    for c in s:
        if c == char:
            current_len += 1
        else:
            if max_len < current_len:
                max_len = current_len
            current_len = 0

    return max_len

if __name__ == "__main__":
    N, A, B, C, D = [int(x) for x in input().split()]
    S = input()

    def main():
        global A, B
        if C < D:
            raw_sharp = count_renzoku_char(S[A+1: D], '#')
            if raw_sharp >= 2:
                print('No')
                return
            else:
                print('Yes')
                return
        else:
            raw_sharp = count_renzoku_char(S[A+1: C], '#')
            if raw_sharp >= 2:
                print('No')
                return

            is_reached = False
            while(True):
                if A + 1 == C or A + 2 == C:
                    is_reached = True
                    break
                su2 = S[A+2]
                if su2 == '.':
                    A = A + 2
                    continue
                elif su2 == '#':
                    pass
                elif A + 2 == B:
                    if not (B == D or S[B+1] == '#'):
                        B = B + 1
                        A = A + 2
                        continue
                
                su1 = S[A+1]
                if su1 == '.':
                    A = A + 1
                    continue
                elif su1 == '#':
                    break
                elif A + 1 == B:
                    if not (B == D or S[B+1] == '#'):
                        B = B + 1
                        A = A + 1
                        continue
                    else:
                        break
                
                break
            
            print('Yes' if is_reached else 'No')

    main()

Submission status: Wrong Answer

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

'''
7 1 2 3 4
....

7 1 3 5 7
.#.#.#.#.#.#

'''
#print(S)
iwa_cnt = 0
kusa_cnt = 0
result ='No'
for i,s in enumerate(S[A:max(C,D)-1]):
    #print(s)
    #print(i)
    #print(iwa_cnt)
    #print(kusa_cnt)
    if s =='#':
        iwa_cnt +=1
        kusa_cnt = 0
    else:
        if i + A - 1 > B -1:
            kusa_cnt +=1
        iwa_cnt = 0
    if iwa_cnt == 2:
        break
    if kusa_cnt == 1 and C < D:
        result = 'Yes'
    #if kusa_cnt == 2:
    #    result = 'Yes'
    if kusa_cnt == 2 and  D < C:
        result = 'Yes'

print(result)



'''
Aの現在地からCまでに...が三つ続いていれば、
そこにCをおける
Cは##がない限り、さきに動かせばいいので、問題ない


'''
#print(N,M)
#print(target)
#print(P)

Submission status: Wrong Answer

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

if c>d:
  if s[b-2:d].find("...")!=-1 and s[a-1:c-1].find("##")==-1:
    print("Yes")
  else:
    print("No")
elif b>c:
  if s[a-1:c-1].find("##")==-1 and s[b-1:d-1].find("##")==-1:
    print("Yes")
  else:
    print("No")
elif s[a-1:d-1].find("##")==-1:
  print("Yes")
else:
  print("No")

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, s, ".")
        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:
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1

# for i in range(firstsunuke, lastsunuke-1):
#    if s[i] == '#' and s[i+1] == '#':
#        tobenaiflag += 1
#        break
# for k in range(firstfunuke, lastfunuke-1):
#    if s[k] == '#' and s[k+1] == '#':
#        tobenaiflag += 1
#        break
tobenaiflag = 1
if lastfunuke < lastsunuke:
    for j in range(max(firstsunuke, firstfunuke)-1, lastfunuke-1):
        if s[j] == '.' and s[j+1] == '.' and s[j+2] == '.':
            nukaseruflag += 1
            break
else:
    nukaseruflag += 1
if tobenaiflag == 0 and nukaseruflag == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
N, A, B, C, D = (int(i) for i in input().rstrip().split())
S = stdin.readline().rstrip()
A -= 1
B -= 1
C -= 1
D -= 1
swap_flag = False
swap_able = -1
for itr in range(len(S)):
    if itr < (len(S) - 1) and S[itr] == '#' and S[itr+1] == '#':
        print('No')
        exit()
    if swap_flag == False and 2 <= itr and S[itr] == '.' and S[itr-1] == '.' and S[itr-2] == '.':
        swap_able = itr
        swap_flag = True 
# print(swap_able)
# print(A, B, C, D)
if swap_able > max(A,B):
    if A > B and C < D and S[C-1] == '#' and C < swap_able:
        print('No')
    elif A > B and C < D and C != N and S[C+1] == '#' and C < swap_able:
        print('No')
    elif A < B and D < C and S[D-1] == '#' and D < swap_able:
        print('No')
    elif A < B and D < C and D != N and S[D+1] == '#' and D < swap_able:
        print('No')
    else:
        print('Yes')
else:
    if A > B and C < D and S[C-1] == '#':
        print('No')
    elif A > B and C < D and C != N and S[C+1] == '#':
        print('No')
    elif A < B and D < C and S[D-1] == '#':
        print('No')
    elif A < B and D < C and D != N and S[D+1] == '#':
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

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(N-1)]
can_change = [0] + [(1-S[i])*(1-S[i+1])*(1-S[i+2]) for i in range(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:C-1]):
      return True
    else:
      return False

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

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = 0
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 = min(ans2, cou2)
            cou2 = 0
    if ans1 < 2 and ans2 >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
c1 = [0] * N
c2 = [0] * N
cnt1 = 0
cnt2 = 0
for i in range(N):
    if S[i] == '.':
        c2[i] = cnt2
        cnt2 = 0
        cnt1 += 1
    else:
        c1[i] = cnt1
        cnt1 = 0
        cnt2 += 1
        
if cnt1 >= 1:
    c1[-1] = cnt1
if cnt2 >= 1:
    c2[-1] = cnt2
    
index2 = []
index1 = []
for i in range(N):
    if c2[i] >= 2:
        index2.append(i)
    if c1[i] >= 3:
        index1.append(i)

flag = True
for i in index2:
    if A <= i - c2[i] + 1 < C or B <= i - c2[i] + 1 < D:
        flag = False
    if C <= i < A or D <= i < B:
        flag = False

if len(index1) == 0:
    if A <= B and C >= D:
        flag = False
    if A >= B and C <= D:
        flag = False

if S[A-1] == '#' or S[B-1] == '#' or S[C-1] == '#' or S[D-1] == '#':
    flag = False
if A == B or A == C or A == D or B == C or B == D or C == D:
    flag = False

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

Submission status: Wrong Answer

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

rock = 0
max_rock = []
non = 0
max_non = []
k = 0
for i in s:
    if i == '#':
        rock += 1
        if non >= 3:
            max_non.append([non, k])
        non = 0
    else:
        non += 1
        if rock >= 2:
            max_rock.append([rock, k])
        rock = 0
    if k == n-1:
        k += 1
        if non >= 3:
            max_non.append([non, k])
        if rock >= 2:
            max_rock.append([rock, k])
    k += 1

# print(max_non)
max_non1 = [i for i in max_non if i[1]-i[0]+2 < d and i[1]-i[0]+2 < c and i[1]-2 >= a and i[1]-2 >= b and not i[1]-1 == b]
max_rock1 = [i for i in max_rock if i[1] < d and i[1] < c and i[1] > a and i[1] > b]
max_non2 = max_non
max_rock2 = [i for i in max_rock if (i[1] < d and i[1] > b) or (i[1] > a and i[1] > c)]
# print(max_non1)
# print(max_rock1)
if b > c:
    if len(max_rock2) > 0:
        print('No')
    else:
        print('Yes')
elif c > d:
    if len(max_non1) > 0:
        print('Yes')
    else:
        print('No')
elif len(max_rock1) > 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = [int(i) for i in input().split()]
S = [list(i) for i in input().split()][0]
oldS = S
A,B,C,D = A-1,B-1,C-1,D-1
S[A],S[B] = 'A','B'

#print(S)

outflag=0
giveup=0
while giveup<1:
  end=0
  while end==0 and S[D]!='B':
    giveup=0
    ind = S.index('B')
    if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='A':
      S[ind] = '.'
      S[ind+1] = 'B'
    elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='A':
      S[ind] = '.'
      S[ind+2] = 'B'
    else:
      giveup+=1
      end=1

  end=0
  while end==0 and S[C]!='A':
    ind = S.index('A')
    if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='B':
      S[ind] = '.'
      S[ind+1] = 'A'
    elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='B':
      S[ind] = '.'
      S[ind+2] = 'A'
    else:
      giveup+=1
      end=1
      
  if S[C]=='A' and S[D]=='B':
    print('Yes')
    outflag=1
    break

#---------AしてB
if outflag==0:
  S = oldS
  outflag=0
  giveup=0
  while giveup<1:
    end=0
    while end==0 and S[C]!='A':
      giveup=0
      ind = S.index('A')
      if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='B':
        S[ind] = '.'
        S[ind+1] = 'A'
      elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='B':
        S[ind] = '.'
        S[ind+2] = 'A'
      else:
        giveup+=1
        end=1

    end=0
    while end==0 and S[D]!='B':
      ind = S.index('B')
      if ind+1!=len(S) and S[ind+1]!='#' and S[ind+1]!='A':
        S[ind] = '.'
        S[ind+1] = 'B'
      elif ind+1!=len(S) and ind+2!=len(S) and S[ind+2]!='#' and S[ind+2]!='A':
        S[ind] = '.'
        S[ind+2] = 'B'
      else:
        giveup+=1
        end=1
        
    if S[C]=='A' and S[D]=='B':
      print('Yes')
      outflag=1
      break

if outflag==1:
  print('No')
#print(S)

Submission status: Wrong Answer

Solution code:
class KenkenRace:
    def __init__(self):
        N, A, B, C, D = map(int, input().split())
        S = [str(c) for c in input()]

        self.N = N
        self.A = A
        self.B = B
        self.C = C
        self.D = D
        self.S = S

    def main(self):
        result = False

        # C < B のとき
        if self.C < self.B:
            # 割れているので, A -> C and B -> D を検証
            result = self.__canSepClear__(self.A, self.C) and self.__canSepClear__(self.B, self.D)

        # C < D のとき
        elif self.C < self.D:
            # クリアできるか確かめる
            result = self.__canClear__(self.D)

        # D < C のとき
        else:
            # 追い越せるかどうかを確かめる and クリアできるか確かめる
            result = self.__canClear__(self.C) and self.__canOvertake__(self.D)

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

    def __canClear__(self, higher):
        isDouble = False
        preObject = ""
        for i in range(self.A - 1, higher):
            c = self.S[i]
            if c == "#" and preObject == "#":
                isDouble = True
                break
            else:
                preObject = c

        return not isDouble

    def __canSepClear__(self, start, end):
        isDouble = False
        preObject = ""

        for i in range(start - 1, end):
            c = self.S[i]
            if c == "#" and preObject == "#":
                isDouble = True
                break
            else:
                preObject = c

        return not isDouble

    def __canOvertake__(self, lower):
        isTriple = False
        objectCount = 0
        severalCount = 0

        for i in range(self.B - 2, lower):
            c = self.S[i]
            objectCount += 1

            # 何もない箇所が何連続目か, カウント
            if c == ".":
                severalCount += 1
            else:
                severalCount = 0

            if objectCount == lower:
                # この位置 or 次の位置で3連続でない場合, 追い越せない
                if severalCount < 2:
                    break
                elif severalCount == 2 and self.S[i + 1] == ".":
                    isTriple = True
                    break

            # 3連続で何もなければ追い越し可能か
            if severalCount == 3:
                isTriple = True
                break

        return isTriple


kenkenRace = KenkenRace()
kenkenRace.main()

Submission status: Wrong Answer

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
arr[c]=3
arr[d]=4
#print(arr)
for i in range(max(c,d)):
	if(s[i]=='#' and s[i+1]=='#'):
		flag=1
		break

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

else:
	print("No")

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
# sample code

v = list(map(int, input().split()))
n, a, b, c, d = v[0], v[1], v[2], v[3], v[4]
s = input()

ac_cnt_1, ac_max_1 = 0, 0
bd_cnt_1, bd_max_1 = 0, 0
bd_cnt_0, bd_max_0 = 0, 0

for i in range(c-a-1):
	if s[i+a] == '#':
		ac_cnt_1 += 1
		if ac_max_1 < ac_cnt_1:
			ac_max_1 = ac_cnt_1
	else:
		ac_cnt_1 = 0
for i in range(d-b-1):
	if s[i+b] == '#':
		bd_cnt_0 = 0
		bd_cnt_1 += 1
		if bd_max_1 < bd_cnt_1:
			bd_max_1 = bd_cnt_1
	else:
		bd_cnt_0 += 1
		bd_cnt_1 = 0
		if bd_max_0 < bd_cnt_0:
			bd_max_0 = bd_cnt_0
if c < b:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1):
		print('Yes')
	else:
		print('No')
elif c < d:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1):
		print('Yes')
	else:
		print('No')
else:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1) and (bd_max_0 >= 3):
		print('Yes')
	else:
		if ((s[b-2] == '.') and (s[b] == '.')) or ((s[d-2] == '.') and (s[d] == '.')):
			print('Yes')
		else:
			print('No')

Submission status: Wrong Answer

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

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

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1

# for i in range(firstsunuke, lastsunuke-1):
#    if s[i] == '#' and s[i+1] == '#':
#        tobenaiflag += 1
#        break
# for k in range(firstfunuke, lastfunuke-1):
#    if s[k] == '#' and s[k+1] == '#':
#        tobenaiflag += 1
#        break
tobenaiflag = 0
if lastfunuke < lastsunuke:
    for j in range(max(firstsunuke, firstfunuke)-1, lastfunuke-1):
        if s[j] == '.' and s[j+1] == '.' and s[j+2] == '.':
            nukaseruflag += 1
            break
else:
    nukaseruflag += 1
if tobenaiflag == 0 and nukaseruflag == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

def scan(a_, c_):
    mae = ''
    for i, l in enumerate(s, 1):
        if a_ > i:
            continue
        if c_ == i:
            return True
        if mae == l == '#':
            return False
        mae = l

def scan2(b_, d_):
    mae = ''
    maemae = ''
    for i, l in enumerate(s + ' ', 1):
        if i < b_ - 1:
            continue
        if d == d_ + 2:
            return False
        if mae == maemae == l == '.':
            return True
        maemae = mae
        mae = l

if d > c and scan(a, c) and scan(b, d):
    print('Yes')
elif d < c and scan(a, c) and scan(b, d) and scan2(b, d):
    print('Yes')
else:
    print('No')