Problem: There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty.  In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.  You can repeat the following operation any number of times:    * Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.  You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.  Determine whether this is possible.

Submission attempts (in order):
# -*- coding: utf-8 -*-

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

A -= 1
B -= 1
C -= 1
D -= 1
S[A] = 'a'
S[B] = 'b'

ans_D = False
ans_C = False

b = B
a = A

if C <= D:
    while True:
        if b == D:
            ans_D = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if ans_D:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
    if ans_C and ans_D:
        print('YES')
    else:
        print('No')
else:
    swap_flag = False
    while b + 1 < N:
        if (S[b-1] == '.' and S[b+1] == '.') or (S[b-1] == 'a' and S[b+1] == '.'):
            swap_flag = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if swap_flag:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
        if ans_C:
            while True:
                if b == D:
                    ans_D = True
                    break
                else:
                    if S[b+1] == '.':
                        S[b] = '.'
                        S[b+1] = 'b'
                        b += 1
                    else:
                        if S[b+2] == '.':
                            S[b] = '.'
                            S[b+2] = 'b'
                            b += 2
                        else:
                            break
            if ans_C and ans_D:
                print('YES')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')


# -*- coding: utf-8 -*-
N,A,B,C,D = map(int, input().split())
S = list(input())

A -= 1
B -= 1
C -= 1
D -= 1
S[A] = 'a'
S[B] = 'b'

ans_D = False
ans_C = False

b = B
a = A

if C <= D:
    while True:
        if b == D:
            ans_D = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if ans_D:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
    if ans_C and ans_D:
        print('YES')
    else:
        print('No')
else:
    swap_flag = False
    while b + 1 < N:
        if S[b-1] == '.' and S[b+1] == '.':
            swap_flag = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if swap_flag:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
        if ans_C:
            while True:
                if b == D:
                    ans_D = True
                    break
                else:
                    if S[b+1] == '.':
                        S[b] = '.'
                        S[b+1] = 'b'
                        b += 1
                    else:
                        if S[b+2] == '.':
                            S[b] = '.'
                            S[b+2] = 'b'
                            b += 2
                        else:
                            break
            if ans_C and ans_D:
                print('YES')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

# -*- coding: utf-8 -*-

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

A -= 1
B -= 1
C -= 1
D -= 1
S[A] = 'a'
S[B] = 'b'

ans_D = False
ans_C = False

b = B
a = A

if C <= D:
    while True:
        if b == D:
            ans_D = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if ans_D:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
    if ans_C and ans_D:
        print('Yes')
    else:
        print('No')
else:
    swap_flag = False
    while b + 1 < N:
        if (S[b-1] == '.' and S[b+1] == '.') or (S[b-1] == 'a' and S[b+1] == '.'):
            swap_flag = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if swap_flag:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
        if ans_C:
            while True:
                if b == D:
                    ans_D = True
                    break
                else:
                    if S[b+1] == '.':
                        S[b] = '.'
                        S[b+1] = 'b'
                        b += 1
                    else:
                        if S[b+2] == '.':
                            S[b] = '.'
                            S[b+2] = 'b'
                            b += 2
                        else:
                            break
            if ans_C and ans_D:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')


Verdicts: Wrong Answer

Wrong Answer

Accepted