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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
s = input()
if C<D:
    ans = 'Yes'
else:
    if s[B-2:D].count('...')>0:
        ans = 'Yes'
        if D-B == 1:
            ans = 'No'
        elif D-B == 2: 
            if s[B-2]!= '#' or s[D]!= '#':
                ans = 'No'
    else:
        ans = 'No'
if s[A:C-2].count('##')!=0 or s[B:D-2].count('##')!=0:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    N, A, B, C, D = map(int, input().split())
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    iwa = "#"
    S = input()
    ans = True
    canexchange = False

    exchagable_list = []
    for i in range(N-2):
        temps = S[i:i+3]
        if temps == "...":
            exchagable_list.append(i)

    if len(exchagable_list) > 0:
        for i in exchagable_list:
            if i >= A and i+1 <= min(C, D):
                canexchange = True
    # print(canexchange)
    for i in range(N-1):
        if S[i] == iwa and S[i+1] == iwa:
            if not (i+1 < A or i > max(C, D)):
                ans = False

    if ans:
        if C < D:
            ans = True
        elif C > D and canexchange:
            ans = True
        elif C > D and not canexchange:
            if S[D-1] == iwa or S[D+1] == iwa:
                ans = False
            else:
                ans = True

    if ans:
        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:
    print("No")
    quit()

if C > D:
    if '...' not in S[B:C-1]:
        print("No")
        quit()
    if S[B:C-1].count('...') % 2 == 0:
        print("No")
        quit()
    if C - D == 2 and S[C - 2] == '#' and S[D - 2] == '#':
        print("No")
        quit()

print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            if(S[B-1:D].count('...') == 0):
                print(NO)
            else:
                print(YES)
        else:
            print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int,input().split())
s = input()
if '##' in s:
    print('No')
elif c < d:
    print('Yes')
else:
    p = []
    i = -1
    while True:
        i = s.find('...', i + 1)
        if b <= i < d:
            print('Yes')
            break
        elif i >= d:
            print('No')
        else:
            pass

Submission status: Wrong Answer

Solution code:
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")
elif c < d:
    print("Yes")
else:
    if s[b-1:c].count("...") > 0 or s[b-2] == "." and s[b] == ".":
        if s[b-1:c].count("...") == 1 and s[d-1:c] == "..." and s[d-2] == "#":
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
A -= 1
B -= 1
C -= 1
D -= 1
ans = True
if C < B:
    count_x = 0
    ans = True
    for i in range(A, C):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
    if ans:
        count_x = 0
        for i in range(B, D):
            if S[i] == "#":
                count_x += 1
            else:
                count_x = 0
            if count_x > 1:
                ans = False
                break
elif C < D:
    count_x = 0
    ans = True
    for i in range(A, D):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
else:
    count_x = 0
    ans = True
    for i in range(A, C):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
    if ans:
        count_o = 0
        ans = False
        for i in range(B, D+2):
            if S[i] == "#":
                count_o = 0
            else:
                count_o += 1
            if count_o > 2:
                ans = True
                break
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
obs = [S[i] is "#" and S[i+1] is "#" for i in range(0,max(C,D)-1)]
space = [S[i] is "." and S[i+1] is "." and S[i+2] is "." for i in range(0,max(C,D)-2)]
if C < D:
  if True in obs[B:D] or True in obs[A:C]:
    print("No")
  else:
    print("Yes")
else:
  if True not in space[B-1:D]:
    print("No")
  elif True in obs[B:D-1] or True in obs[A:C-1]:
    print("No")
  else:
    print("Yes")

Submission status: Wrong Answer

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

tmp_s = s[:b - 1] + "#" + s[b:]
a_s = tmp_s[a:]
tmp_s = s[:d - 1] + "#" + s[d:]
aa_s = tmp_s[a:c]

tmp_s = s[:a - 1] + "#" + s[a:]
b_s = tmp_s[b:]
tmp_s = s[:c - 1] + "#" + s[c:]
bb_s = tmp_s[b:d]

a_flag = False
b_flag = False
if ("##" not in a_s and "##" not in bb_s) or ("##" not in aa_s and "##" not in b_s) or "..." in a_s or "..." in aa_s:
    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

if S[C] == '#' or S[D] == '#':
    print("No")
    exit()

stone = 0
road = 0
c = False
l = [-1]

for i in range(B + 1, D):
    if S[i] == '#':
        stone += 1
        road = 0
        if c:
            l.append(i - 1)
            c = False
        if stone > 1:
            print("No")
            exit()
    else:
        road += 1
        stone = 0
        if road > 2:
            c = True

stone = 0
road = 0

count = 0

# B放置でゴールできるか
if S[B - 1] == '#' or S[B + 1] == '#':
    count += 1
# Bがゴールしているとゴールできるか
if D < C:
    if S[D - 1] == '#' or S[D + 1] == '#':
        count += 1

if count > 1:
    if l[-1] < 0:
        print("No")
        exit()

# Bが避難しているときBはAを通したあとゴールできるか
if C < D:
    if l[-1] < C:
        if S[C - 1] == '#' or S[C + 1] == '#':
            count += 1

if count > 2:
    print("No")
    exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
flag=0
span=0
buf=-5
if(c<d):
    for i in range(a-1,d):
        if(s[i]=='#' and s[i+1]=='#'):
            flag=1
            break
else:
    for i in range(a-1,c):
        if(s[i]=='#' and s[i+1]=='#'):
            flag=1
            break
        elif s[i]=='#' :
            buf=max([span,buf])
            span=0
        elif b-2<i<d+2:
            span+=1
    if buf<=2:
        flag=1
        #print(buf)
print('No' if flag==1 else 'Yes')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if (c<d):
	if not '##' in s[a-1:d-1]: print('Yes')
	else: print('No')
elif (d<c):
	if (not '##' in s[a-1:c-1])&('..' in s[d-2:c-1]): print('Yes')
	else: print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    # A,Bからみて先が"##"の状態になったら詰み
    if "##" not in S[A:] and "##" not in S[B:]:
        if C < D or C < B:
            # 先にBをDまで移動させればAもたどり着ける
            print("Yes")
        else:
            # AがBを追い抜く必要があるので、
            # その瞬間に#B or B#にならないようにしないといけない
            # BからD+1の間に ... があればOK
            if "..." in S[B:D+2]:
                print("Yes")
            else:
                print("No")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
n,a,b,c,d = map(int,input().split())
s = input()
a -= 1
b -= 1
c -= 1
d -= 1
truth = [[0 for i in range(n)],[0 for j in range(n)]]

def solve(now,dest,i):
    if truth[i][now] == 1:
        return True
    if truth[i][now] == -1:
        return False
    if now == dest:
        truth[i][now] = 1
        return True
    if now + 2 < n:
        if s[now + 2] == '.' and solve(now + 2, dest,i):
            truth[i][now] = 1
            return True
    if now + 1 < n:
        if s[now + 1] == '.' and solve(now + 1, dest,i):
            truth[i][now] = 1
            return True
    else:
        truth[i][now] = -1
        return False

if c < d:
    if solve(a,c,0) and solve(b,d,1):
        print('Yes')
    else:
        print('No')

else:
    q = False
    for i in range(b,d):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            q = True
            break
    if q and solve(a,c,0) and solve(b,d,1):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

if d > c:
    flag1 = False
    block = 0
    for i in range(b, len(s)):
        if block == 2:
            flag1 = False
            break
        elif i == d-1:
            flag1 = True
            break
        elif s[i] == ".":
            block = 0
        elif s[i] == "#":
            block += 1

    if flag1 == True:
        s2 = s[:d-1]+'#'+s[d:]
        flag1 = False
        block = 0
        for i in range(a, c + 1):
            if block == 2:
                flag1 = False
                break
            elif i == c-1:
                flag1 = True
                break
            elif s2[i] == ".":
                block = 0
            elif s2[i] == "#":
                block += 1

    if flag1:
        print("Yes")
    else:
        print("No1")



else:
    flag2 = False
    flag3 = False
    temp = 0
    block = 0
    for i in range(b,c-1):
        if temp == 3:
            flag2 = True
            temp = i-1
            break
        elif s[i] == "#":
            temp = 0
        elif s[i] == ".":
            temp += 1

    if flag2 == True:
        flag3 = False
        block = 0
        s1 = s[:temp - 1] + '#' + s[temp:]
        for i in range(a, len(s)):
            print(s1[i])
            if block == 2:
                flag3 = False
                break
            elif i == c-1:
                flag3 = True
                break
            elif s1[i] == ".":
                block = 0
            elif s1[i] == "#":
                block += 1

        if flag3 == True:
            s3 = s1[:c - 1] + '#' + s1[c:]
            flag3 = False
            block = 0
            for i in range(temp + 1, len(s)):
                if block == 2:
                    flag3 = False
                    break
                elif i == c-1:
                    flag3 = True
                    break
                elif s3[i] == ".":
                    block = 0
                elif s3[i] == "#":
                    block += 1

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    A -= 1
    B -= 1
    C -= 1
    D -= 1

    S_original = S
    S = list(S_original)

    flag = False
    
    # case1 Cに先にたどり着くパターン
    S[C] = '#'
    S[B] = '#'

    S = ''.join(S)
    if '##' in S[A+1:C]:
        pass
    elif '##' in S[B+1:D]:
        pass
    else:
        flag = True

    # case2 Dに先にたどり着くパターン
    S = list(S_original)

    S[D] = '#'
    S[A] = '#'

    S = ''.join(S)
    if '##' in S[A+1:C]:
        pass
    elif '##' in S[B+1:D]:
        pass
    else:
        flag = True

    # case 3 途中で追い越すパターン
    S = list(S_original)

    S = ''.join(S)
    if '...' in S[B+1:C] or '..' == S[B+1:B+1+2] or '..' == S[C-2:C]:
        # case 3-1 Cに先にたどり着くパターン
        S = list(S_original)
        S[C] = '#'
        S = ''.join(S)
        
        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

        # case 3-2 Dに先にたどり着くパターン
        S = list(S_original)
        S[D] = '#'
        S = ''.join(S)
        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

    # case 4 途中で追い越すパターン
    S = list(S_original)

    S = ''.join(S)
    if '...' in S[B+1:C] or '..' == S[B+1:B+1+2] or '..' == S[D-2:D]:
        # case 3-1 Cに先にたどり着くパターン
        S = list(S_original)
        S[C] = '#'
        S = ''.join(S)
        
        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True

        # case 3-2 Dに先にたどり着くパターン
        S = list(S_original)
        S[D] = '#'
        S = ''.join(S)
        if '##' in S[A+1:C]:
            pass
        elif '##' in S[B+1:D]:
            pass
        else:
            flag = True


    if flag == True:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

n, a, b, c, d = map(int, input().split())
s = [ s for s in input()]
a = a-1
b = b-1
s[a] = "a"
s[b] = "b"

result = True
cnt = 0

if c > d and a < b:
    while True:
        if b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
            s[b+1] = "b"
            s[b] = "."
            b += 1
        elif b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
            s[b+2] = "b"
            s[b] = "."
            b += 2
        else:
            cnt = 1
        if b+1 >= n:
            resut = False
            break
        elif s[b-1] == "." and s[b+1] == ".":
            break
        if cnt == 1:
            result = False
            break
    while a < b:
        if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
            s[a+2] = "a"
            s[a] = "."
            a += 2
        elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
            s[a+1] = "a"
            s[a] = "."
            a += 1
        else:
            reult = False
            break
if not result:
    print("NO")
    sys.exit(0)

while True:
    if a != c-1:
        if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
            s[a+2] = "a"
            s[a] = "."
            a += 2
        elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
            s[a+1] = "a"
            s[a] = "."
            a += 1
        else:
            cnt += 1
    if b != d-1:
        if b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
            s[b+2] = "b"
            s[b] = "."
            b += 2
        elif b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
            s[b+1] = "b"
            s[b] = "."
            b += 1
        else:
            cnt += 1
    if cnt == 2:
        result = False
        break
    if a == c-1 and b == d-1:
        break
if result:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
if c<d:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f==1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
  if f==1:print('No')
  else:print('Yes')
else:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
  if f==0:
    if s[d-2]=='#' or s[d]=='#':
      ct=0
      for i in range(b-1,d-2):
        if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
          ct=1
          break
      if ct==0:
        if s[b-2]=='#' or s[b]=='#':
          f=1
  if f==1:print('No')
  else:print('Yes')

Submission status: Wrong Answer

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

r2 = set()
r1 = {B-1}

for i, c in enumerate(S):
    if c=='.' and (i-2 in r1 or i-1 in r1):
        r1 |= {i}
print(r1)

for x in range(A-1, C):
    if S[x]=='#' : r0 = set()
    else:
        r0=r1|r2
        r0.discard(x)
        for i, c in enumerate(S):
            if i!=x and c=='.' and (i-2 in r0 or i-1 in r0):
                r0 |= {i}
                
    r2=r1
    r1=r0

out = 'YES' if D-1 in r0 else 'NO'
print(out)

Submission status: Wrong Answer

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

ans = "Yes"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(a - 1, c - 1))):
    ans = "No"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(b - 1, d - 1))):
    ans = "No"
if d < c and not any(map(lambda i: b < i + 1 < d, list(filter(lambda i: s[i - 1] == s[i] == s[i + 1] == '.', range(1, n - 1))))):
    ans = "No"
if b < c < d and not any(map(lambda i: b < i + 1 < c, list(filter(lambda i: s[i - 1] == s[i] == s[i + 1] == '.', range(1, n - 1))))):
    ans = "No"

print(ans)

Submission status: Wrong Answer

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

if c<d:
    s = list(s)
    h = s[b:d]
    for i in range(1,len(h)):
        if h[i]==h[i-1] and h[i]=="#":
            print("No")
            break
    else:
        hh = s[a:c]
        for i in range(1,len(hh)):
            if hh[i]==hh[i-1] and hh[i]=="#":
                print("No")
                break
        else:
            print("Yes")
else:
    if "..." in s[a:d]:
        h = s[a:c]
        for i in range(1,len(h)):
            if h[i]==h[i-1] and h[i]=="#":
                print("No")
                break
        else:
            hh = s[b:d]
            for i in range(1,len(hh)):
                if hh[i]==hh[i-1] and hh[i]=="#":
                    print("No")
                    break
            else:
                print("Yes")
    else:
        s = list(s)
        h = s[b:d]
        for i in range(1,len(h)):
            if h[i]==h[i-1] and h[i]=="#":
                print("No")
                break
        else:
            if s[d-2]=="#" or s[d]=="#":
                print("No")
            else:
                print("Yes")

Submission status: Wrong Answer

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

def not_double_stone(way):
    already=False
    for i in way:
        if i=="#" and already:
            return False
        elif i=="#":
            already=True
        else:
            already=False
    return True

def can_over(way):
    count=0
    for i in way:
        if i==".":
            count+=1
        else:
            count=0
        if count==3:
            return True
    return False

if c<d:
    if not_double_stone(way[b-1:d]):
        answer='Yes'
    else:
        answer='No'
else:
    if can_over(way[a-1:c]):
        if not_double_stone(way[a-1:c]):
            answer='Yes'
        else:
            answer='No'
    else:
        if not_double_stone(way[a-1:c]) and way[d-2]!="#" and way[d]!="#":
            answer='Yes'
        else:
            answer='No'

print(answer)

Submission status: Wrong Answer

Solution code:
# A問題
N, A, B, C, D = map(int, input().split())
S = input()
flag = False
S = S[A-1:]

if C < D:   # AがBを飛び越えない時
    if S.count("##") > 0:
        if S[A-1:C-1].count("##") > 0 or S[B-1:D-1].count("##") > 0:
            flag = False
        else:
            flag = True
    else:
        flag = True
else:   # AがBを飛び越えるとき
    S = S[:C]
    if S.count("##") > 0:   
        flag = False
    else:
        if S.count("...") > 0:
            if S[B] == ".":
                flag = True
            if S[B] == "#":
                if S[B:].count("...") > 0:
                    flag = True
                else:
                    flag = False
            else:
                flag = True
        else:
            if S[D] == "#" or S[D-2] == "#":
                flag = False
            else:
                flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

#C<Dのとき　AはBを抜かなくて良い
if C < D:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1:
        print('Yes')
    else:
        print('No')
        
#C>Dのとき　AはBを抜かなければならない
else:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1 and ''.join(S[B-2:D+1]).find('...') > 0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

a, b, c, d = a - 1, b - 1, c - 1, d - 1

if s.find('##', b, d + 1) != -1 or s.find('##', a, c + 1) != -1:
    ans = 'No'
elif c < d:
    ans = 'Yes'
elif s[d - 1] == '.' and s[d + 1] != '#':
    ans = 'Yes'
elif s.find('..', b + 1, d) != -1:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
A -= 1
B -= 1
C -= 1
D -= 1
ans = True
if C < B:
    # A ~ C に行けるか
    # B ~ D に行けるか
    count_x = 0
    ans = True
    for i in range(A, C):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
    if ans:
        count_x = 0
        for i in range(B, D):
            if S[i] == "#":
                count_x += 1
            else:
                count_x = 0
            if count_x > 1:
                ans = False
                break
elif C < D:
    # B ~ D に行けるか
    # A ~ C に行けるか
    count_x = 0
    ans = True
    for i in range(A, D):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
else:
    # A ~ Cに行けるか
    # AがBを超えれるか
    # (B~Dに3つ以上の連続空きがある)
    count_x = 0
    ans = True
    for i in range(A, C):
        if S[i] == "#":
            count_x += 1
        else:
            count_x = 0
        if count_x > 1:
            ans = False
            break
    if ans:
        count_o = 0
        ans = False
        for i in range(B, D+2):
            if S[i] == "#":
                count_o = 0
            else:
                count_o += 1
            if count_o > 2:
                ans = True
                break
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

sunuke = ""
hunuke = ""


if C > D:
    k = ''.join(s[B-1:D])
    result = "..." in k
    if result == 0:
        print("No")
        exit()

while B <= D:
    if s[B] == ".":
        B += 1
        if B == D:
            hunuke = "ok"
            break
    elif s[B+1] == ".":
        B += 2
        if B == D:
            hunuke = "ok"
            break
    else:
        print("No")
        exit()

while A <= C:
    if s[A] == ".":
        A += 1
        if A == C:
            sunuke = "ok"
            break
    elif s[A+1] == ".":
        A += 2
        if A == C:
            sunuke = "ok"
            break
        elif A > C:
            print("No")
            exit()
    else:
        print("No")
        exit()

if sunuke == "ok" and hunuke == "ok":
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

if "##" in s[A-1:max(C,D)]:
  print("No")
  quit()
st,e=0,0
for spl in s.split("##"):
  e += (len(spl)+2)
  if st <A<max(C,D)<=e:
    break
  st+= (len(spl)+2)

if "..." in s[st:e]:
  print("Yes")
elif D<C or C<B:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

Sa = S[A:C]
Sb = S[B:D]

#if S.find('##')>=0 and A<S.find('ABC')<C or B<S.find('ABC')<D:
if Sa.find('##')>=0 or Sb.find('##')>=0:
    ans = "No"

if A<B<D<C and not '...' in S:
    ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
obs = [S[i] is "#" and S[i+1] is "#" for i in range(0,max(C,D)-1)]
space = [S[i] is "." and S[i+1] is "." and S[i+2] is "." for i in range(0,max(C,D)-2)]
if C < D:
  if True in obs[B:D] or True in obs[A:C]:
    print("No")
  else:
    print("Yes")
else:
  if True not in space[B-1:D]:
    print("No")
  elif True in obs[B:D-1] or True in obs[A:C-1]:
    print("No")
  else:
    print("Yes")
    
    
print(space)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)

ans = 0

cb_cnt = 0
state = 0
# state 0 = なんにもない状態
for i in range(n)[::-1]:
    # なんでもない状態→Cの状態のみに以降
    if state == 0:
        if s[i] == "C":
            cb_cnt = 1
            state = 1
            continue
    # Cが入ってきている時→CBの状態のみに移行
    elif state == 1:
        if s[i] == "B":
            state = 2
            continue
        elif s[i] == "C":
            cb_cnt = 1
            continue
    # CBCB ... Bのとき
    elif state == 2:
        if s[i] == "C":
            cb_cnt += 1
            state = 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            state = 3
            continue
    # CBCB...A になったとき
    elif state == 3:
        if s[i] == "C":
            state = 1
            cb_cnt += 1
            continue
        elif s[i] == "A":
            ans += cb_cnt
            continue
    cb_cnt = 0
    state = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
s = input()
if C<D:
    ans = 'Yes'
else:
    if s[B-2:D].count('...')>0:
        ans = 'Yes'
        if D-B == 1:
            ans = 'No'
        elif D-B == 2 and s[B-2]!= '#' and s[D]!= '#':
            ans = 'No'
    else:
        ans = 'No'
if s[A:C-2].count('##')!=0 or s[B:D-2].count('##')!=0:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s="*"+input()+"*"
ruiwa=[0 for i in range(n+1)]
ruidot=[0 for i in range(n+1)]

wa=0
for i in range(n+1):
  if s[i]=="#":
    wa+=1
    ruiwa[i]=wa
  else:
    wa=0
    
wa=0
for i in range(n+1):
  if s[i]==".":
    wa+=1
    ruidot[i]=wa
  else:
    wa=0
    
ans=""

for i in range(a,n):
  if ruiwa[i]>1:
    ans="No"
    break

for i in range(b,n):
  if ruiwa[i]>1:
    ans="No"
    break

if ans=="":
  if s[d-1]=="#" or s[d+1]=="#":
    if a<b:
      for i in range(b,n+1):
        if ruidot[i]==3:
          ans="Yes"
          break
      if ans=="":
        ans="No"
  if s[c-1]=="#" or s[c+1]=="#":
    if b<a:
      for i in range(a,n+1):
        if ruidot[i]==3:
          ans="Yes"
          break
      if ans=="":
        ans="No"          
if ans=="":
  ans="Yes"
  
print(ans)

Submission status: Wrong Answer

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

m = max([c, d])
if n>m:
    n = m
    s = s[:n]
    
if '##' in s:
    print('No')
else:
    if c>d:
        if '...' in s[:d]:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')