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):
N,A,B,C,D = map(int,input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
if (A < B < D < C):
    cnt = 0
    cntl = [0]
    for i in range(A+1,C):
        if (S[i] == '.') & (S[i+1] == '.'):
            cnt += 1
            if i == C-1:
                cntl.append(cnt)
        elif (S[i] == '.') & (S[i+1] == '#'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) < 2:
        print('No')
    else:
        cnt = 0
        cntL = [0]
        for i in range(B+1,D-1):
            if (S[i] == '#') & (S[i+1] == '#'):
                cnt += 1
                if i == C-1:
                    cntL.append(cnt)
            elif (S[i] == '#') & (S[i+1] == '.'):
                cntL.append(cnt)
                cnt = 0
        if max(cntL) >= 1:
            print('No')
        else:
            if (S[D+1] == '.')&(S[D-1] == '.'):
                if (S[B+1] == '.')&(S[B-1] == '.'):
                    print('Yes')
                else:
                    x = 0
                    xl = [0]
                    for i in range(B+1,D-1):
                        if (S[i] == '.') & (S[i+1] == '.'):
                            x += 1
                            if x == D-2:
                                xl.append(x)
                        elif (S[i] == '.') & (S[i+1] == '#'):
                            xl.append(x)
                    if max(xl) >= 2:
                        print('Yes')
                    else:
                        print('No')
            elif S[D-1] == '#':
                x = 0
                xl = [0]
                for i in range(B-1,D-2):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                        if i == D-3:
                            xl.append(x)
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('Yes')
                else:
                    print('No')
            else:
                x = 0
                xl = [0]
                for i in range(B-1,D-1):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                        if x == D-2:
                            xl.append(x)
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('Yes')
                else:
                    print('No')
else:
    cnt = 0
    cntl = [0]
    for i in range(A+1,C):
        if (S[i] == '#') & (S[i+1] == '#'):
            cnt += 1
            if i == C-1:
                cntl.append(cnt)
        elif (S[i] == '#') & (S[i+1] == '.'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) >= 1:
        print('No')
    else:
        if (S[B+1] == '.')&(S[B-1] == '.'):
                print('Yes')
        else:
            x = 0
            xl = [0]
            for i in range(B+1,D-1):
                if (S[i] == '.') & (S[i+1] == '.'):
                    x += 1
                    if x == D-2:
                        xl.append(x)
                elif (S[i] == '.') & (S[i+1] == '#'):
                    xl.append(x)
            if max(xl) >= 2:
                print('Yes')
            else:
                print('No')

N,A,B,C,D = map(int,input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
if (A < B < D < C):
    cnt = 0
    cntl = []
    for i in range(A+1,C-1):
        if (S[i] == '.') & (S[i+1] == '.'):
            cnt += 1
        elif (S[i] == '.') & (S[i+1] == '#'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) < 2:
        print('NO')
    else:
        cnt = 0
        cntL = []
        for i in range(B+1,D-1):
            if (S[i] == '#') & (S[i+1] == '#'):
                cnt += 1
            elif (S[i] == '#') & (S[i+1] == '.'):
                cntL.append(cnt)
                cnt = 0
        if max(cntL) >= 1:
            print('NO')
        else:
            if (S[D+1] == '.')&(S[D-1] == '.'):
                print('YES')
            elif S[D-1] == '#':
                x = 0
                xl = []
                for i in range(B-1,D-2):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('YES')
                else:
                    print('NO')
            else:
                x = 0
                xl = []
                for i in range(B-1,D-1):
                    if (S[i] == '.') & (S[i+1] == '.'):
                        x += 1
                    elif (S[i] == '.') & (S[i+1] == '#'):
                        xl.append(x)
                if max(xl) >= 2:
                    print('YES')
                else:
                    print('NO')
else:
    cnt = 0
    cntl = []
    for i in range(A+1,C-1):
        if (S[i] == '#') & (S[i+1] == '#'):
            cnt += 1
        elif (S[i] == '#') & (S[i+1] == '.'):
            cntl.append(cnt)
            cnt = 0
    if max(cntl) >= 1:
        print('NO')
    else:
        print('YES')

N,A,B,C,D = map(int,input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
if D < C:
    sl = [0]
    ml = [0]
    cnt = 0
    mcnt = 0
    for i in range(A+1,B-1):
        if [S[i],S[i+1]] == ['#','#']:
            cnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            sl.append(cnt)
            cnt = 0
        if i == B-2 :
            sl.append(cnt)
            cnt = 0
    for i in range(D+1,C):
        if [S[i],S[i+1]] == ['#','#']:
            cnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            sl.append(cnt)
            cnt = 0
        if i == C-1 :
            sl.append(cnt)
    for i in range(B-1,D+1):
        if [S[i],S[i+1]] == ['.','.']:
            mcnt += 1
        elif [S[i],S[i+1]] == ['.','#']:
            ml.append(mcnt)
            mcnt = 0
        if i == D:
            ml.append(mcnt)
            mcnt = 0
    if max(sl) >= 1:
        print('No')
    elif max(ml) <= 1:
        print('No')
    else:
        print('Yes')
else:
    acnt = 0
    bcnt = 0
    al = [0]
    bl = [0]
    for i in range(A+1,C):
        if [S[i],S[i+1]] == ['#','#']:
            acnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            al.append(acnt)
            acnt = 0
        if i == C-1 :
            al.append(acnt)
            acnt = 0
    for i in range(B+1,D):
        if [S[i],S[i+1]] == ['#','#']:
            bcnt += 1
        elif [S[i],S[i+1]] == ['#','.']:
            bl.append(bcnt)
            bcnt = 0
        if i == C-1 :
            bl.append(bcnt)
            bcnt = 0
    if max(al) >= 1:
        print('No')
    elif max(bl) >= 1:
        print('No')
    else:
        print('Yes')

Verdicts: Wrong Answer

Wrong Answer

Accepted