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:

n,a,b,c,d = map(int,input().split())
s = input()
s = s + "."
cant = 0
sanrenzoku = 0
for i in range(a-1,d-1):
    if s[i] == "#":
        if s[i+1] == "#":
            cant = 1
    if c > d:
        if s[i] == ".":
            if s[i+1] == ".":
                if s[i+2] == ".":
                    if i > b-2:
                        if i < d:
                            sanrenzoku = 1

if cant == 1:
    print("No")
elif c > d:
    if sanrenzoku == 0:
        print("No")
    else:
        print("Yes")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
class Kenken():
	def __init__(self,n,a,b,c,d,s):
		self.n = n
		self.a = a-1
		self.b = b-1
		self.c = c-1
		self.d = d-1
		self.s = s
		self.s = self.s[:a-1] + "A" + self.s[a:]
		self.s = self.s[:b-1] + "B" + self.s[b:]

	def str_replace(self,i,k,S):
		if k == 1:
			self.s = self.s[:i] + "." + S + self.s[i+2:]
		else:
			self.s = self.s[:i] + "." + self.s[i+1] + S + self.s[i+3:]

	def check_stone(self,i):
		if i < self.n:
			if self.s[i] == ".":
				return True
		return False

	def left(self,target,i):
		if target == "a":
			self.str_replace(self.a,i,"A")
			self.a += i
		else:
			self.str_replace(self.b,i,"B")
			self.b += i
	
	def get_space(self,S):
		if S == "a":
			return self.a
		elif S == "b":
			return self.b
		elif S == "c":
			return self.c
		elif S == "d":
			return self.d
	
n,a,b,c,d = map(int, input().split())
s = input()

over = 0
e = s.find("##")
if e != -1:
	if e < c or e < d: 
		print("No")
		exit()

if c > d:
	if s.find("...") == -1:
		print("No")
		exit()
	else:
		over = 1
ken = Kenken(n,a,b,c,d,s)
flag=0

if over == 0:
	for i in range(n):
		if ken.get_space("b") != ken.get_space("d"):
			if ken.check_stone(ken.get_space("b")+1):
                        	ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()
		else:
			break
	for i in range(n):
		if ken.get_space("a") != ken.get_space("c"):
			if ken.check_stone(ken.get_space("a")+1):
                        	ken.left("a",1)
			elif ken.check_stone(ken.get_space("a")+2):
				ken.left("a",2)
			else:
				print("No")
				exit()
		else:
			print("Yes")
			exit()
else:
	for i in range(n*2):
		if ken.get_space("b") == ken.get_space("d"):
			print("Yes")
			exit()
		elif ken.check_stone(ken.get_space("b")-1) and ken.check_stone(ken.get_space("b")+1):
			if ken.get_space("a") != ken.get_space("c"):
				if ken.check_stone(ken.get_space("a")+1):
					ken.left("a",1)
				elif ken.check_stone(ken.get_space("a")+2):
					ken.left("a",2)
				else:
					print("No")
					exit()
			else:
				if ken.check_stone(ken.get_space("b")+1):
					ken.left("b",1)
				elif ken.check_stone(ken.get_space("b")+2):
					ken.left("b",2)
				else:
					print("No")
					exit()
		else:
			if ken.check_stone(ken.get_space("b")+1):
				ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()

Submission status: Wrong Answer

Solution code:
import sys    

# 入力の読み込み
n, a , b, c, d = list(map(int, input().split()))
s = input()

# a,b,c,dをそれぞれ-1する
a, b, c, d = map(lambda x:x-1,[a,b,c,d])

# aとbのうち、小さい方を開始位置とする
# cとdのうち、大きい方を終了位置とする
start = a if a<b else b
end = c if c>d else d
s = s[start+1:end]
## start~endの間に岩が２連続あったらだめ
if s.find('##') != -1:
    print('No')
    sys.exit()

## 追い抜きが発生する場合はstart~endの間に...がないとだめ
if c > d and s.find('...') == -1:
    print('No')
    sys.exit()   

print('Yes')

Submission status: Wrong Answer

Solution code:
lis=list(map(int,input().split()))
S=input()
ans="Yes"
memo=0
if lis[3]<lis[4]:
    #Bを先に行かせてみる
    for i in range(lis[2],lis[4]-2):
        if S[i:i+2]=="##":
            ans="No"
            break
    #更にAも行かせてみる
    for i in range(lis[1],lis[3]-2):
        if S[i:i+2]=="##":
            ans="No"
            break
    print(ans)

else:
    #Bの位置に岩を置く
    a=S[:lis[2]-1]
    b=S[lis[2]:]
    S=a+"#"+b
    #Aを先に行かせる。可能なら終了。ダメならBを先に行かせてみる
    for i in range(lis[1],lis[3]-2):
        if S[i:i+2]=="##":
            ans="No"
            break
    #先にBを行かせる。まず可能か判定
    if ans=="No":
        ans="Yes"
        for i in range(lis[2],lis[4]-2):
            if S[i:i+2]=="##":
                ans="No"
                break
        for i in range(lis[2],lis[4]-3):
            if S[i:i+3]=="...":
                memo=i+1
                break
        #だめなら終了。可能ならmemoもしくはDに岩を置いてAについて検討
        if ans=="Yes":
            #print(S)
            if memo>0:
                a=S[:memo]
                b=S[memo+1:]
                S=a+"#"+b
            else:
                a=S[:lis[4]-1]
                b=S[lis[4]:]
                S=a+"#"+b
            #print(S)
            a=S[:lis[2]-1]
            b=S[lis[2]:]
            S=a+"."+b
            #print(S,memo)
            for i in range(lis[1],lis[3]-2):
                if S[i:i+2]=="##":
                    ans="No"
                    break
    print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int,input().split())
S = input()
slist = list(S)
buf = "".join(slist[A:max(C,D)-1])
#print(N, A, B, C, D)
#print(S)
 
judge = buf.find("##")
#print(judge)
 
#print(slist[A::])
#print(judge)
if judge != -1:
  print("No")
else:
  if C < D:
    print("Yes")
  else:
    s_change= "".join(slist[B-1:D])
    #print(s_change)
    judge = s_change.count("...")
    #print(judge)
    if judge > 0:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int,input().split())
S = input()
slist = list(S)
buf = "".join(slist[A:max(C,D)-1])
#print(N, A, B, C, D)
#print(S)
 
judge = buf.find("##")
#print(judge)
 
#print(slist[A::])
#print(judge)
if judge != -1:
  print("No")
else:
  if C < D:
    print("Yes")
  else:
    s_change= "".join(slist[B:D])
    #print(s_change)
    judge = s_change.count("...")
    #print(judge)
    if judge > 0:
      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 D > C:
    # 連続して岩があるとき（＝解けない）
    for i in range(D):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'

elif D < C:
    
    # 連続して岩があるとき（＝解けない）
    for i in range(C):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
    
    # 3マス連続する空きマスがあれば順番をいれかえられる
    if ans == 'Yes':
        ans = 'No'
        for i in range(D - B):
            i = i + B
            if ss[i-1] == 0 and ss[i] == 0 and ss[i+1] == 0 :
                ans = 'Yes'
else :
    ans = 'No'

print(ans)

Submission status: Wrong Answer

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

a_to_c = s[a:c-1]
b_to_d = s[b-1:d-1]
    
possibility = True

if c>d:
    if "##" in a_to_c or "..." not in s[(b-1)-1:(d-1)+1]:
        possibility = False
else:
    if "##" in a_to_c or "##" in s[b:d-2]:
        possibility = False

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

Submission status: Wrong Answer

Solution code:
import sys    

# 入力の読み込み
n, a , b, c, d = list(map(int, input().split()))
s = input()

# a,b,c,dをそれぞれ-1する
a, b, c, d = map(lambda x:x-1,[a,b,c,d])

# aとbのうち、小さい方を開始位置とする
# cとdのうち、大きい方を終了位置とする
start = a if a<b else b
end = c if c>d else d
s = s[start+1:end]
print(s)
## start~endの間に岩が２連続あったらだめ
if s.find('##') != -1:
    print('No')
    sys.exit()

## 追い抜きが発生する場合はstart~endの間に...がないとだめ
if c > d and s.find('...') == -1:
    print('No')
    sys.exit()   

print('Yes')

Submission status: Wrong Answer

Solution code:
#Python標準入出力

import numpy as np

# 1行に複数の文字列（数字）を取得，整数に直す
# 今回は2つ受け取って，足し算する

# 0 len root 1 sunuke 2 funuke 3 point1 4 point2 funuke
Masu = list(map(int, input().split()))
Root = input()

N = Masu[0]
A = Masu[1]
B = Masu[2]
C = Masu[3]
D = Masu[4]

S = Root

At = A-1
Bt = B-1
Ct = C-1
Dt = D-1

Judge = True

#Answer 1 パターン入れ込み

# print(Root[Bt:Dt])


threePoints = False

if C < D:
    if "##" in Root[Bt:Dt]:
        Judge = False
else:

    if "##" in Root[Bt:Ct]:
        Judge = False

    if "..." in Root[Bt:Dt] :
        threePoints = True

    Judge = threePoints

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




    # Rock = []
    # for i in range(Masu[0]):
    #     if Root[i] == "#":
    #         Rock.append(i+1)



    # print(threePoints)
    # for j in range(N):
    #     if S[j] == "#" and S[j-1] == "#":
    #         Judge = False
    #
    #     if C == j+1 and D == j+1-1 and Root[j-2] == "#" and threePoints:
    #         Judge = False
    #     if C == j+1 and Root[j-1] == "#" and D == j+1-2 and threePoints:
    #         Judge = False
    #
    #     # if Masu[3] == j+1:
    #     #     for p in range(j):
    #     #         if Masu[4] == p+1 and Root[p-1] == "#":
    #     #             Judge = False




    #Answer 2 動かし

# Sunuke = At
# Funuke = Bt
# throuth = 0
#
#
# if C < D:
#     for i in range(N-Funuke):
#
#         ii = i+Bt
#
#         # print("current {0}: funuke: {1}".format(ii,Funuke))
#         if Funuke == Dt:
#             break
#
#         elif S[ii] == "#" and S[ii+1] == "#":
#             Judge = False
#             break
#
#         elif S[ii] == "#":
#             throuth = 0
#
#         elif S[ii+1] == ".":
#             Funuke = Funuke+1
#
#         elif S[ii+1] == "#":
#             Funuke = Funuke+2
#
#     #
#     # print("Funuke: {}".format(Funuke))
#     # print("Sunuke: {}".format(Sunuke))
#     # print(At)
#     if Judge:
#         for j in range(N-Sunuke):
#
#             jj = j+At
#             # print("current {0}: Sunuke: {1}".format(jj, Sunuke))
#
#             if Sunuke == Ct:
#                 break
#
#             elif S[jj] == "#" and jj + 1 == Funuke:
#                 Judge = False
#                 break
#
#             elif S[jj] == "#":
#                 throuth = 0
#
#             elif S[jj + 1] == ".":
#                 Sunuke = Sunuke + 1
#
#             elif S[jj + 1] == "#" or jj+1 == Funuke:
#                 Sunuke = Sunuke + 2
#
#     #
#     # print(Sunuke)
#     # print(Funuke)
#     #
#
# else:
#     Rock = []
#     for i in range(Masu[0]):
#         if Root[i] == "#":
#             Rock.append(i + 1)
#
#     threePoints = False
#
#     for k in range(N):
#         if k < 1:
#             gg = 0
#         elif S[k] == "." and S[k - 1] == "." and S[k - 2] == ".":
#             # print("roop{}".format(k))
#             if D+1 > k:
#                 threePoints = True
#
#     # print(threePoints)
#
#     for j in range(Masu[0]):
#         if S[j] == "#" and S[j - 1] == "#":
#             Judge = False
#
#         if C == j + 1 and D == j + 1 - 1 and Root[j - 2] == "#" and (not threePoints):
#             Judge = False
#         if C == j + 1 and Root[j - 1] == "#" and D == j + 1 - 2 and (not threePoints):
#             Judge = False
#
#             # if Masu[3] == j+1:
#             #     for p in range(j):
#             #         if Masu[4] == p+1 and Root[p-1] == "#":
#             #             Judge = False
#
# if Judge:
#     print("Yes")
# else:
#     print("No")

Submission status: Wrong Answer

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

def check_serial(mark, number, start, end):
    ans = False
    i = start
    while i < end:
        for j in range(number):
            if s[i+j] != mark:
                i += j 
                break
            elif j == number-1:
                ans = True
        if ans:
            break
        i += 1
    return ans

ans = False
if c > d:
    ans = check_serial('.', 3, b, d-1)
ans = not check_serial('#', 2, a, c-1)
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int,input().split())
S = input()
slist = list(S)
buf = "".join(slist[A:max(C,D)-1])
#print(N, A, B, C, D)
#print(S)
 
judge = buf.find("##")
#print(judge)
 
#print(slist[A::])
#print(judge)
if judge != -1:
  print("No")
else:
  if C < D:
    print("Yes")
  else:
    s_change= "".join(slist[A:D])
    #print(s_change)
    judge = s_change.count("...")
    #print(judge)
    if judge > 0:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
class Kenken():
	def __init__(self,n,a,b,c,d,s):
		self.n = n
		self.a = a-1
		self.b = b-1
		self.c = c-1
		self.d = d-1
		self.s = s
		self.s = self.s[:a-1] + "A" + self.s[a:]
		self.s = self.s[:b-1] + "B" + self.s[b:]

	def str_replace(self,i,k,S):
		if k == 1:
			self.s = self.s[:i] + "." + S + self.s[i+2:]
		else:
			self.s = self.s[:i] + "." + self.s[i+1] + S + self.s[i+3:]

	def check_stone(self,i):
		if i < self.n:
			if self.s[i] == ".":
				return True
		return False

	def left(self,target,i):
		if target == "a":
			self.str_replace(self.a,i,"A")
			self.a += i
		else:
			self.str_replace(self.b,i,"B")
			self.b += i
	
	def get_space(self,S):
		if S == "a":
			return self.a
		elif S == "b":
			return self.b
		elif S == "c":
			return self.c
		elif S == "d":
			return self.d
	
n,a,b,c,d = map(int, input().split())
s = input()

over = 0

if s.find("##") >= 0:
	print("No")
	exit()

if c > d:
	if s.find("...") == -1:
		print("No")
		exit()
	else:
		over = 1
ken = Kenken(n,a,b,c,d,s)
flag=0

if over == 0:
	for i in range(n):
		if ken.get_space("b") != ken.get_space("d"):
			if ken.check_stone(ken.get_space("b")+1):
                        	ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()
		else:
			break
	for i in range(n):
		if ken.get_space("a") != ken.get_space("c"):
			if ken.check_stone(ken.get_space("a")+1):
                        	ken.left("a",1)
			elif ken.check_stone(ken.get_space("a")+2):
				ken.left("a",2)
			else:
				print("No")
				exit()
		else:
			print("Yes")
			exit()
else:
	for i in range(n*2):
		if ken.get_space("b") == ken.get_space("d"):
			print("Yes")
			exit()
		elif ken.check_stone(ken.get_space("b")-1) and ken.check_stone(ken.get_space("b")+1):
			if ken.get_space("a") != ken.get_space("c"):
				if ken.check_stone(ken.get_space("a")+1):
					ken.left("a",1)
				elif ken.check_stone(ken.get_space("a")+2):
					ken.left("a",2)
				else:
					print("No")
					exit()
			else:
				if ken.check_stone(ken.get_space("b")+1):
					ken.left("b",1)
				elif ken.check_stone(ken.get_space("b")+2):
					ken.left("b",2)
				else:
					print("No")
					exit()
		else:
			if ken.check_stone(ken.get_space("b")+1):
				ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()

Submission status: Wrong Answer

Solution code:
import sys    

# 入力の読み込み
n, a , b, c, d = list(map(int, input().split()))
s = input()

# a,b,c,dをそれぞれ-1する
a, b, c, d = map(lambda x:x-1,[a,b,c,d])

# aとbのうち、小さい方を開始位置とする
# cとdのうち、大きい方を終了位置とする
start = a if a<b else b
end = c if c>d else d
s = s[start:end+1]

## start~endの間に岩が２連続あったらだめ
if s.find('##') != -1:
    print('No')
    sys.exit()

## 追い抜きが発生する場合はstart~endの間に...がないとだめ
if c > d and s.find('...') == -1:
    print('No')
    sys.exit()   

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
 
N, A, B, C, D = map(int, input().split())
s = list(input())
 
A -= 1
B -= 1
C -= 1
D -= 1
 
for i in range(len(s)):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#' and max(C, D) < i and i <= C:
            print("No")
            exit()
 
if D < C:
    tmp = 0
    for i in range(len(s)):
        if i == len(s) - 2 or i == len(s) - 1:
            continue
        else:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' and B <= i + 1 <= D:
                tmp = 1
    if tmp != 1:
        print("No")
        exit()
 
 
 
#def check(s, start, goal, ans):
#    if start == goal:
#        return 1
#    if s[start] == '#':
#        return 0
#    if start + 1 <= N - 1:
#        ans += check(s, start + 1, goal, ans)
#    if start + 2 <= N - 1:
#        ans += check(s, start + 2, goal, ans)
#    return ans
 
#ans = 0
#if not check(s, B, D, ans):
#    print("No")
#    exit()
##s[D] = '#'
#if not check(s, A, C, ans):
#    print("No")
#    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int,input().split())
S = input()
slist = list(S)
buf = "".join(slist[A:max(C,D)-1])
#print(N, A, B, C, D)
#print(S)
 
judge = buf.find("##")
#print(judge)
 
#print(slist[A::])
#print(judge)
if judge != -1:
  print("No")
else:
  if C < D:
    print("Yes")
  else:
    s_change= "".join(slist[A:C])
    #print(s_change)
    judge = s_change.count("...")
    #print(judge)
    if judge > 0:
      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 = ''

# 場合分けして解く
if D > C:
    # 連続して岩があるとき（＝解けない）
    for i in range(D):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'Yes'

elif D < C:
    
    # 連続して岩があるとき（＝解けない）
    for i in range(C):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'Yes'
    
    # 3マス連続する空きマスがあれば順番をいれかえられる
    if ans == 'Yes':
        ans = 'No'
        for i in range(D - B):
            i = i + B
            if ss[i-1] == 0 and ss[i] == 0 and ss[i+1] == 0 :
                ans = 'Yes'
else :
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
 
 
def inputs(): return list(map(int, input().split()))
 
 
def main():
    _, A, B, C, D = inputs()
    S = input()
    maxDst = max(C, D)
    courseA = S[A:C]
    courseB = S[B:D]
    cnt = 0
    ans = []
    for i in courseB:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    cnt = 0
    for i in courseA:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    if D < C:
        cnt = 0
        for i in S[B-2:D+1]:
            if i == '.':
                cnt += 1
            if cnt == 3:
                ans.append(True)
                break
        else:
            ans.append(False)
 
    if all(ans):
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a_to_c = s[a:c-2]
b_to_d = s[b-1:d-1]
    
possibility = True

if c>d:
    if "##" in a_to_c or "..." not in s[(b-1)-1:d]:
        possibility = False
else:
    if "##" in a_to_c or "##" in s[b:d-2]:
        possibility = False

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

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int,input().split())
S = input()
slist = list(S)
buf = "".join(slist)
#print(N, A, B, C, D)
#print(S)
 
judge = buf.find("##")
#print(judge)
 
#print(slist[A::])
#print(judge)
if judge != -1:
  print("No")
else:
  if C < D:
    print("Yes")
  else:
    s_change= "".join(slist)
    #print(s_change)
    judge = s_change.count("...")
    #print(judge)
    if judge > 0:
      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 = ''

# 場合分けして解く
if D > C:
    # 連続して岩があるとき（＝解けない）
    for i in range(D - 1):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'Yes'

elif D < C:
    
    # 連続して岩があるとき（＝解けない）
    for i in range(C - 1):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'Yes'
    
    # 3マス連続する空きマスがあれば順番をいれかえられる
    if ans == 'Yes':
        ans = 'No'
        for i in range(D - B - 1):
            i = i + B
            if ss[i-1] == 0 and ss[i] == 0 and ss[i+1] == 0 :
                ans = 'Yes'
else :
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
#Python標準入出力

import numpy as np

# 1行に複数の文字列（数字）を取得，整数に直す
# 今回は2つ受け取って，足し算する

# 0 len root 1 sunuke 2 funuke 3 point1 4 point2 funuke
Masu = list(map(int, input().split()))
Root = input()

N = Masu[0]
A = Masu[1]
B = Masu[2]
C = Masu[3]
D = Masu[4]

S = Root

At = A-1
Bt = B-1
Ct = C-1
Dt = D-1

Judge = True

#Answer 1 パターン入れ込み


threePoints = False

if C < D:
    for j in range(D):
        if Root[j] == "#" and Root[j - 1] == "#":
            Judge = False
            break
else:
    for k in range(C):

        if Root[k] == "#" and Root[k - 1] == "#":
            Judge = False
            break

        if Root[k] == "." and Root[k-1] == "." and Root[k-2] == "." :
            if Dt>k and k-2 > Bt:
                threePoints = True

    Judge = threePoints

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




    # Rock = []
    # for i in range(Masu[0]):
    #     if Root[i] == "#":
    #         Rock.append(i+1)



    # print(threePoints)
    # for j in range(N):
    #     if S[j] == "#" and S[j-1] == "#":
    #         Judge = False
    #
    #     if C == j+1 and D == j+1-1 and Root[j-2] == "#" and threePoints:
    #         Judge = False
    #     if C == j+1 and Root[j-1] == "#" and D == j+1-2 and threePoints:
    #         Judge = False
    #
    #     # if Masu[3] == j+1:
    #     #     for p in range(j):
    #     #         if Masu[4] == p+1 and Root[p-1] == "#":
    #     #             Judge = False




    #Answer 2 動かし

# Sunuke = At
# Funuke = Bt
# throuth = 0
#
#
# if C < D:
#     for i in range(N-Funuke):
#
#         ii = i+Bt
#
#         # print("current {0}: funuke: {1}".format(ii,Funuke))
#         if Funuke == Dt:
#             break
#
#         elif S[ii] == "#" and S[ii+1] == "#":
#             Judge = False
#             break
#
#         elif S[ii] == "#":
#             throuth = 0
#
#         elif S[ii+1] == ".":
#             Funuke = Funuke+1
#
#         elif S[ii+1] == "#":
#             Funuke = Funuke+2
#
#     #
#     # print("Funuke: {}".format(Funuke))
#     # print("Sunuke: {}".format(Sunuke))
#     # print(At)
#     if Judge:
#         for j in range(N-Sunuke):
#
#             jj = j+At
#             # print("current {0}: Sunuke: {1}".format(jj, Sunuke))
#
#             if Sunuke == Ct:
#                 break
#
#             elif S[jj] == "#" and jj + 1 == Funuke:
#                 Judge = False
#                 break
#
#             elif S[jj] == "#":
#                 throuth = 0
#
#             elif S[jj + 1] == ".":
#                 Sunuke = Sunuke + 1
#
#             elif S[jj + 1] == "#" or jj+1 == Funuke:
#                 Sunuke = Sunuke + 2
#
#     #
#     # print(Sunuke)
#     # print(Funuke)
#     #
#
# else:
#     Rock = []
#     for i in range(Masu[0]):
#         if Root[i] == "#":
#             Rock.append(i + 1)
#
#     threePoints = False
#
#     for k in range(N):
#         if k < 1:
#             gg = 0
#         elif S[k] == "." and S[k - 1] == "." and S[k - 2] == ".":
#             # print("roop{}".format(k))
#             if D+1 > k:
#                 threePoints = True
#
#     # print(threePoints)
#
#     for j in range(Masu[0]):
#         if S[j] == "#" and S[j - 1] == "#":
#             Judge = False
#
#         if C == j + 1 and D == j + 1 - 1 and Root[j - 2] == "#" and (not threePoints):
#             Judge = False
#         if C == j + 1 and Root[j - 1] == "#" and D == j + 1 - 2 and (not threePoints):
#             Judge = False
#
#             # if Masu[3] == j+1:
#             #     for p in range(j):
#             #         if Masu[4] == p+1 and Root[p-1] == "#":
#             #             Judge = False
#
# if Judge:
#     print("Yes")
# else:
#     print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
s = input()
#index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]
#print(index)

if s.count("##")>=1:
    print("No")
    exit()

if C < D:
    print("Yes")

elif C > D:
    if "..." in s[B-2:D+1]:
        print("Yes")

    else:
        print("No")

Submission status: Wrong Answer

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

s = input()

flag1 = True
flag2 = True
flag3 = True

for i in range(b, d):
    if s[i:i+2] == "##":
        flag1 = False
for i in range(a, c):
    if s[i:i+2] == "##":
        flag2 = False
for i in range(b-2, d-1):
    if s[i:i+3] != "...":
        flag3 = False

if flag1 and flag2 and flag3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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


def get(a, b):
  s = S[:]
  s[a] = 'A'
  s[b] = 'B'

  return s


def check(s, i, dest):
  while i < dest:
    i += 1
    if i <= dest and s[i] == '.':
      continue
    i += 1
    if i <= dest and s[i] == '.':
      continue

    return False

  return i == dest


def move(s, i, dest):
  if i == dest:
    return -1

  while i < dest:
    i = i + 1
    if i + 1 < N:
      if s[i - 1] == '.' and s[i] == '.' and s[i + 1] == '.':
        return i

  return i if i == dest else -1


def main():
  a = A
  b = B

  for _ in range(1000):
    s = get(a, b)

    is_a = check(s, a, C)
    is_b = check(s, b, D)
    print((is_a, is_b), s)
    if is_a and is_b:
      return True

    if C > D:
      if is_a:
        a = C
      elif is_b:
        b = move(s, b, D)
      else:
        a = move(s, a, C)
    else:
      if is_b:
        b = D
      elif is_a:
        a = move(s, a, C)
      else:
        b = move(s, b, D)

    if a < 0 or b < 0:
      return False


print('Yes' if main() else 'No')

Submission status: Wrong Answer

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


if a > b:
    a, b, c, d = b, a, d, c


if '##' in s[a:c] or '##' in s[b:d]:print('No')
else:
    if c < d:
        print('Yes')

    else:
        if '...' in s[b - 1 : d + 1]:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
class Kenken():
	def __init__(self,n,a,b,c,d,s):
		self.n = n
		self.a = a-1
		self.b = b-1
		self.c = c-1
		self.d = d-1
		self.s = s
		self.s = self.s[:a-1] + "A" + self.s[a:]
		self.s = self.s[:b-1] + "B" + self.s[b:]

	def str_replace(self,i,k,S):
		if k == 1:
			self.s = self.s[:i] + "." + S + self.s[i+2:]
		else:
			self.s = self.s[:i] + "." + self.s[i+1] + S + self.s[i+3:]

	def check_stone(self,i):
		if i < self.n:
			if self.s[i] == ".":
				return True
		return False

	def check_goal(self):
		if self.a == self.c and self.b == self.d:
			return False
		else:
			return True

	def left(self,target,i):
		if target == "a":
			self.str_replace(self.a,i,"A")
			self.a += i
		else:
			self.str_replace(self.b,i,"B")
			self.b += i
	
	def get_space(self,S):
		if S == "a":
			return self.a
		elif S == "b":
			return self.b
		elif S == "c":
			return self.c
		elif S == "d":
			return self.d
	
	def print_all(self):
		print(self.s)

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

over = 0

if c > d:
	if s.find("...") == -1:
		print("No")
		exit()
	else:
		over = 1
ken = Kenken(n,a,b,c,d,s)
flag=0

if over == 0:
	for i in range(n):
		if ken.get_space("b") != ken.get_space("d"):
			if ken.check_stone(ken.get_space("b")+1):
                        	ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()
		else:
			break
	for i in range(n):
		if ken.get_space("a") != ken.get_space("c"):
			if ken.check_stone(ken.get_space("a")+1):
                        	ken.left("a",1)
			elif ken.check_stone(ken.get_space("a")+2):
				ken.left("a",2)
			else:
				print("No")
				exit()
		else:
			print("Yes")
			exit()
else:
	for i in range(n*2):
		if ken.get_space("b") == ken.get_space("d"):
			print("Yes")
			exit()
		elif ken.check_stone(ken.get_space("b")-1) and ken.check_stone(ken.get_space("b")+1):
			if ken.get_space("a") != ken.get_space("c"):
				if ken.check_stone(ken.get_space("a")+1):
					ken.left("a",1)
				elif ken.check_stone(ken.get_space("a")+2):
					ken.left("a",2)
				else:
					print("No")
					exit()
			else:
				if ken.check_stone(ken.get_space("b")+1):
					ken.left("b",1)
				elif ken.check_stone(ken.get_space("b")+2):
					ken.left("b",2)
				else:
					print("No")
					exit()
		else:
			if ken.check_stone(ken.get_space("b")+1):
				ken.left("b",1)
			elif ken.check_stone(ken.get_space("b")+2):
				ken.left("b",2)
			else:
				print("No")
				exit()

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 = ''

# 場合分けして解く
if D > C:
    # 連続して岩があるとき（＝解けない）
    for i in range(D - 1):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'Yes'

elif D < C:
    
    # 連続して岩があるとき（＝解けない）
    for i in range(C - 1):       
        if ss[i] == 1  and ss[i+1] == 1 :
            ans = 'No'
        else :
            ans = 'No'
    
            # 3マス連続する空きマスがあれば順番をいれかえられる
            for i in range(D - B - 1):
                i = i + B
                if ss[i-1] == 0 and ss[i] == 0 and ss[i+1] == 0 :
                    ans = 'Yes'
else :
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if s.count("##")>=1:
    print("No")
    exit()

elif C < D:
    print("Yes")

elif C > D:
    if len(index)>=1:
        for i in index:
            if B <= i+1 <= D:
                print("Yes")
                exit()
        print("No")
    else:
        print("No")