Problem: 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.

Submission attempts (in order):
7 1class 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()

ken = Kenken(n,a,b,c,d,s)
flag=0
while ken.check_goal():
	if (ken.check_stone(ken.get_space("b")+1) and ken.check_stone(ken.get_space("b")-1)) or (ken.get_space("a")+1 == ken.get_space("b") and ken.check_stone(ken.get_space("b")+1)): 
		if ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		elif ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		else:
			flag=1
			break
	else:
		if ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		elif ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		else:
			flag=1
			break

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

7 1class 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()

ken = Kenken(n,a,b,c,d,s)
flag=0
ken.print_all()
while ken.check_goal():
	if (ken.check_stone(ken.get_space("b")+1) and ken.check_stone(ken.get_space("b")-1)) or (ken.get_space("a")+1 == ken.get_space("b") and ken.check_stone(ken.get_space("b")+1)): 
		if ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		elif ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		else:
			flag=1
			break
	else:
		if ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		elif ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		else:
			flag=1
			break

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

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()

ken = Kenken(n,a,b,c,d,s)
flag=0
ken.print_all()
while ken.check_goal():
	if (ken.check_stone(ken.get_space("b")+1) and ken.check_stone(ken.get_space("b")-1)) or (ken.get_space("a")+1 == ken.get_space("b") and ken.check_stone(ken.get_space("b")+1)): 
		if ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		elif ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		else:
			flag=1
			break
	else:
		if ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		elif ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		else:
			flag=1
			break
	ken.print_all()

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

n,a,b,c,d = map(int, input().split())
s = input()
if s[a:c-1].count("##")!=0 or s[b:d-1].count("##")!=0:
	print("No")
	exit()

if c > d:
	if s[b-2:d+1].count("...") == 0:
		print("No")
		exit()
print("Yes")

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted