Problem:


Score : 600 points

Problem Statement

We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.
On this grid, there is a piece, which is initially placed at square (s_r,s_c).

Takahashi and Aoki will play a game, where each player has a string of length N.
Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: L, R, U and D.

The game consists of N steps. The i-th step proceeds as follows:

First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.

Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.

Here, to move the piece in the direction of L, R, U and D, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done.

Takahashi wants to remove the piece from the grid in one of the N steps.
Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid.
Determine if the piece will remain on the grid at the end of the game when both players play optimally.

Constraints

2 \leq H,W \leq 2 \times 10^5

2 \leq N \leq 2 \times 10^5

1 \leq s_r \leq H

1 \leq s_c \leq W

|S|=|T|=N

S and T consists of the four kinds of letters L, R, U and D.

Input

Input is given from Standard Input in the following format:

H W N
s_r s_c
S
T

Output

If the piece will remain on the grid at the end of the game, print YES; otherwise, print NO.

Sample Input 1

2 3 3
2 2
RRL
LUD

Sample Output 1

YES

Here is one possible progress of the game:

Takahashi moves the piece right. The piece is now at (2,3).

Aoki moves the piece left. The piece is now at (2,2).

Takahashi does not move the piece. The piece remains at (2,2).

Aoki moves the piece up. The piece is now at (1,2).

Takahashi moves the piece left. The piece is now at (1,1).

Aoki does not move the piece. The piece remains at (1,1).

Sample Input 2

4 3 5
2 2
UDRRR
LLDUD

Sample Output 2

NO

Sample Input 3

5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD

Sample Output 3

NO



Sample input:
2 3 3
2 2
RRL
LUD


Sample output:
YES

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,direction_op,cs,flg,seq1,seq2):

    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<=0 or cs>N:
            return False
        if s2==direction_op:
            cs-=flg
        
        if cs <= 0 or cs > N:
            return False
            
    return cs



sr=position_relative("R","L",initp[0],1,S,T)
sl = position_relative("L","R",initp[0],-1,S,T)

su = position_relative("U","D",initp[1],-1,S, T)
sd = position_relative("D","U",initp[1],1, S, T)

#print(sr,sl,su,sd)

#if sr or sl or su or sd:
if (sr and sl and su and sd):
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,cs,flg,seq1,seq2):

    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<=0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg
        
        if cs <= 0 or cs > N:
            return False
            
    return cs



sr=position_relative("R",initp[0],1,S,T)
sl = position_relative("L",initp[0],-1,S,T)

su = position_relative("U",initp[1],-1,S, T)
sd = position_relative("D", initp[1],1, S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,flg,seq1,seq2):
    cs = 0
    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<=0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg
        
        if cs < 0 or cs > N:
            return False
            
    return cs




sr=position_relative("R",initp[0],S,T)
sl = position_relative("L",initp[0],S,T)

su = position_relative("U",initp[1],S, T)
sd = position_relative("D", initp[1], S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,flg,seq1,seq2):
    cs = 0
    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<=0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg
        
        if cs < 0 or cs > N:
            return False
            
    return cs




sr=position_relative("R",initp[0],S,T)
sl = position_relative("L",initp[1],S,T)

su = position_relative("U",-1,S, T)
sd = position_relative("D",1, S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,flg,seq1,seq2):
    cs = 0
    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg
        
        if cs < 0 or cs > N:
            return False
            
    return cs




sr=position_relative("R",initp[0],S,T)
sl = position_relative("L",initp[1],S,T)

su = position_relative("U",-1,S, T)
sd = position_relative("D",1, S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

l, r = 1, W
if S[-1] == 'L':
    l += 1
if S[-1] == 'R':
    r -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'L':
        r += 1
    if T[i] == 'R':
        l -= 1

    if S[i] == 'L':
        l += 1
    if S[i] == 'R':
        r -= 1

    if l > r:
        print('NO')
        exit()

u, d = 1, H
if S[-1] == 'U':
    u += 1
if S[-1] == 'D':
    d -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'U':
        d += 1
    if T[i] == 'D':
        u -= 1

    if S[i] == 'U':
        u += 1
    if S[i] == 'D':
        d -= 1

    if u > d:
        print('NO')
        exit()

if l <= sc <= r and u <= sr <= d:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

l, r = 1, W
if S[-1] == 'L':
    l += 1
if S[-1] == 'R':
    r -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'L':
        r = min(r+1, W)
    if T[i] == 'R':
        l = max(l-1, 1)

    if S[i] == 'L':
        l += 1
    if S[i] == 'R':
        r -= 1
    if l > r:
        print('NO')
        exit()

u, d = 1, H
if S[-1] == 'U':
    u += 1
if S[-1] == 'D':
    d -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'U':
        d = min(d+1, W)
    if T[i] == 'D':
        u = max(u-1, 1)

    if S[i] == 'U':
        u += 1
    if S[i] == 'D':
        d -= 1

    if u > d:
        print('NO')
        exit()

if l <= sc <= r and u <= sr <= d:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

l, r = 1, W
if S[-1] == 'L':
    l += 1
if S[-1] == 'R':
    r -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'L':
        r = min(r+1, W)
    if T[i] == 'R':
        l = max(l-1, 1)

    if S[i] == 'L':
        l += 1
    if S[i] == 'R':
        r -= 1
    if l > r:
        print('NO')
        exit()

u, d = 1, H
if S[-1] == 'U':
    u += 1
if S[-1] == 'D':
    d -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'U':
        d = min(d+1, W)
    if T[i] == 'D':
        u = max(u-1, 1)

    if S[i] == 'U':
        d -= 1
    if S[i] == 'D':
        u += 1

    if u > d:
        print('NO')
        exit()

if l <= sc <= r and u <= sr <= d:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

# left
x = sc
for i in range(N):
    if S[i] == 'L':
        x -= 1
    if x < 1:
        print('NO')
        exit()
    if T[i] == 'R' and x < W:
        x += 1
# right
x = sc
for i in range(N):
    if S[i] == 'R':
        x += 1
    if x > W:
        print('NO')
        exit()
    if T[i] == 'L' and x > 1:
        x -= 1
# top
y = sr
for i in range(N):
    if S[i] == 'U':
        y -= 1
    if y < 1:
        print('NO')
        exit()
    if T[i] == 'D' and y < H:
        y += 1
# bottom
y = sr
for i in range(N):
    if S[i] == 'D':
        y += 1
    if y > H:
        print('NO')
        exit()
    if T[i] == 'D' and y > 1:
        y -= 1
print('YES')

Submission status: Wrong Answer

Solution code:
h,w,n=map(int,input().split())
sr,sc=map(int,input().split())
s=input()[::-1]
t=input()[::-1]
limit=[0,h-1,0,w-1]
direction={"D":0,"U":1,"L":2,"R":3}
for i in range(2*n-1):
    if not i%2:
        #Takahashi's turn
        see=i//2
        limit[direction[s[see]]]+=(-1)**(direction[s[see]])
        #print(s[see],limit,"TAKAHASHI")
    else:
        #Aoki's turn
        see=i//2+1
        if t[see]=="U":
            limit[0]=max(0,limit[0]-1)
        elif t[see]=="D":
            limit[1]=min(h-1,limit[1]+1)
        elif t[see]=="R":
            limit[2]=max(0,limit[2]-1)
        elif t[see]=="L":
            limit[3]=min(w-1,limit[3]+1)
        #print(t[see],limit,"AOKI")
    if limit[0]>limit[1] or limit[2]>limit[3]:print("NO");exit()
if limit[0]<=sr-1 and limit[1]>=sr-1 and limit[2]<=sc-1 and limit[3]>=sc-1:print("YES")
else:print("NO")

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    H,W,N = map(int, input().split())
    start = tuple(map(int, input().split()))
    S = input().rstrip()
    T = input().rstrip()
    D = {
        'R': (0,1),
        'L': (0,-1),
        'U': (-1,0),
        'D': (1,0)
    }
    Dc = ['R', 'L', 'U', 'D']

    def move(current, direction):
        d = D[direction]
        return (current[0]+d[0], current[1]+d[1])

    def check(a):
        return 1<=a[0]<=H and 1<=a[1]<=W

    ans = False
    cur = start
    for i in range(4):
        for j in range(N):
            if S[j] == Dc[i]:
                cur = move(cur, Dc[i])
                if not check(cur): ans = True
            if T[j] == Dc[i^1]:
                cur = move(cur, Dc[i^1])
                if not check(cur): cur = move(cur, Dc[i])
    print('NO' if ans else 'YES')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w,n=map(int,input().split())
sr,sc=map(int,input().split())
s=input()[::-1]
t=input()[::-1]
limit=[0,h-1,0,w-1]
direction={"D":0,"U":1,"L":2,"R":3}
for i in range(2*n-1):
    if not i%2:
        #Takahashi's turn
        see=i//2
        limit[direction[s[see]]]+=(-1)**(direction[s[see]])
        #print(s[see],limit)
    else:
        #Aoki's turn
        see=i//2+1
        if t[see]=="U":
            limit[0]=max(0,limit[0]-1)
        elif t[see]=="D":
            limit[1]=min(h-1,limit[1]+1)
        elif t[see]=="R":
            limit[2]=min(0,limit[2]-1)
        elif t[see]=="L":
            limit[3]=max(w-1,limit[3]+1)
        #print(t[see],limit)
    if limit[0]<=-1 or limit[2]<=-1 or limit[1]>=h or limit[3]>=w or limit[0]>limit[1] or limit[2]>limit[3]:print("NO");exit()
if limit[0]<=sr-1 and limit[1]>=sr-1 and limit[2]<=sc-1 and limit[3]>=sc-1:print("YES")
else:print("NO")
#print(limit)

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = list(input())
T = list(input())

# 青木くんが左に動かせるということは、駒の生存可能範囲の右端を1つのばせる
# 高橋くんが左に動かせるということは、駒の生存可能範囲の左端を1つ縮める
l = 1
r = W
u = 1
d = H
for s, t in zip(S[::-1], T[::-1]):
    if t in ('L', 'R'):
        if t == 'L':
            r = min(r + 1, W)
        else:
            l = max(1, l - 1)
    else:
        if t == 'U':
            d = max(d + 1, H)
        else:
            u = min(u - 1, 1)

    if s in ('L', 'R'):
        if s == 'L':
            l += 1
        else:
            r -= 1
    else:
        if s == 'U':
            u += 1
        else:
            d -= 1
    if l > r or u > d:
        print('NO')
        exit()

if l <= sc <= r and u <= sr <= d:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
H, W, N, sr, sc, S, T = open(0).read().split()
H, W, N, sr, sc = map(int, (H,W,N,sr,sc))
dpr = [0]*N
dpl = [0]*N
dpu = [0]*N
dpd = [0]*N
dpr[0] = W-sc
dpl[0] = sc-1
dpu[0] = sr-1
dpd[0] = H-sr
for i in range(N-1):
  if T[i]=='R':
    dpl[i+1] = min(W-1,dpl[i]+1)
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
    dpu[i+1] = dpu[i]
  elif T[i]=='L':
    dpr[i+1] = min(W-1,dpr[i]+1)
    dpl[i+1] = dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  elif T[i]=='U':
    dpd[i+1] = min(H-1,dpd[i]+1)
    dpl[i+1]= dpl[i]
    dpu[i+1] = dpu[i]
    dpr[i+1] = dpr[i]
  else:
    dpu[i+1] = min(H-1,dpu[i]+1)
    dpl[i+1] = dpl[i]
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
sdpr = [0]*(N+1)
sdpl = [0]*(N+1)
sdpu = [0]*(N+1)
sdpd = [0]*(N+1)
for i in range(N):
  if S[i]=='R':
    sdpr[i+1] = sdpr[i]+1
    sdpl[i+1] = sdpl[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpr[i+1]>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    sdpd[i+1] = sdpd[i]+1
    sdpr[i+1] = sdpr[i]
    sdpl[i+1] = sdpl[i]
    sdpu[i+1] = sdpu[i]
    if sdpd[i+1]>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    sdpl[i+1] = sdpl[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpl[i+1]>dpl[i]:
      print('NO')
      break
  else:
    sdpu[i+1] = sdpu[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpl[i+1] = sdpl[i]
    if sdpu[i+1]>dpu[i]:
      print('NO')
      break
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
H, W, N, sr, sc, S, T = open(0).read().split()
H, W, N, sr, sc = map(int, (H,W,N,sr,sc))
dpr = [0]*N
dpl = [0]*N
dpu = [0]*N
dpd = [0]*N
dpr[0] = W-sc
dpl[0] = sc-1
dpu[0] = sr-1
dpd[0] = H-sr
for i in range(N-1):
  if T[i]=='R':
    dpl[i+1] = min(W-1,dpl[i]+1)
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
    dpu[i+1] = dpu[i]
  elif T[i]=='L':
    dpr[i+1] = min(W-1,dpr[i]+1)
    dpl[i+1] = dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  elif T[i]=='U':
    dpd[i+1] = min(H-1,dpd[i]+1)
    dpl[i+1]= dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  else:
    dpu[i+1] = min(H-1,dpu[i]+1)
    dpl[i+1] = dpl[i]
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
sdpr = [0]*(N+1)
sdpl = [0]*(N+1)
sdpu = [0]*(N+1)
sdpd = [0]*(N+1)
for i in range(N):
  if S[i]=='R':
    sdpr[i+1] = sdpr[i]+1
    sdpl[i+1] = sdpl[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpr[i+1]>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    sdpd[i+1] = sdpd[i]+1
    sdpr[i+1] = sdpr[i]
    sdpl[i+1] = sdpl[i]
    sdpu[i+1] = sdpu[i]
    if sdpd[i+1]>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    sdpl[i+1] = sdpl[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpl[i+1]>dpl[i]:
      print('NO')
      break
  else:
    sdpu[i+1] = sdpu[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpl[i+1] = sdpl[i]
    if sdpu[i+1]>dpu[i]:
      print('NO')
      break
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
H, W, N, sr, sc, S, T = open(0).read().split()
H, W, N, sr, sc = map(int, (H,W,N,sr,sc))
dpr = [0]*N
dpl = [0]*N
dpu = [0]*N
dpd = [0]*N
dpr[0] = W-sr
dpl[0] = sr-1
dpu[0] = sc-1
dpd[0] = H-sc
for i in range(N-1):
  if T[i]=='R':
    dpl[i+1] = min(W,dpl[i]+1)
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
    dpu[i+1] = dpu[i]
  elif T[i]=='L':
    dpr[i+1] = min(W,dpr[i]+1)
    dpl[i+1] = dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  elif T[i]=='U':
    dpd[i+1] = min(H,dpd[i]+1)
    dpl[i+1]= dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  else:
    dpu[i+1] = min(H,dpu[i]+1)
    dpl[i+1] = dpl[i]
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
sdpr = [0]*(N+1)
sdpl = [0]*(N+1)
sdpu = [0]*(N+1)
sdpd = [0]*(N+1)
for i in range(N):
  if S[i]=='R':
    sdpr[i+1] = sdpr[i]+1
    sdpl[i+1] = sdpl[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpr[i+1]>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    sdpd[i+1] = sdpd[i]+1
    sdpr[i+1] = sdpr[i]
    sdpl[i+1] = sdpl[i]
    sdpu[i+1] = sdpu[i]
    if sdpd[i+1]>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    sdpl[i+1] = sdpl[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpl[i+1]>dpl[i]:
      print('NO')
      break
  else:
    sdpu[i+1] = sdpu[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpl[i+1] = sdpl[i]
    if sdpu[i+1]>dpu[i]:
      print('NO')
      break
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
H, W, N, sr, sc, S, T = open(0).read().split()
H, W, N, sr, sc = map(int, (H,W,N,sr,sc))
dpr = [0]*N
dpl = [0]*N
dpu = [0]*N
dpd = [0]*N
dpr[0] = W-sr
dpl[0] = sr
dpu[0] = sc
dpd[0] = H-sc
for i in range(N-1):
  if T[i]=='R':
    dpl[i+1] = min(W,dpl[i]+1)
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
    dpu[i+1] = dpu[i]
  elif T[i]=='L':
    dpr[i+1] = min(W,dpr[i]+1)
    dpl[i+1] = dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  elif T[i]=='U':
    dpd[i+1] = min(H,dpd[i]+1)
    dpl[i+1]= dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  else:
    dpu[i+1] = min(H,dpu[i]+1)
    dpl[i+1] = dpl[i]
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
sdpr = [0]*(N+1)
sdpl = [0]*(N+1)
sdpu = [0]*(N+1)
sdpd = [0]*(N+1)
for i in range(N):
  if S[i]=='R':
    sdpr[i+1] = sdpr[i]+1
    sdpl[i+1] = sdpl[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpr[i+1]>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    sdpd[i+1] = sdpd[i]+1
    sdpr[i+1] = sdpr[i]
    sdpl[i+1] = sdpl[i]
    sdpu[i+1] = sdpu[i]
    if sdpd[i+1]>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    sdpl[i+1] = sdpl[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpu[i+1] = sdpu[i]
    if sdpl[i+1]>dpl[i]:
      print('NO')
      break
  else:
    sdpu[i+1] = sdpu[i]+1
    sdpr[i+1] = sdpr[i]
    sdpd[i+1] = sdpd[i]
    sdpl[i+1] = sdpl[i]
    if sdpu[i+1]>dpu[i]:
      print('NO')
      break
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
H, W, N, sr, sc, S, T = open(0).read().split()
H, W, N, sr, sc = map(int, (H,W,N,sr,sc))
dpr = [0]*N
dpl = [0]*N
dpu = [0]*N
dpd = [0]*N
dpr[0] = W-sr
dpl[0] = sr
dpu[0] = sc
dpd[0] = H-sc
for i in range(N-1):
  if T[i]=='R':
    dpl[i+1] = min(W-1,dpl[i]+1)
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
    dpu[i+1] = dpu[i]
  elif T[i]=='L':
    dpr[i+1] = min(W-1,dpr[i]+1)
    dpl[i+1] = dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  elif T[i]=='U':
    dpd[i+1] = min(H-1,dpd[i]+1)
    dpl[i+1]= dpl[i]
    dpu[i+1] = dpu[i]
    dpd[i+1] = dpd[i]
  else:
    dpu[i+1] = min(H-1,dpu[i]+1)
    dpl[i+1] = dpl[i]
    dpr[i+1] = dpr[i]
    dpd[i+1] = dpd[i]
sdpr = [0]*(N+1)
sdpl = [0]*(N+1)
sdpu = [0]*(N+1)
sdpd = [0]*(N+1)
for i in range(N):
  if S[i]=='R':
    sdpr[i+1] = sdpr[i]+1
    if sdpr[i+1]>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    sdpd[i+1] = sdpd[i]+1
    if sdpd[i+1]>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    sdpl[i+1] = sdpl[i]+1
    if sdpl[i+1]>dpl[i]:
      print('NO')
      break
  else:
    sdpu[i+1] = sdpu[i]+1
    if sdpu[i+1]>dpu[i]:
      print('NO')
      break
else:
  print('YES')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

H,W,N = map(int, input().split())
sy, sx = map(int, input().split())
T = input()
A = input()

td = defaultdict(int)
ad = defaultdict(int)

for i in range(N):
    td[T[i]] += 1

    # 落とせるか判定
    if max(1, sx - ad["L"]) + td["R"] > W \
    or min(W, sx + ad["R"]) - td["L"] < 1 \
    or max(1, sy - ad["U"]) + td["D"] > H \
    or min(H, sy + ad["D"]) - td["U"] < 1:
        print("NO")
        exit()

    ad[A[i]] += 1

print("YES")

Submission status: Wrong Answer

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *

H,W,N=map(int,input().split())
sr,sc=map(int,input().split())
S=input()
T=input()


st=0
end=W-1
sttate=0
endtate=H-1
for i in range(N-1,-1,-1):
    if T[i]=="L":
        if end<W-1:
            end+=1
    if T[i]=="R":
        if st>0:
            st-=1
    if T[i]=="U":
        if endtate<H-1:
            endtate+=1
    if T[i]=="D":
        if sttate>0:
            sttate-=1

    if S[i]=="L":
        st+=1
    if S[i]=="R":
        end-=1
    if S[i]=="U":
        sttate+=1
    if S[i]=="D":
        endtate-=1
    if st>end or sttate>end:
        print("NO")
        exit()

if st<=sc-1<=end and sttate<=sr-1<=endtate:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations
from itertools import accumulate
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,w,n=map(int,input().split())
src=list(map(int,input().split()))
s=input()
t=input()
lrud=["L","U","D","R"]
dic={"L":[0,-1],"R":[0,1],"U":[-1,0],"D":[1,0]}
for i in range(4):
    tmp=src[:]
    print(lrud[i],lrud[-1-i])
    for j in range(n):
        if s[j]==lrud[i]:
            tmp[0]+=dic[s[j]][0]
            tmp[1]+=dic[s[j]][1]
        if lrud[i]=="L" and tmp[1]==0:
            print("NO")
            quit()
        if lrud[i]=="R" and tmp[1]==w+1:
            print("NO")
            quit()
        if lrud[i]=="U" and tmp[0]==0:
            print("NO")
            quit()
        if lrud[i]=="D" and tmp[0]==h+1:
            print("NO")
            quit()
        # print(tmp)
        if t[j]==lrud[-1-i]:
            if 0<tmp[0]+dic[t[j]][0]<=h:
                tmp[0]+=dic[t[j]][0]
            if 0<tmp[1]+dic[t[j]][1]<=w:
                tmp[1]+=dic[t[j]][1]
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    H, W, N = LI()
    start = LI()
    S = SI(); T = SI()
    for t,a in [["U","D"],["R","L"]]:
        if t=="U":
            n = H
        else:
            n = W
        # 落ちないエリア
        l = 1; r = n
        if S[-1]==t:
            r -=1
        elif S[-1]==a:
            l +=1
        for i in range(N-2,-1,-1):
            if T[i]==t and l>1:
                l -= 1
            elif T[i]==a and r<n:
                r += 1
            if S[i] == t:
                r -= 1
            elif S[i] == a:
                l += 1
#            print(l,r)
            if l>r:
                print("NO")
                return

        if t=="U" and (not l<=start[0]<=r):
            print("NO")
            return
        elif t=="R" and (not l<=start[1]<=r):
            print("NO")
            return
    print("YES")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    H, W, N = LI()
    start = LI()
    S = SI(); T = SI()
    for t,a in [["U","D"],["R","L"]]:
        if t=="U":
            n = H
        else:
            n = W
        # 落ちないエリア
        l = 1; r = n
        if S[-1]==t:
            r -=1
        elif S[-1]==a:
            l +=1
        for i in range(N-2,-1,-1):
            if T[i]==t and l>1:
                l -= 1
            elif T[i]==a and r<n:
                r += 1
            if S[i] == t:
                r -= 1
            elif S[i] == a:
                l += 1
#            print(l,r)
            if l>r:
                print("NO")
                return
            if t=="U" and (r==0 or l==n):
                print("NO")
                return
            if t=="R" and (r==0 or l==n):
                print("NO")
                return

        if t=="U" and (not l<=start[0]<=r):
            print("NO")
            return
        elif t=="R" and (not l<=start[1]<=r):
            print("NO")
            return
    print("YES")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    H, W, N = LI()
    start = LI()
    S = SI(); T = SI()
    for t,a in [["U","D"],["R","L"]]:
        if t=="U":
            n = H
        else:
            n = W
        # 落ちないエリア
        l = 1; r = n
        if S[-1]==t:
            r -=1
        elif S[-1]==a:
            l +=1
        for i in range(N-2,-1,-1):
            if T[i]==t and l>1:
                l -= 1
            elif T[i]==a and r<n:
                r += 1
            if S[i] == t:
                r -= 1
            elif S[i] == a:
                l += 1
#            print(l,r)
            if l>=r:
                print("NO")
                return
            if t=="U" and (r==0 or l==n):
                print("NO")
                return
            if t=="R" and (r==0 or l==n):
                print("NO")
                return

        if t=="U" and (not l<=start[0]<=r):
            print("NO")
            return
        elif t=="R" and (not l<=start[1]<=r):
            print("NO")
            return
    print("YES")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""