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
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
for i in range(N-2):
    if maze[i+1] == maze[i+2] == '#' and A-1 <= i+1 <= max(C,D):
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.' and B-1 <= i+1 <= C-1:
        Flag = 1
        break
if C > D:
    if Flag == 0:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
for i in range(N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.' and B-1 <= i+1 <= C-1:
        Flag = 1
        break
if C > D:
    if Flag == 0:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  space1 = S[A:D+1]
  if ('##' in space1) != True:
    print('Yes')
  else:
    print('No')
else:
  space1 = S[A:D+1]
  space2 = S[B-1:D+1]
  if ('##' in space1) != True and ('...' in space2) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  space1 = S[A:D+1]
  if ('##' in space1) != True:
    print('Yes')
  else:
    print('No')
else:
  space = S[B-1:D+1]
  if ('##' in S) != True and ('...' in space) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
hupt = 0
for i in range(N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.' and B-1 <= i <= C-1:
        Flag = 1
        hupt = i+1
        break
if C > D:
    if Flag == 0:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  if ('##' in S) != True:
    print('Yes')
  else:
    print('No')
else:
  space = S[B-1:D+2]
  if ('##' in S) != True and ('...' in space) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  if ('##' in S) != True:
    print('Yes')
  else:
    print('No')
else:
  space = S[B-1:D+1]
  if ('##' in S) != True and ('...' in space) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  if ('##' in S) != True:
    print('Yes')
  else:
    print('No')
else:
  space = S[B:D+2]
  if ('##' in S) != True and ('...' in space) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
A_start = True
if C < D:
  if ('##' in S) != True:
    print('Yes')
  else:
    print('No')
else:
  space = S[B:D+1]
  if ('##' in S) != True and ('...' in space) == True:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
hupt = 0
for i in range(B-2,N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.':
        Flag = 1
        hupt = i+1
        break
if C > D:
    if Flag == 0:
        print('No')
        exit()
    if B-1 <= hupt <= D-1:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
hupt = 0
for i in range(N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.':
        Flag = 1
        hupt = i+1
        break
if C > D:
    if Flag == 0:
        print('No')
        exit()
    if B-1 <= hupt <= C-1:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
supt = 0
hupt = 0
for i in range(B-2,N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.':
        Flag = 1
        supt = i+2
        hupt = i+1
        break
if C > D:
    if Flag == 0:
        print('No')
        exit()
    if supt < C and hupt < D:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = list(s())
if maze[0] == maze[1] == '#':
    print('No')
    exit()
Flag = 0
supt = 0
hupt = 0
for i in range(B-1,N-2):
    if maze[i+1] == maze[i+2] == '#':
        print('No')
        exit()
    if maze[i] == maze[i+1] == maze[i+2] == '.':
        Flag = 1
        supt = i+2
        hupt = i+1
        break
if C > D:
    if Flag == 0:
        print('No')
        exit()
    if supt < C and hupt < D:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

  # a と c の間に ## があったらだめ
  for i in range(a, c):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # b と d の間に ## があったらだめ
  for i in range(b, d):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # a が b を飛び越えないと行けない場合  b - d の間に ... がないとだめ
  if d < c and b < c:
    flag = False
    for i in range(b-1, d - 2):
      if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
        flag = True
    if not flag:
      print('No')
      return
  print('Yes')

  return

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=[int(i) for i in input().split()]
s=input()
flag = '...' in s
ans = flag or (a>b == c>d)
if '##' in s:
  ans=False
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n, a, b, c, d = map(int, input().split())
    s = input()
    bit = 0
    if c > d:
        for i in range(b, d-4):
            if s[i] == s[i+1] == s[i+3] == ".":
                bit = 1
                break
    else:
        bit = 1
    for i in range(a, max(c, d)-2):
        if s[i] == s[i+1] == "#":
            print("No")
            break
    else:
        if bit == 1:
            print("Yes")
        else:
            print("No")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

  # a と c の間に ## があったらだめ
  for i in range(a, c):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # b と d の間に ## があったらだめ
  for i in range(b, d):
    if s[i] == '#' and s[i+1] == '#':
      print('No')
      return
  # a が b を飛び越えないと行けない場合  b - d の間に ... がないとだめ
  if d < c:
    flag = False
    for i in range(b-1, d - 2):
      if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
        flag = True
    if not flag:
      print('No')
      return
  print('Yes')

  return

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

def exp(idx, goal):
    while 1:
        if idx==goal:
            return True
        if idx+1<N and S[idx+1]==".":
            idx += 1
        elif idx+2<N and S[idx+2]=='.':
            idx += 2
        else:
            return False

if C<D:
    if exp(A-1, C-1) and exp(B-1, D-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(B-2, max(N-2, D-1)):
        if S[i]=="." and S[i+1]=="." and S[i+2]==".":
            if exp(A-1, C-1) and exp(B-1, D-1):
                print('Yes')
            else:
                print('No')
            break
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

def exp(idx, goal):
    while 1:
        if idx==goal:
            return True
        if idx+1<N and S[idx+1]==".":
            idx += 1
        elif idx+2<N and S[idx+2]=='.':
            idx += 2
        else:
            return False

if C<D:
    if exp(A-1, C-1) and exp(B-1, D-1):
        print('Yes')
    else:
        print('No')
elif B-D>=2:
    for i in range(B-1, D-2):
        if S[i]=="." and S[i+1]=="." and S[i+2]==".":
            if exp(A-1, C-1) and exp(B-1, D-1):
                print('Yes')
            else:
                print('No')
            break
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n, a, b, c, d = map(int, input().split())
    s = input()
    bit = 0
    if c > d:
        for i in range(b, d-1):
            if s[i] == s[i+1] == s[i+3] == ".":
                bit = 1
                break
    else:
        bit = 1
    for i in range(a, max(c, d)-2):
        if s[i] == s[i+1] == "#":
            print("No")
            break
    else:
        if bit == 1:
            print("Yes")
        else:
            print("No")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
S = list(S)
Flag = False
if D > C:
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")
else:
  P = False
  for i in range(B-1,D-1):
    if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
      P = True
  if not P:
    #print("unko")
    print("No")
    exit()
  #Flag = False
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
S = list(S)
Flag = False
if D > C:
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")
else:
  P = False
  for i in range(B-1,D-1):
    if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
      P = True
  if not P:
    print("unko")
    print("No")
    exit()
  #Flag = False
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

def exp(idx, goal):
    while 1:
        if idx==goal:
            return True
        if idx+1<N and S[idx+1]==".":
            idx += 1
        elif idx+2<N and S[idx+2]=='.':
            idx += 2
        else:
            return False

if C<D:
    if exp(A-1, C-1) and exp(B-1, D-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(B-1, D-2):
        if S[i]=="." and S[i+1]=="." and S[i+2]==".":
            if exp(A-1, C-1) and exp(B-1, D-1):
                print('Yes')
            else:
                print('No')
            break
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
S = list(S)
Flag = False
if D > C:
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")
else:
  P = False
  for i in range(B-1,D-3):
    if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
      P = True
  if not P:
    print("No")
    exit()
  for i in range(B,D):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False

  Flag = False
  for i in range(A,C):
    if S[i] == "#" and Flag == True:
      print("No")
      exit()
    elif S[i] == "#":
      Flag = True
    else:
      Flag = False
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,A,B,C,D = map(int,readline().split())
S = readline().rstrip()

if C < D:#抜かさなくて良い
    if "##" not in S[A-1:D]:
        print("Yes")
    else:
        print("No")
else:#抜かす必要がある
    if "..." in S[B-2:D] and "##" not in S[A-1:C]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
Flag = False
for i in range(B-1,D):
  if S[i] == "#" and Flag == True:
    print("No")
    exit()
  elif S[i] == "#":
    Flag = True
  else:
    Flag = False
Flag = False
for i in range(A-1,C):
  if S[i] == "#" and Flag == True:
    print("No")
    exit()
  elif S[i] == "#":
    Flag = True
  else:
    Flag = False
print("Yes")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
for i in range(B-1,D-1):
  if S[i:i+2]=='##':
    print('No')
    exit() 
for i in range(A-1,C-1):
  if S[i:i+2]=='##':
    print('No')
    exit()
if C>D:
  for i in range(B-2,D-2):
    if S[i:i+3]=='...':
      print('Yes')
      exit()
  print('No')
  exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#ランレングス圧縮
def rle_comp(S):
    rle = []
    pre = 'X'
    chain = 1
    for c in S:
        if c == pre:
            chain += 1
        else:
            if pre != 'X':
                rle.append([pre,chain])
            
            pre = c
            chain = 1
    rle.append([pre,chain])

    #print(rle)
    return rle

N,A,B,C,D = map(int,input().split())
S = input()
#S = S[:A-1] + 'A' + S[A:]
#S = S[:B-1] + 'B' + S[B:]
#print(S)
ans = "Yes"
#すぬけ君がふぬけ君を2マスジャンプで追い越しが不要な場合
if C < D:
    rle = rle_comp(S[A-1:D])
    for i in range(len(rle)):
        #2マスジャンプで岩をやりすごせるか判定
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"
#すぬけ君がふぬけ君を2マスジャンプで追い越しが必要な場合
else:
    rle = rle_comp(S[A-1:C])
    for i in range(len(rle)):
        #2マスジャンプで岩をやりすごせるか判定
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"

    space = False
    #ふぬけ君がゴール地点にいる状態で追い越しをする場合を考慮するため
    #D+1までを範囲に含める
    rle = rle_comp(S[B-1:D+1])
    for i in range(len(rle)):
        #追い越しができるか判定
        if rle[i][0] == '.' and rle[i][1] >= 3:
            space = True
    
    if space == False:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
#ランレングス圧縮
def rle_comp(S):
    rle = []
    pre = 'X'
    chain = 1
    for c in S:
        if c == pre:
            chain += 1
        else:
            if pre != 'X':
                rle.append([pre,chain])
            
            pre = c
            chain = 1
    rle.append([pre,chain])

    #print(rle)
    return rle

N,A,B,C,D = map(int,input().split())
S = input()
#S = S[:A-1] + 'A' + S[A:]
#S = S[:B-1] + 'B' + S[B:]
#print(S)
ans = "Yes"
if C < D:
    rle = rle_comp(S[A-1:D-1])
    for i in range(len(rle)):
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"
else:
    rle = rle_comp(S[A-1:C-1])
    for i in range(len(rle)):
        if rle[i][0] == '#' and rle[i][1] >= 2:
            ans = "No"

    space = False
    rle = rle_comp(S[B-1:D-1])
    for i in range(len(rle)):
        if rle[i][0] == '.' and rle[i][1] >= 3:
            space = True
    
    if space == False:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

# 連続した岩がないか
for i in range(max(c, d) - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

if c < d:
    print('Yes')
    sys.exit()

else:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            print('Yes')
            sys.exit()
    print('No')

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

# 連続した岩がないか
for i in range(max(c, d) - 1):
    # print(f'{s[i:i+2]=}')
    if s[i:i + 2] == '##':
        print('No')
        sys.exit()

if c < d:
    print('Yes')
    sys.exit()

else:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            print('Yes')
            sys.exit()
    print('No')

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

is_ok = True
# 連続した岩がないか
for i in range(max(c, d) - 1):
    # print(f'{s[i:i+2]=}')
    if s[i:i + 2] == '##':
        is_ok = False
        break

if d < c:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    is_ok = False
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            is_ok = True
            break

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

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

is_ok = True
# 連続した岩がないか
for i in range(max(c, d) - 1):
    # print(f'{s[i:i+2]=}')
    if s[i:i + 2] == '##':
        is_ok = False
        break

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

if d < c:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    is_ok = False
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            is_ok = True
            break

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

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

is_ok = True
# 連続した岩がないか
for i in range(max(c, d) - 1):
    print(f'{s[i:i+2]=}')
    if s[i:i + 2] == '##':
        is_ok = False
        break

if is_ok:
    print('Yes')
else:
    print('No')
if d < c:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    is_ok = False
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            is_ok = True
            break

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

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

is_ok = True
# 連続した岩がないか
for i in range(n - 1):
    if s[i:i + 2] == '##':
        is_ok = False
        break
if d < c:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    is_ok = False
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            is_ok = True
            break

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

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = list(S())

is_ok = True
# 連続した岩がないか
for i in range(n - 1):
    if s[i:i + 2] == '##':
        is_ok = False
        break
if d < c:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] != '...':
            is_ok = False
            break

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

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = list(S())
s1 = s[::]
s2 = s[::]


def search(start, goal, ss):
    now = start
    while now < goal:
        # 1マス移動 と 2マス移動のできる方を選んでいく
        if now + 2 <= n - 1 and ss[now + 2] != '#':
            now += 2
        elif now + 1 <= n - 1 and ss[now + 1] != '#':
            now += 1
        else:
            return False
        if now == goal:
            return True


res = False
# すぬけ君とふぬけ君のどちらかを先に動かして確かめる
for befor, after, si in [[(a, c), (b, d), s1], [(b, d), (a, c), s2]]:
    i, k = befor
    j, l = after
    if i == a:
        si[b] = '#'
    if search(i, k, si):
        si[k] = '#'
        si[b] = '.'
    else:
        continue
    if search(j, l, si):
        res = True
        break

if res:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = list(S())
s1 = s[::]
s2 = s[::]


def search(start, goal, ss):
    now = start
    while now < goal:
        # 1マス移動 と 2マス移動のできる方を選んでいく
        if now + 2 <= n - 1 and ss[now + 2] != '#':
            now += 2
        elif now + 1 <= n - 1 and ss[now + 1] != '#':
            now += 1
        else:
            return False
        if now == goal:
            return True


res = False
# すぬけ君とふぬけ君のどちらかを先に動かして確かめる
for befor, after, si in [[(a, c), (b, d), s1], [(b, d), (a, c), s2]]:
    i, k = befor
    j, l = after

    if search(i, k, si):
        si[k] = '#'
    else:
        continue
    if search(j, l, si):
        res = True
        break

if res:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

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

flag = 0
for i in range(min(a,b)+1,max(c,d)):
        if (a < i < c or b < i < d) and s[i] == s[i-1] == '#':
                print("No")
                exit()       
        elif max(a,b) < i < min(c,d) and s[i-1] == s[i] == s[i+1] == '.':
                flag = 1

if c > d and flag == 0:
        print("No")
else:
        print("Yes")