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:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
tri = 0
for i in range(min(A, B) - 1, N - 1):
  if S[i] == "#" and (S[i + 1] == "#"):
    print("No")
    exit(0)
for i in range(min(A, B) - 1, N - 2):
  if S[i] == "." and (S[i + 1] == ".") and (S[i + 2] == "."): tri = 1
if C <= D:
  print("Yes")
else:
  if tri: print("Yes")
  else: print("No")

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

def check_one_people_can(start, end):
    s = S[start+1: end]
    before_sharp = False
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start: end+1]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, C) and check_triple_dots(A, C) and check_triple_dots(D, C):
        print("Yes")
    else:
        print("No")

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

def check_one_people_can(start, end):
    s = S[start+1: end]
    before_sharp = False
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start: end+1]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, C) and check_triple_dots(A, B) and check_triple_dots(D, C):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
for _ in range(2):
  A, B, C, D = B, A, D, C
  S[A - 1] = "#"
  dp = [0] * (N + 1)
  dp[B] = 1
  for i in range(B, N + 1):
    if dp[i] == 0: continue
    if i + 1 <= N:
      if S[i] == ".":
        dp[i + 1] = 1
    if i + 2 <= N:
      if S[i + 1] == ".":
        dp[i + 2] = 1
  if dp[D] == 0:
    S[A - 1] = "."
    continue
  S[A - 1] = "."
  S[D - 1] = "#"
  dp = [0] * (N + 1)
  dp[A] = 1
  for i in range(A, N + 1):
    if dp[i] == 0: continue
    if i + 1 <= N:
      if S[i] == ".":
        dp[i + 1] = 1
    if i + 2 <= N:
      if S[i + 1] == ".":
        dp[i + 2] = 1
  if dp[C]:
    print("Yes")
    exit(0)
  else:
    f = 0
    for i in range(min(A, B) - 1, N - 3):
      if S[i] == "." and (S[i + 1] == ".") and (S[i + 2] == "."):
        f = 1
    if f:
      S[D - 1] = "."
      dp = [0] * (N + 1)
      dp[A] = 1
      for i in range(A, N + 1):
        if dp[i] == 0: continue
        if i + 1 <= N:
          if S[i] == ".":
            dp[i + 1] = 1
        if i + 2 <= N:
          if S[i + 1] == ".":
            dp[i + 2] = 1
      if dp[C]:
        print("Yes")
        exit(0)
    
print("No")

Submission status: Wrong Answer

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

B_range = S[B - 2 : D + 1]
# print(B_range)

for i in range(len(B_range) - 1):
    if B_range[i] == B_range[i + 1] == "#":
        print("No")
        exit()

is_three = False
for i in range(len(B_range) - 2):
    if B_range[i] == B_range[i + 1] == B_range[i + 2] == ".":
        is_three = True
        break

if S[-2] == '.' and N == D:
    is_three = True

for i in range(len(S) - 1):
    if S[i] == S[i + 1] == "#":
        print("No")
        exit()
if is_three:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, a, b, c, d = MAP()
s = STR()
dp1 = [inf for _ in range(n + 1)]
dp1[a] = 0
for i in range(a + 1,c + 1):
    if s[i - 1] == '.':
        if i - 2 >= a:
            dp1[i] = min(dp1[i - 1], dp1[i - 2]) + 1
        else:
            dp1[i] = dp1[i - 1] + 1
dp2 = [inf for _ in range(n + 1)]
dp2[b] = 0
for i in range(b + 1, d + 1):
    if s[i - 1] == '.':
        if i - 2 >= b:
            dp2[i] = min(dp2[i - 1], dp2[i - 2]) + 1
        else:
            dp2[i] = dp2[i - 1] + 1

if a < b and c < d or a > b and c > d:
    if dp1[c] < inf and dp2[d] < inf:
        print('Yes')
    else:
        print('No')
else:
    if a > b and c < d:
        a, b = b, a
        c, d = d, c
    flag = False
    for i in range(b + 1, d + 1): #抜かす場所
        if s[i - 2] == '.' and s[i - 1] == '.' and s[i] == '.':
            flag = True
    if dp1[c] < inf and dp2[d] < inf and flag:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
if C > D:
  A, B = B, A
  C, D = D, C
S[A - 1] = "#"
dp = [0] * (N + 1)
dp[B] = 1
for i in range(B, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[D] == 0:
  print("No")
  exit(0)
S[A - 1] = "."
S[D - 1] = "#"
dp = [0] * (N + 1)
dp[A] = 1
for i in range(A, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[C]:
  print("Yes")
else:
  f = 0
  for i in range(min(A, B) - 1, N - 3):
    if S[i] == "." and (S[i + 1] == ".") and (S[i + 2] == "."):
      f = 1
  if f:
    S[D - 1] = "."
    dp = [0] * (N + 1)
    dp[A] = 1
    for i in range(A, N + 1):
      if dp[i] == 0: continue
      if i + 1 <= N:
        if S[i] == ".":
          dp[i + 1] = 1
      if i + 2 <= N:
        if S[i + 1] == ".":
          dp[i + 2] = 1
    if dp[C]:
      print("Yes")
      exit(0)
  print("No")

Submission status: Wrong Answer

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

def isOk(fr, to):
    if S[fr: to + 1].count('##') > 0:
        return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

def canSwitch():
    if A + 1 == B and D < C and S[A: A + 3] == '...':
        return True
    if B + 1 == A and C < D and S[B: B + 3] == '...':
        return True
    if C + 1 == D and B < A and S[C - 1: D + 1] == '...':
        return True
    if D + 1 == C and A < B and S[D - 1: C + 1] == '...':
        return True
    if S[max(A, B): min(C, D) + 1].count('...'):
        return True
    return False

if A < B and D < C or B < A and C < D:
    if not canSwitch():
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    N, a, b, c, d = (int(i) for i in input().split())
    S = input()
    if "##" in S[a:c] or "##" in S[b:d]:
        return print("No")
    if c < d:
        return print("Yes")
    # d < c
    if "..." in S[b-2:d+2]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def isOk(fr, to):
    now = A
    while now < C:
        if S[now + 1] == '.':
            now += 1
        elif S[now + 2] == '.':
            now += 2
        else:
            return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

def canSwitch():
    if A + 1 == B and S[A: A + 3] == '...':
        return True
    if B + 1 == A and S[B: B + 3] == '...':
        return True
    if C + 1 == D and S[C - 1: D + 1] == '...':
        return True
    if D + 1 == C and S[D - 1: C + 1] == '...':
        return True
    if S[max(A, B): min(C, D) + 1].count('...'):
        return True
    return False

if A < B and D < C or B < A and C < D:
    if not canSwitch():
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    N, a, b, c, d = (int(i) for i in input().split())
    S = input()
    if "##" in S[a:c] or "##" in S[b:d]:
        return print("No")
    if c < d:
        return print("Yes")
    # d < c
    if "..." in S[b-2:d-1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if "##" in S[B: D - 1]:
    print("No")
    exit()
elif "##" in S[A: C - 1]:
    print("No")
    exit()

if D < C:
    if not "..." in S[B - 2: D + 2]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

def isOk(fr, to):
    now = A
    while now < C:
        if S[now + 1] == '.':
            now += 1
        elif S[now + 2] == '.':
            now += 2
        else:
            return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

if A < B and D < C or B < A and C < D:
    if S[max(A, B) - 1: min(C, D) + 3].count('...') == 0:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = 100#sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, a, b, c, d = MAP()
s = STR()
if a < b and c < d or a > b and c > d:
    dp1 = [inf for _ in range(n + 1)]
    dp1[a] = 0
    for i in range(a + 1,c + 1):
        if s[i - 1] == '.':
            if i - 2 >= a:
                dp1[i] = min(dp1[i - 1], dp1[i - 2]) + 1
            else:
                dp1[i] = dp1[i - 1] + 1
    dp2 = [inf for _ in range(n + 1)]
    dp2[b] = 0
    for i in range(b + 1, d + 1):
        if s[i - 1] == '.':
            if i - 2 >= b:
                dp2[i] = min(dp2[i - 1], dp2[i - 2]) + 1
            else:
                dp2[i] = dp2[i - 1] + 1
    if dp1[c] < inf and dp2[d] < inf:
        print('Yes')
    else:
        print('No')
else:
    if a > b and c < d:
        a, b = b, a
        c, d = d, c
    dp1 = [[inf for _ in range(n + 1)] for _ in range(n + 1)]
    for i in range(n):
        dp1[i][a] = 0
    dp2 = [inf for _ in range(n + 1)]
    dp2[b] = 0
    for ii in range(b + 1, d + 1):
        if s[ii - 1] == '.':
            if i - 2 >= b:
                dp2[ii] = min(dp2[ii - 1], dp2[ii - 2]) + 1
            else:
                dp2[ii] = dp2[ii - 1] + 1
            for i in range(a + 1, c + 1):
                if s[i - 1] == '.' and i != ii:
                    if i - 2 >= a:
                        dp1[ii][i] = min(dp1[ii][i - 1], dp1[ii][i - 2]) + 1
                    else:
                        dp1[ii][i] = dp1[ii][i - 1] + 1
    '''
    for i in range(n):
        print(dp1[i])
    print('')
    print(dp2)
    '''
    for i in range(n):
        if dp1[i][c] < inf and dp2[d] < inf:
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

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

def isOk(fr, to):
    now = A
    while now < C:
        if S[now + 1] == '.':
            now += 1
        elif S[now + 2] == '.':
            now += 2
        else:
            return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

if A < B and D < C or B < A and C < D:
    if S[max(A, B) - 1: min(C, D) + 2].count('...') == 0:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

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

def isOk(fr, to):
    now = A
    while now < C:
        if S[now + 1] == '.':
            now += 1
        elif S[now + 2] == '.':
            now += 2
        else:
            return False
    return True

if not (isOk(A, C) and isOk(C, D)):
    print('No')
    exit()

if A < B and D < C or B < A and C < D:
    if S[max(A, B): min(C, D) + 1].count('...') == 0:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

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

if "##" in S[B: D - 1]:
    print("No")
    exit()
elif "##" in S[A: C - 1]:
    print("No")
    exit()


if D < C:
    if "..." in S[A: D - 1]:
        print("Yes")
    else:
        print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
if C > D:
  A, B = B, A
  C, D = D, C
dp = [0] * (N + 1)
dp[B] = 1
for i in range(B, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[D] == 0:
  print("No")
  exit(0)
S[A - 1] = "."
S[D - 1] = "#"
dp = [0] * (N + 1)
dp[A] = 1
for i in range(A, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
#print(dp)
if dp[C]:
  print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
dp = [0] * (N + 1)
dp[B] = 1
for i in range(B, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[D] == 0:
  print("No")
  exit(0)
S[D - 1] = "#"
dp = [0] * (N + 1)
dp[A] = 1
for i in range(A, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
#print(dp)
if dp[C]:
  print("Yes")
else: print("No")

Submission status: Wrong Answer

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

if c<d:
    if s[a-1:].find("##")!=-1:
        print("No")
    else:
        print("Yes")

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

Submission status: Wrong Answer

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

if c<d:
    if s[a-1:].find("##")!=-1:
        print("No")
    else:
        print("Yes")

else:
    if s[a-1:].find("##")!=-1:
        print("No")
    else:
        for i in range(b-1,d):
            if s[i-1]=="." and s[i]=="." and s[i+1]==".":
                print("Yes")
                exit()
        print("No")

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B,C,D = imn()
S = list(input())

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-1, b-1):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if C == D:
    ans = False
if not can_reach(A, C) or not can_reach(B, D):
    ans = False
if C > D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B,C,D = imn()
S = list(input())

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-1, b-1):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if not can_reach(A, C) or not can_reach(B, D):
    ans = False
if C > D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B,C,D = imn()
S = list(input())

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-1, b-3):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if not can_reach(A, C) or not can_reach(B, D):
    ans = False
if C > D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B,C,D = imn()
S = list(input())

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-1, b-2):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if not can_reach(A, C) or not can_reach(B, D):
    ans = False
if C > D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B,C,D = imn()
S = list(input())

def can_reach(a, b):
    reachable = True
    for i in range(a-1, b-1):
        if S[i] != '#' or S[i+1] != '#': continue
        reachable = False
    return reachable

def takeoverable(a, b):
    cantakeover = False
    for i in range(a-1, b-2):
        if S[i] == '#' or S[i+1] == '#' or S[i+2] == '#': continue
        cantakeover = True
    return cantakeover

ans = True
if not can_reach(A, B) or not can_reach(C, D):
    ans = False
if C < D:
   if not takeoverable(B,D):
       ans = False
print('Yes' if ans else 'No')