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 -*-

import sys


def solve(N, A, B, C, D, S):
    p_A = set([A])
    for p, n1, n2 in zip(range(A, C-1), S[A+1:], S[A+2:]):
        if p in p_A:
            if n1 == '.' and p+1:
                p_A.add(p+1)
            if n2 == '.' and p+2:
                p_A.add(p+2)

    p_B = set([B])
    for p, n1, n2 in zip(range(B, D-1), S[B+1:], S[B+2:]):
        if p in p_B:
            if n1 == '.' and p+1:
                p_B.add(p+1)
            if n2 == '.' and p+2:
                p_B.add(p+2)

    p_t = set()
    for p, p1, p2, p3 in zip(range(B, N+1), S[B:D+1], S[B+1:], S[B+2:]):
        if p1 == '.' and p2 == '.' and p3 == '.':
            p_t.add(p+1)

    if C < D:
        if C in p_A and D in p_B:
            return 'Yes'
        return 'No'
    else:
        if (C in p_A) and (D in p_B) and (p_A & p_t) and (p_B & p_t):
            return 'Yes'
        return 'No'


def main(args):
    N, A, B, C, D = map(int, input().split())
    S = input()
    S = '#' + S + '##'
    ans = solve(N, A, B, C, D, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

import sys


def solve(N, A, B, C, D, S):
    p_A = set([A])
    for p, n1, n2 in zip(range(A, C-1), S[A+1:], S[A+2:]):
        if p in p_A:
            if n1 == '.' and p+1:
                p_A.add(p+1)
            if n2 == '.' and p+2:
                p_A.add(p+2)

    p_B = set([B])
    for p, n1, n2 in zip(range(B, D-1), S[B+1:], S[B+2:]):
        if p in p_B:
            if n1 == '.' and p+1:
                p_B.add(p+1)
            if n2 == '.' and p+2:
                p_B.add(p+2)

    p_t = set()
    for p, p1, p2, p3 in zip(range(B, N+1), S[B:D+1], S[B+1:], S[B+2:]):
        if p1 == '.' and p2 == '.' and p3 == '.':
            p_t.add(p+1)

    if C < D:
        if C in p_A and D in p_B:
            return 'Yes'
        return 'No'
    else:
        if (C in p_A) and (D in p_B) and (p_B & p_t):
            return 'Yes'
        return 'No'


def main(args):
    N, A, B, C, D = map(int, input().split())
    S = input()
    S = '#' + S + '##'
    ans = solve(N, A, B, C, D, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

import sys


def solve(N, A, B, C, D, S):
    p_A = set([A])
    for p, n1, n2 in zip(range(A, C), S[A+1:], S[A+2:]):
        if p in p_A:
            if n1 == '.' and p+1 <= C:
                p_A.add(p+1)
            if n2 == '.' and p+2 <= C:
                p_A.add(p+2)

    p_B = set([B])
    for p, n1, n2 in zip(range(B, D), S[B+1:], S[B+2:]):
        if p in p_B:
            if n1 == '.' and p+1 <= D:
                p_B.add(p+1)
            if n2 == '.' and p+2 <= D:
                p_B.add(p+2)

    p_t = set()
    for p, p1, p2, p3 in zip(range(B, N+1), S[B-1:D], S[B:D+1], S[B+1:]):
        if p1 == '.' and p2 == '.' and p3 == '.' and p <= D:
            p_t.add(p)

    if C < D:
        if C in p_A and D in p_B:
            return 'Yes'
        return 'No'
    else:
        if (C in p_A) and (D in p_B) and (p_B & p_t):
            return 'Yes'
        return 'No'


def main(args):
    N, A, B, C, D = map(int, input().split())
    S = input()
    S = '#' + S + '##'
    ans = solve(N, A, B, C, D, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Verdicts: Wrong Answer

Wrong Answer

Accepted