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: Runtime Error

Solution code:
def available(start, end, S, step=None):
    if step is not None:    #   追い越し処理
        S = S[:step] + "#" + S[step+1:]
    for i in range(start-1, end-1):
        if S[i] == "#" and S[i+1] == "#":
            return False
    return True, S
    
def overtake(start, end, S):
    for i in range(start-1, end-1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            step = i
            return True, step
    return False, None

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

if D > C:   #   追い越しが不要な時
    judge1, S = available(A, C, S)
    judge2, S = available(B, D, S)
    if judge1 and judge2:
        print("Yes")
    else:
        print("No")
else:   #   追い越しが必要な時
    overtakable, step = overtake(B, D, S)
    if overtakable:   #   追い越しが可能な時
        judge1, S = available(A, C, S, step=step)
        judge2, S = available(B, D, S)
        if judge1 and judge2:
            print("Yes")
        else:
            print("No")
    else:   #   追い越しができない時
        print("No")

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
a-=1
b-=1
c-=1
d-=1
s=input()
m=[0 for i in range(n)]
#a-c,b-d
#abcd
#abdc
for i in range(n):
    if s[i]=="#":
        m[i]=1
if c<d:#abcd
    if "##" in s[a:d]:
        print("NO")
            else:
print("YES")
else:#d<c abdc
    if "##" in s[a:c]:
        print("NO")
            else:
if "..." in s[b-1:d+1]:
    print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
def has_path(start, goal):
    for step in range(start, goal):
        if (not isRoad[step]) and (not isRoad[step-1]):
            return False
    return True


N, A, B, C, D = map(int, input().split())
S = input()
isRoad = [True if c == "." else False for c in S]

if C <= B:      # すぬけ・ふぬけの二人が独立になっているとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
elif C < D:    # ふぬけを動かしてからすぬけを動かせば良いとき
    if has_path(A, C) and has_path(B, D):
        print("Yes")
    else:
        print("No")
    exit()
else:       # どこかでふぬけがすぬけを追い越さなければいけない場合
    for i in range(B - 1, D + 1):   # 追い抜く場所があるかどうかを探索
        if isRoad[i - 1] and isRoad[i] and isRoad[i + 1]:
            print("Yes")
            exit()
    print("No")

Submission status: Runtime Error

Solution code:

import sys
sys.setrecursionlimit(100000000)

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

A -= 1
B -= 1
C -= 1
D -= 1

for i in len(s):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#':
            print("No")
            exit()




def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

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

    
for i in range(len(S)):
    if S[i + 1] == ".":
        if C - A > 2:
            A+=2
        if D - B >2:
            B+=2
    if S[i] == ".":
        if C - A > 1:
            A+=1
        if D - B >1:
            B+=1
        
    if A == C and B ==D:
        print("Yes")
        break
        
    if A > N or B > N:
        print("No")
        break

    if C == D:
        print("No")
        break
else:
    print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
Start = max(A,B)
Start2 = min(A,B)
mas = max(A,B)
ans = 0
out = 0
for i in range(mas,D):
    if S[i+1] == ".":
        mas += 1
    elif S[i+2] == ".":
        mas += 2
    if mas == D:
        break
        ans += 1
        mas = 0
    else:
        print("No")
        out += 1
        break
for j in range(Start2,C):
        if S[j+1] == ".":
          mas += 1
        elif S[j+2] == ".":
         mas += 2
        if mas == C:
          break
          ans += 1
        else:
            if out == 0:
                print("No")
                break

Submission status: Runtime Error

Solution code:
N = input()
N = int(N)
N,K = (int(i) for i in input().split())
s = [[ i for i in input().split()] for i in range(N)]


N,A,B,C,D = (int(i) for i in input().split())
S = input()
S = list(S)

result = "Yes"
onon = True

if C < D:
    for i in range(len(S)-1):
        if S[i] == "#" and S[i + 1] == "#":
            result =  "No"
else:
    result = "No"
    for i in range(len(S)-1):
        if S[i] == "#" and S[i + 1] == "#":
            onon = False
    if onon:
        for i in range(B,D-2):
            if S[i] == "." and S[i + 1] == "."and S[i + 2] == ".":
                result = "Yes"


print(result)

Submission status: Runtime Error

Solution code:
print(2n-1)
print(2n+1)

Submission status: Runtime Error

Solution code:

import sys
sys.setrecursionlimit(10000)

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

A -= 1
B -= 1
C -= 1
D -= 1


def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

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

A -= 1
B -= 1
C -= 1
D -= 1


def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Submission status: Runtime Error

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

def ken(pos, dest):   
    global road
    global n

    if pos >= n:
        return False

    if road[pos] == "#":
        return False
    
    if pos == dest:
        return True

    x = ken(pos+1, dest)
    y = ken(pos+2, dest)

    return x or y

if ken(a-1, c-1) and ken(b-1, d-1):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
fun main(args: Array<String>) {
    val (n, a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    if (c < d) {
        if (f2(s, a, c) && f2(s, b, d)) {
            println("Yes")
        } else {
            println("No")
        }
    } else {
        if (f2(s, a, c) && f3(s, b, d)) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

fun f2(s: String, l: Int, r: Int): Boolean {
    var ok = true
    s.slice((l - 1)..(r - 1)).reduce { a, b -> if (a == '#' && b == '#') ok = false;b }
    return ok
}

fun f3(s: String, l: Int, r: Int): Boolean {
    for (i in (l - 1)..(r - 3)) {
        if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') return true
    }
    return false
}

Submission status: Runtime Error

Solution code:
temp = input().split("\n")
N, A, B, C, D = [int(x) for x in temp[0].split()]
flag = True
before = -1

for x, xi in enumerate(temp[1]):
    if x<A:
        continue
    if xi==".":
        continue
    else:
        if x-before==1:
            flag = False
            break
        else:
            before = x
            
if flag:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D=list(map(int,input().split()))
S=input()
bS=S[B-1:D-1]
a=True
if C<D:
    if "##" in bS:
        a=False
    else:
        S=S[:D-1]+"#"+S[D-1:]
        aS=S[A-1:C-1]
        if "##" in aS:
            a=False

else:
    if "##" in bS:
        a=False
    else:
        aS=S[A-1:C-1]
        if "##" in aS:
            a=False
        else:
            if (not "..." in bS) and (aS[D]=="#" or aS[D-2]=="#"):
                a=False
            
        
        
if a:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,a,b,c,d = f()
    s = input()

    has_2_consecu = 0
    for i in range(a+1, max(c,d)-1):
        if s[i]=='#' and s[i+1] == '#':
            has_2_consecu = 1
            break



    if has_2_consecu:
        print('No')
        return

    if d>c:
        print('Yes')
        return
    else:
        has_3_consecu = 0
        for i in range(b+1, d):
            if s[i]=='.' and s[i+1] == '.' and s[i+2]=='.':
                has_3_consecu = 1
                break
        
        if has_3_consecu:
            print('Yes')
            return
    
    print('No')




solve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


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

    for i in range(a - 1, c):
        if s[i + 1] == s[i] == '#':
            print('No')
            return

    for i in range(b - 1, d):
        if s[i + 1] == s[i] == '#':
            print('No')
            return

    if d > c:
        print('Yes')
        return

    for i in range(b - 1, d):
        if s[i - 1] == s[i] == s[i + 1] == '.':
            print('Yes')
            return

    print('No')
    return


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

A -= 1
B -= 1
C -= 1
D -= 1

def check2():
	for i in range(A, C - 1):
		if S[i] == S[i + 1] == "#":
			return False
	
	if D < C:
		for i in range(B, D):
			if S[i - 1] == S[i] == S[i + 1] == ".":
				return True
		return False
	else:
		return True

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

Submission status: Runtime Error

Solution code:
n,a,b,c,d=list(map(int,input().split()))
s=input().rstrip()
vis=[False]*(n+1)
i=a-1
flag=1
s=[i for i in s]
#check for b
i=b-1
while(i<d):
    if i==d-1:
        break
    elif s[i+2]=='.':
        i+=2
    elif s[i+1]=='.':
        i+=1
    else:
        break
if i==d-1:
    pass
else:
    print('No')
    exit()
i=a-1
while(i<c):
    if i==c-1:
        break
    elif  s[i+2]=='.':
        i+=2
    elif  s[i+1]=='.':
        i+=1
    else:
        break
if i==c-1:
    pass
else:
    print('No')
    exit()
if d==c:
    print('No')
    exit()
print('Yes')

Submission status: Runtime Error

Solution code:
# 1.A_C間,B_D間に##となっているマスがないこと
# 2.D>CまたはDの周辺に#がないまたはB_D間に...があること
n, a, b, c, d = map(int, input().split())
s = " " + input()
Triple_floor = False
Triple_floor = False
before_stat = ""
floor_num = 0
counter = a+1
for char in s[a+1:]:
    if(counter > c and counter > d):
        # この先はどうでもいい.
        break
    if(char == "."):
        floor_num += 1
        if(floor_num >= 3 and counter > (b+1) and counter <= (d+1)):
            Triple_floor = True
    else:
        floor_num = 0
        if(before_stat == "#"):
            print("No")
            exit(1)
    before_stat = char
    counter += 1
if(c<d or Triple_floor):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
N, A, B, C, D = [int(x) for x in input().split()]
S = [x for x in input()]

if not (A < B < D and A < C):
    print("制約違反")

A -= 1
B -= 1
C -= 1
D -= 1

# 深さ優先探索プログラム
def move(pos, target):
    if pos == target:
        return True
    if pos+1 < N and S[pos+1] == ".":
        r = move(pos+1, target)
        if r != None:
            return r
    if pos+2 < N and S[pos+2] == ".":
        r = move(pos+2, target)
        if r != None:
            return r
    return False

# B側移動
if not move(B, D):
    print("No")
    sys.exit(0)

# A側移動
if not move(A, C):
    print("No")
    sys.exit(0)

print("Yes")

Submission status: Runtime Error

Solution code:
def possible(i, j, k, l):
	if i > k or j > l:
		return 0
	if s[i] == '#' or s[j] == '#' or i == j:
		return 0
	if i == k and j == l:
		return 1
	res = possible(i + 1, j, k, l)
	res |= possible(i + 2, j, k, l)
	res |= possible(i, j + 1, k, l)
	res |= possible(i, j + 2, k, l)
	return res
n, a, b, c, d = map(int, raw_input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = list(raw_input())
if possible(a, b, c, d):
	print "Yes"
else:
	print "No"

Submission status: Runtime Error

Solution code:
import sys
N, A, B, C, D = [int(x) for x in input().split()]
S = [x for x in input()]

if not (A < B < D and A < C):
    print("制約違反")

A -= 1
B -= 1
C -= 1
D -= 1

# 深さ優先探索プログラム
def move(pos, target):
    if pos == target:
        return True
    if S[pos+1] == ".":
        r = move(pos+1)
        if r != None:
            return r
    if S[pos+2] == ".":
        r = move(pos+1)
        if r != None:
            return r
    return False

# B側移動
if not move(B, D):
    print("No")
    sys.exit(0)

# A側移動
if not move(A, C):
    print("No")
    sys.exit(0)

print("Yes")

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b,c,d = LI()
    s = input()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    if c == d:
        print("No")
    else:
        if c < d:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            print("Yes")
        else:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == k[i+2] == ".":
                    print("Yes")
                    quit()
            print("No")
    return

#B
def B():
    s = S()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    n,a,b,c,d = LI_()
    n += 1
    s = S()
    if d < c:
        f = 0
        for i in range(max(0,b-1), min(min(n-1,d+1)), c-1):
            if s[i:i+3] == '...':
                f = 1
                break
        if f == 0:
            return 'No'

    for i in range(a+1,c-1):
        if s[i:i+2] == '##':
            return 'No'
    for i in range(b+1,d-1):
        if s[i:i+2] == '##':
            return 'No'


    return 'Yes'


print(main())

Submission status: Runtime Error

Solution code:
abc