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

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

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+1)
dpl = [0]*(N+1)
dpu = [0]*(N+1)
dpd = [0]*(N+1)
dpr[0] = W-sc
dpl[0] = sc-1
dpu[0] = sr-1
dpd[0] = H-sr
for i in range(N):
  if S[i]=='R':
    dpr[i] -= 1
    if 0>dpr[i]:
      print('NO')
      break
  elif S[i]=='D':
    dpd[i] -= 1
    if 0>dpd[i]:
      print('NO')
      break
  elif S[i]=='L':
    dpl[i] -= 1
    if 0>dpl[i]:
      print('NO')
      break
  else:
    dpu[i] -= 1
    if 0>dpu[i]:
      print('NO')
      break
  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]
else:
  print('YES')

Submission status: Runtime Error

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

Solution code:
import sys
input = sys.stdin.readline
h,w,N = map(int,input().split())
sx,sy = map(int,input().split())
S = input().rstrip()
T = input().rstrip()
L = 0
R = 0
U = 0
D = 0
for i in range(n):
    if S[i] == "L":
        L+=1
    if S[i] == "R":
        R+=1
    if S[i] == "U":
        U+=1
    if S[i] == "D":
        D+=1
    if L>=sy or R >= w-sy+1 or U>=sx or D >= h-sx+1:
        print("NO")
        exit()
    if T[i] == "L":
        R = max(,)
    if T[i] == "R":
        R+=1
    if T[i] == "U":
        U+=1
    if T[i] == "D":
        D+=1

Submission status: Runtime Error

Solution code:
di='URLD'
mp=dict(zip(list(di),range(4)))
rv=dict(zip(list(di),list(di[::-1])))
h,w,n=map(int,input().split())
b=[h,w,w,h]
r,c=map(int,input().split())
st=[h-r+1,c,w-c+1,r]
s=input()
t=[rv[i] for i in input()]
ans=True
for j,i in mp.items():
    c=st[i]
    for k in range(n):
        c+=1*(s[k]==j)
        if c>b[i]:
            a=False
        if c>1:
            c-=1*(t[k]==j)
if a:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

h,w,n=LI()
b=[h,w,w,h]
r,c=LI()
st=[r,c,c,r]
s=input()
t=input()
cs=[[0]for i in range(4)]
ct=[[0]for i in range(4)]
di='URLD'
di=dict(zip(list(di),range(4)))
for j,i in di.items():
    for k in range(n):
        cs[i].append(cs[i][-1]+(1 if s[k]==j else 0))
        ct[i].append(ct[i][-1]+(1 if t[k]==j else 0))
ans=False
for i in range(4):
    if max([(i-j)*(-1)**(i//2)+st[i] for i,j in zip(cs[i],[0]+ct[3-i])])>b[i]:
        ans=True
if ans:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
Sr,Sc=map(int,input().split())
S=input()
T=input()

def solve():
  Ls,Rs,Us,Ds=0,0,0,0
  Lt,Rt,Ut,Dt=0,0,0,0
  for c in S:
    if c = 'L':Ls+=1
    if c = 'R':Rs+=1
    if c = 'U':Us+=1
    if c = 'D':Ds+=1
  for c in T:
    if c = 'L':Lt+=1
    if c = 'R':Rt+=1
    if c = 'U':Ut+=1
    if c = 'D':Dt+=1
  print("NO" if Ls-Rt-Sc<=0 or
Rs-Lt+Sc>W or
Us-Dt-Sr<=0 or
Ds-Ut+Sr>H else "YES")
solve()

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int h,w,n;
int x,y;
string s,t;

bool calc(char L,char R,int Max,int sta){
    int left=1,right=Max;
    if (s[n-1]==R) right-=1; 
    if (s[n-1]==L) left+=1; 
    per(i,n-1){
        if (t[i]==R) left=max(1,left-1);
        if (t[i]==L) right=min(right+1,Max); 
         
        if (s[i]==R) right-=1;
        if (s[i]==L) left+=1;
        

        if (left>right) return false;
    }

    return left<=sta && sta<=right;

}

void solve(){
    cin >> h >> w >> n;
    cin >> y >> x;
    cin >> s >> t;
    bool a1=calc('L','R',w,x);
    bool a2=calc('U','D',h,y);
    puts(a1&&a2 ? "YES" : "NO");
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Submission status: Runtime Error

Solution code:
# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def aok_turn(aoki: str, tolow: str, toup: str, lower: int, upper: int, amin: int, amax: int):
    if aoki == tolow:
        upper = min(amax, upper + 1)
    elif aoki == toup:
        lower = max(amin, lower - 1)

    return lower, upper


def tak_turn(taki: str, tolow: str, toup: str, lower: int, upper: int, amin:int, amxax: int):
    if taki == tolow:
        lower = min(amax, lower + 1)
    elif taki == toup:
        upper = max(amin, upper - 1)

    return lower, upper


def on_board(lower: int, upper: int, amin: int, amax: int):
    if lower < upper and upper > amin and lower < amax:
        return True
    else:
        return False


def judge(tak: str, aok: str, tolow: str, toup: str, start: int, amin: int, amax: int) -> bool:
    lower = amin
    upper = amax
    for aoki, taki in zip(aok, tak):
        lower, upper = aok_turn(aoki, tolow, toup, lower, upper, amin, amax)
        lower, upper = tak_turn(taki, tolow, toup, lower ,upper, amin, amax)
        if not on_board(lower, upper, amin, amax):
            return False

    return True if lower <= start < upper else False


h,w,n = li()
sr, sc = li_()
tak = ns()[::-1]
aok = ns()[::-1]

L = 'L'
R = 'R'
U = 'U'
D = 'D'

lr = judge(tak, aok, L, R, sc, 0, w)
ud = judge(tak, aok, D, U, sr, 0, h)

print("YES") if lr and ud else print("NO")

Submission status: Runtime Error

Solution code:
file = open("sample.txt", "r")
stdin = file

# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def aok_turn(aoki: str, tolow: str, toup: str, lower: int, upper: int, amin: int, amax: int):
    if aoki == tolow:
        upper = min(amax, upper + 1)
    elif aoki == toup:
        lower = max(amin, lower - 1)

    return lower, upper


def tak_turn(taki: str, tolow: str, toup: str, lower: int, upper: int, amin:int, amxax: int):
    if taki == tolow:
        lower = min(amax, lower + 1)
    elif taki == toup:
        upper = max(amin, upper - 1)

    return lower, upper


def on_board(lower: int, upper: int, amin: int, amax: int):
    if lower < upper and upper > amin and lower < amax:
        return True
    else:
        return False


def judge(tak: str, aok: str, tolow: str, toup: str, start: int, amin: int, amax: int) -> bool:
    lower = amin
    upper = amax
    for aoki, taki in zip(aok, tak):
        lower, upper = aok_turn(aoki, tolow, toup, lower, upper, amin, amax)
        lower, upper = tak_turn(taki, tolow, toup, lower ,upper, amin, amax)
        if not on_board(lower, upper, amin, amax):
            return False

    return True if lower <= start < upper else False


h,w,n = li()
sr, sc = li_()
tak = ns()[::-1]
aok = ns()[::-1]

L = 'L'
R = 'R'
U = 'U'
D = 'D'

lr = judge(tak, aok, L, R, sc, 0, w)
ud = judge(tak, aok, D, U, sr, 0, h)

print("YES") if lr and ud else print("NO")

Submission status: Runtime Error

Solution code:
R,G,B,N = (int(i) for i in input().split())
maxr = N // R
maxg = N // G
maxb = N // B
result = 0

for i in range(maxr + 1):
    for j in range(maxg + 1):
        if (N - R * i - G * j) % B == 0:
            result += 1
        

print(result)

Submission status: Runtime Error

Solution code:
H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H
for i in range(H, -1, -1):
    if T[i] == 'U':
        down = min(H, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up >= down:
        print('NO')
        exit()
        
# horizontal direction
left, right = 0, W
for j in range(W-1, -1, -1):    
    if T[j] == 'L':
        right = min(W, right + 1)
    elif T[j] == 'R':
        left = max(0, left - 1)
    
    if S[j] == 'L':
        left += 1
    elif S[j] == 'R':
        right -= 1
    
    if left >= right:
        print('NO')
        exit()
if up <= s_r < down and left <= s_c < right:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
import sys

H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H-1
for i in range(H, -1, -1):
    if T[i] == 'U':
        down = min(H, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up >= down:
        print('NO')
        sys.exit()
        
# horizontal direction
left, right = 0, W-1
for j in range(W-1, -1, -1):    
    if T[j] == 'L':
        right = min(H, right + 1)
    elif T[j] == 'R':
        left = max(0, left - 1)
    
    if S[j] == 'L':
        left += 1
    elif S[j] == 'R':
        right -= 1
    
    if left >= right:
        print('NO')
        sys.exit()
if up <= s_r <= down and left <= s_c <= right:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

#gridのindexは入力値のまま扱う(grid=[1,1]~[H,W])
#left<x<rightの間が生存範囲(初めはグリッド全てが生存可能状態)
left=0
right=W+1
up=0
down=H+1

ans="YES"
#手を逆順で見ていく。
for s,t in zip(reversed(S),reversed(T)):
    if t=='R':#生存可能範囲を広げる(0より小さくならないようにする)
        left=max(0,left-1)
    elif t=="L":
        right=min(W+1,right+1)
    elif t=="D":
        up = max(0,up-1)
    else:
        down=min(H+1,down+1)


    if s=="R"
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    #もし、途中でright-left==1。つまり、生存可能範囲がなくなってしまったら、
    #落とされてしまうため、ans=NOにして終了する
    if right-left==1 or down-up==1:
        ans="NO"
        break

#全ての手を見た後で、スタート地点が生存可能範囲に入っていればOK
if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)

Submission status: Runtime Error

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H,W,N=map(int,input().split())

sr,sc=map(int,input().split())
S=input()[:-1]
T=input()[:-1]

left=0
right=W+1
up=0
down=H+1

ans="YES"
for i,(s,t) in enumerate(zip(reversed(S),reversed(T))):
    if i!=0:
        if t=='R':
            left=max(0,left-1)
        elif t=="L":
            right=min(W+1,right+1)
        elif t=="D":
            up = max(0,up-1)
        else:
            down=min(H+1,down+1)


    if s=="R":
        right-=1
    elif s=="L":
        left+=1
    elif s=="D":
        down-=1
    else:
        up+=1

    if right-left==1 or down-upp==1:
        ans="NO"
        break

if not left<sc<right or not up<sr<down:
    ans="NO"
print(ans)

Submission status: Runtime Error

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

left, right = 0, W+1
if S[-1] == "R":
    right -= 1
elif S[-1] == "L":
    left += 1
for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "R":
        left -= 1
    elif ti == "L":
        right += 1
    left = max(0, left)
    right = min(W+1, right)

    if si == "R":
        right -= 1
    elif si == "L":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sc <= left or right <= sc:
    print("NO")
    exit()


left, right = 0, H+1
if S[-1] == "U":
    left += 1
elif S[-1] == "D":
    right -= 1

for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "D":
        left -= 1
    elif ti == "U":
        right += 1
    down = max(0, down)
    up = min(H+1, up)

    if si == "D":
        right -= 1
    elif si == "":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sr <= left or right <= sr:
    print("NO")
    exit()

print("YES")

Submission status: Runtime Error

Solution code:
H,W,N = tuple(map(int,input().split()))

r,c = tuple(map(int,input().split()))

Ta = input()
Ao = input()

def convert(ch):
    if ch=="R":
        return (0,1)
    elif ch=="L":
        return (0,-1)
    elif ch=="U":
        return (1,0)
    else:
        return (-1,0)
# 青木くんのターンになったらやばいマップを逆方向に1動かして重ねた部分がやばくなる
import numpy as np
yabaiMap = np.zeros((H+2,W+2))
yabaiMap[1:-1,1:-1] = np.ones((H,W))

for idx,(t,a) in enumerate(zip(reversed(Ta),reversed(Ao))):
    if idx != 0:
        
        dy,dx = convert(a)
        # 動かした方向にやばくない場所があれば復帰する
        # つまり フィルタをかけてしまえばいいので，元の場所が0かつ動かした先が1であればよい，その場所を1にする
        yabaiMap[1:-1,1:-1] += (1-yabaiMap)[1:-1,1:-1] * yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
        #print("A",a,yabaiMap)
    dy,dx = convert(t)
    yabaiMap[1:-1,1:-1] *= yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
    if np.sum(yabaiMap) == 0:
        print("NO")
        quit()
print("YES" if yabaiMap[r,c] ==1 else "NO")

Submission status: Runtime Error

Solution code:
H,W,N = tuple(map(int,input().split()))

r,c = tuple(map(int,input().split()))

Ta = input()
Ao = input()

def convert(ch):
    if ch=="R":
        return (0,1)
    elif ch=="L":
        return (0,-1)
    elif ch=="U":
        return (1,0)
    else:
        return (-1,0)
# 青木くんのターンになったらやばいマップを逆方向に1動かして重ねた部分がやばくなる
import numpy as np
yabaiMap = np.zeros((H+2,W+2))
yabaiMap[1:-1,1:-1] = np.ones((H,W))

for idx,(t,a) in enumerate(zip(reversed(Ta),reversed(Ao))):
    if idx != 0:
        
        dy,dx = convert(a)
        # 動かした方向にやばくない場所があれば復帰する
        # つまり フィルタをかけてしまえばいいので，元の場所が0かつ動かした先が1であればよい，その場所を1にする
        yabaiMap[1:-1,1:-1] += (1-yabaiMap)[1:-1,1:-1] * yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
        #print("A",a,yabaiMap)
    dy,dx = convert(t)
    yabaiMap[1:-1,1:-1] *= yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
    
	if np.sum(yabaiMap) == 0:
        print("NO")
        quit()
print("YES" if yabaiMap[r,c] ==1 else "NO")

Submission status: Runtime Error

Solution code:
H,W,N = tuple(map(int,input().split()))

r,c = tuple(map(int,input().split()))

Ta = input()
Ao = input()

def convert(ch):
    if ch=="R":
        return (0,1)
    elif ch=="L":
        return (0,-1)
    elif ch=="U":
        return (1,0)
    else:
        return (-1,0)
# 青木くんのターンになったらやばいマップを逆方向に1動かして重ねた部分がやばくなる
import numpy as np
yabaiMap = np.zeros((H+2,W+2))
yabaiMap[1:-1,1:-1] = np.ones((H,W))

for idx,(t,a) in enumerate(zip(reversed(Ta),reversed(Ao))):
    if idx != 0:
        
        dy,dx = convert(a)
        # 動かした方向にやばくない場所があれば復帰する
        # つまり フィルタをかけてしまえばいいので，元の場所が0かつ動かした先が1であればよい，その場所を1にする
        yabaiMap[1:-1,1:-1] += (1-yabaiMap)[1:-1,1:-1] * yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
        #print("A",a,yabaiMap)
    dy,dx = convert(t)
    yabaiMap[1:-1,1:-1] *= yabaiMap[1+dy:H+1+dy,1+dx:W+1+dx]
    
    #print("T",t,yabaiMap)
print("YES" if yabaiMap[r,c] ==1 else "NO")

Submission status: Runtime Error

Solution code:
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
sr -= 1; sc -= 1
 
L=0; R=w-1; U=0; D=h-1;
is_drop = False
for i in range(n)[::-1]:
    if t[i] == 'U': D = min(D+1, h-1)
    if t[i] == 'D': U = max(U-1, 0)
    if t[i] == 'L': R = min(R+1, w-1)
    if t[i] == 'R': L = max(L-1, 0)
    if s[i] == 'U': U++
    if s[i] == 'D': D--
    if s[i] == 'L': L++
    if s[i] == 'R': R--
    if R < L or D < U: is_drop = True
    if (not L <= sc <= R) or (not U <= sr <= D):  is_drop = True

print( "NO" if is_drop else "YES" )

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w,n = m()

s1,s2 = m()


r = w-s2
l = s2 -1
u = h - s1
d = s1 -1

S = list(input())

T = list(input())

k1 = [0,0,0,0]

k2 = [0,0,0,0]

for i in range(n):
    if S[i] == "R":
        r -= 1
        l += 1
    if r < 0:
        print("NO")
        exit()
    if T[i] ==  "L":
        if l != 0:
            r += 1
            l -= 1

r = w-s2
l = s2−1

for i in range(n):
    if S[i] == "L":
        l -= 1
        r +=1
    if l < 0:
        print("NO")
        exit()
    if T[i] ==  "R":
        if r != 0:
            r -= 1
            l += 1


for i in range(n):
    if S[i] == "U":
        d += 1
        u -= 1
    if u < 0:
        print("NO")
        exit()
    if T[i] == "D":
        if d != 0:
            u += 1
            d -= 1

u = h - s1
d = s1-1
for i in range(n):
    if S[i] == "D":
        u += 1
        d -= 1
    if d < 0:
        print("NO")
        exit()
    if T[i] == "U":
        if u != 0:
            d += 1
            u -= 1

print("YES")

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w,n = m()

s1,s2 = m()


h = s1
r = s2

S = list(input())

T = list(input())


for i in range(n):
    if S[i] == "R":
        r += 1
    if r > w:
        print("NO")
        exit()
    if T[i] ==  "L":
        if r != 1:
            r -= 1

r = s1

for i in range(n):
    if S[i] == "L":
        r -= 1
    if r < 1:
        print("NO")
        exit()
    if T[i] ==  "R":
        if r != w:
            r += 1


for i in range(n):
    if S[i] == "U":
        d += 1
    if d > h:
        print("NO")
        exit()
    if T[i] == "D":
        if d != 1:
            d -= 1

d = s2
for i in range(n):
    if S[i] == "D":
        d -= 1
    if d < 1:
        print("NO")
        exit()
    if T[i] == "U":
        if d != h:
            d += 1

print("YES")

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w,n = m()

s1,s2 = m()


r = s1
d = s2

S = list(input())

T = list(input())


for i in range(n):
    if S[i] == "R":
        r += 1
    if r > w:
        print("NO")
        exit()
    if T[i] ==  "L":
        if r != 1:
            r -= 1

r = s1

for i in range(n):
    if S[i] == "L":
        r -= 1
    if r < 1:
        print("NO")
        exit()
    if T[i] ==  "R":
        if r != w-1:
            r += 1


for i in range(n):
    if S[i] == "U":
        d += 1
    if u > h:
        print("NO")
        exit()
    if T[i] == "D":
        if d != 1:
            d -= 1

d = s2
for i in range(n):
    if S[i] == "D":
        d -= 1
    if d < 1:
        print("NO")
        exit()
    if T[i] == "U":
        if d != h:
            d += 1

print("YES")

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w,n = m()

s1,s2 = m()


r = s1
d = s2

S = list(input())

T = list(input())


for i in range(n):
    if S[i] == "R":
        r += 1
    if r < 1:
        print("NO")
        exit()
    if T[i] ==  "L":
        if r != 1:
            r -= 1

r = s1

for i in range(n):
    if S[i] == "L":
        r -= 1
    if r < 1:
        print("NO")
        exit()
    if T[i] ==  "R":
        if r != w-1:
            r += 1


for i in range(n):
    if S[i] == "U":
        d += 1
    if u >= h:
        print("NO")
        exit()
    if T[i] == "D":
        if d != 1:
            d -= 1

d = s2
for i in range(n):
    if S[i] == "D":
        d -= 1
    if d < 1:
        print("NO")
        exit()
    if T[i] == "U":
        if u != 0:
            d += 1

print("YES")

Submission status: Runtime Error

Solution code:
h, w, n = map(int, input().split())
ar, ac = map(int, input().split())
s = input()
t = input()
r = ac
l = ac
u = ar
d = ar

for i in range(n):
    if s[i] == "R":
        r += 1
    if s[i] == "L":
        l -= 1
    if s[i] == "U":
        u -= 1
    if s[i] == "D":
        d += 1
    if l==0 or r==w+1 or u==0 or d==h+1:
        print("NO")
        ans = True
        break
        
    if t[i] == "R" and l != w:
        l += 1
    if t[i] == "L" and r != 1:
        r -= 1
    if t[i] == "U" and d != 1:
        d -= 1
    if t[i] == "D" and u != h:
        u += 1
 
if ans != True:
    print("YES")

Submission status: Runtime Error

Solution code:
H,W,N = map(int,input().split())
R,C = map(int,input().split())
S = input()
T = input()
a,b = R.copy(),C.copy()
for n in range(N):
        s,t = S[n],T[n]
        if s == 'U':
                R -= 1
                if R < 0:
                        print('N0')
                        exit()
        if t == 'D' and R < H:
                R += 1
R,C = a,b
for n in range(N):
        s,t = S[n],T[n]
        if s == 'L':
                C -= 1
                if C < 0:
                        print('N0')
                        exit()
        if t == 'R' and C < W:
                C += 1
R,C = a,b
for n in range(N):
        s,t = S[n],T[n]
        if s == 'R':
                C += 1
                if C > W:
                        print('N0')
                        exit()
        if t == 'L' and C > 0:
                C -= 1
R,C = a,b
for n in range(N):
        s,t = S[n],T[n]
        if s == 'D':
                R += 1
                if R > H:
                        print('N0')
                        exit()
        if t == 'U' and R > 0:
                R -= 1
print('YES')

Submission status: Runtime Error

Solution code:
H,W,N = map(int, input().split())
now = [int(i) for i in input().split()]
S = input()
T = input()
flag = True
SM = [now[0],now[1]]
TM = [now[0],now[1]]

for n in range(N):
    if S[n] == 'L':
            SM[1] -= 1
    if S[n] == 'R':
            SM[1] += 1 
    if S[n] == 'U':
            SM[0] -= 1 
    if S[n] == 'D':
            SM[0] += 1
    if T[n] == 'L':
            TM[1] -= 1
    if T[n] == 'R':
            TM[1] += 1 
    if T[n] == 'U':
            TM[0] -= 1 
    if T[n] == 'D':
            TM[0] += 1

sm = [0,0,0,0]
if W-SM[1] >= SM[1]-1:
    sm[0] = 1
if W-SM[1] < SM[1]-1:
    sm[1] = 1
if H-SM[0] <= SM[0]-1:
    sm[2] = 1
if H-SM[0] < SM[0]-1:
    sm[3] = 1

tm = [0,0,0,0]
if W-TM[1] >= TM[1]-1:
    tm[0] = 1
if W-TM[1] <= TM[1]-1:
    tm[1] = 1
if H-TM[0] <= TM[0]-1:
    tm[2] = 1
if H-TM[0] <= TM[0]-1:
    tm[3] = 1

for n in range(N):
    if S[n] == 'L':
        if sm[0] == 1:
            now[1] -= 1
    if S[n] == 'R':
        if sm[1] == 1:
            now[1] += 1 
    if S[n] == 'U':
        if sm[3] == 1:
            now[0] -= 1 
    if S[n] == 'D':
        if sm[4] == 1:
            now[0] += 1
    #print(now)

    if now[0]*now[1] == 0 or now[0] == H+1 or now[1] == W+1 :
        flag = False
        break
    
    if T[n] == 'L':
        if tm[1] == 0:
            now[1] -= 1
    if T[n] == 'R':
        if tm[2] == 0:
            now[1] += 1 
    if T[n] == 'U':
        if tm[3] == 0:
            now[0] -= 1 
    if T[n] == 'D':
        if tm[4] == 0:
            now[0] += 1
    #print(now)

    if now[0]*now[1] == 0 or now[0] == H+1 or now[1] == W+1 :
        flag = False
        break

if flag:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
h,w,n = map(int,input().split())
sr,sc = map(int,input().split())
s = input()
t = input()
def taka(k,pos):
    if k=='U' and pos[0]-1<=h-pos[0]+1:
        pos[0] -= 1
    if k=='D' and h-pos[0]<=pos[0]:
        pos[0] += 1
    if k=='R' and w-pos[1]<=pos[1]:
        pos[1] += 1
    if k=='L' and pos[1]-1<=w-pos[1]+1:
        pos[1] -= 1
    return pos
def ao(k,pos):
    if k=='U' and pos[0]-1>=h-pos[0]+1:
        pos[0] -= 1
    if k=='D' and h-pos[0]>=pos[0]:
        pos[0] += 1
    if k=='R' and w-pos[1]>=pos[1]:
        pos[1] += 1
    if k=='L' and pos[1]-1>=w-pos[1]+1:
        pos[1] -= 1
    return pos
pos = [sr,sc]
for i in range(n):
    pos = taka(s[i],pos)
    if pos[0]<=0 or pos[1]=0 or pos[0]>h or pos[1]>w:
        print('NO')
        exit()
    pos = ao(t[i],pos)
print('YES')