Problem:


Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Runtime Error

Solution code:
#082_D
s = input()
x, y = map(int, input().split())
xgo, ygo = [], []

flg = True
cnt = 0
for i in range(len(s)):
    if s[i] == 'T':
        if flg and cnt > 0:
            xgo.append(cnt)
        elif cnt > 0:
            ygo.append(cnt)
        flg = (flg + 1) % 2
        cnt = 0
    else:
        cnt += 1
        
if flg and cnt > 0:
    xgo.append(cnt)
elif cnt > 0:
    ygo.append(cnt)
    
def search(L, x):
    dp = [[False for _ in range(20000)] for _ in range(len(L)+1)]
    dp[0][10000] = True
    
    for i in range(1, len(L)+1):
        for j in range(-8000, 8001):
            k = j + 10000
            if dp[i-1][k-L[i-1]]:
                dp[i][k] = True
            if dp[i-1][k+L[i-1]]:
                dp[i][k] = True

    return dp[len(L)][10000+x]

print('Yes' if search(xgo, x) and search(ygo, y) else 'No')

Submission status: Runtime Error

Solution code:
s = list(str(input()))
x,y = map(int,input().split())

i = 0
while i < len(s) and s[i] =="F":
    i += 1
x -= i
s = s[i:]

m = [[],[]]
num = 0

for i in range(len(s)):
    if s[i] == "F":
        m[num][-1] += 1
    else:
        num += 1
        num %= 2
        m[num].append(0)

#print("m",m)

sumx = sum(m[0])
dpx = [False]*(2*sumx+3) #index(sumx+1)が座標0
dpx[sumx+1] = True
#print("dpx",dpx)

for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0:
            dpx[i-p] = dpx_pre[i] or dpx[i-p]
            #print("dpx",dpx)
        if i+p < 2*sumx+3:
            dpx[i+p] = dpx_pre[i] or dpx[i+p]
            #print("dpx",dpx)
    #print("dpx",dpx)

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) #index(sumy+1)が座標0
dpy[sumy+1] = True
#print("dpy",dpy)

for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0:
            dpy[i-p] = dpy_pre[i] or dpy[i-p]
        if i+p < 2*sumy+3:
            dpy[i+p] = dpy_pre[i] or dpy[i+p]
    #print("dpy",dpy)

if dpx[x+(sumx+1)] and dpy[y+(sumy+1)]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = list(str(input()))
x,y = map(int,input().split())

i = 0
while i < len(s) and s[i] =="F":
    i += 1
x -= i
s = s[i:]

m = [[],[]]
num = 0

for i in range(len(s)):
    if s[i] == "F":
        m[num][-1] += 1
    else:
        num += 1
        num %= 2
        m[num].append(0)

#print("m",m)

sumx = sum(m[0])
dpx = [False]*(2*sumx+3) #index(sumx+1)が座標0
dpx[sumx+1] = True
#print("dpx",dpx)

for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0 and (dpx[i-p] == False):
            dpx[i-p] = dpx_pre[i]
            #print("dpx",dpx)
        if i+p < 2*sumx+3 and (dpx[i+p] == False):
            dpx[i+p] = dpx_pre[i]
            #print("dpx",dpx)
    #print("dpx",dpx)

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) #index(sumy+1)が座標0
dpy[sumy+1] = True
#print("dpy",dpy)

for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0 and (dpy[i-p] == False):
            dpy[i-p] = dpy_pre[i]
        if i+p < 2*sumy+3 and (dpy[i+p] == False):
            dpy[i+p] = dpy_pre[i]
    #print("dpy",dpy)

if dpx[x+(sumx+1)] == True and dpy[y+(sumy+1)] == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = list(str(input()))
x,y = map(int,input().split())

i = 0
while i < len(s) and s[i] =="F":
    i += 1
x -= i
s = s[i+1:]

m = [[],[0]]
num = 1

for i in range(len(s)):
    if s[i] == "F":
        m[num][-1] += 1
    else:
        num += 1
        num %= 2
        m[num].append(0)

#print("m",m)

sumx = sum(m[0])
dpx = [False]*(2*sumx+3) #index(sumx+1)が座標0
dpx[sumx+1] = True
#print("dpx",dpx)

for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0 and (dpx[i-p] == False):
            dpx[i-p] = dpx_pre[i]
            #print("dpx",dpx)
        if i+p < 2*sumx+3 and (dpx[i+p] == False):
            dpx[i+p] = dpx_pre[i]
            #print("dpx",dpx)
    #print("dpx",dpx)

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) #index(sumy+1)が座標0
dpy[sumy+1] = True
#print("dpy",dpy)

for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0 and (dpy[i-p] == False):
            dpy[i-p] = dpy_pre[i]
        if i+p < 2*sumy+3 and (dpy[i+p] == False):
            dpy[i+p] = dpy_pre[i]
    #print("dpy",dpy)

if dpx[x+(sumx+1)] == True and dpy[y+(sumy+1)] == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = list(str(input()))
x,y = map(int,input().split())

m = [[0],[0]]
num = 0

for i in range(len(s)):
    if s[i] == "F":
        m[num][-1] += 1
    else:
        num += 1
        num %= 2
        m[num].append(0)

#print("m",m)

sumx = sum(m[0])
dpx = [False]*(2*sumx+3) #index(sumx+1)が座標0
dpx[sumx+1] = True
#print("dpx",dpx)

for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0 and (dpx[i-p] == False):
            dpx[i-p] = dpx_pre[i]
            #print("dpx",dpx)
        if i+p < 2*sumx+3 and (dpx[i+p] == False):
            dpx[i+p] = dpx_pre[i]
            #print("dpx",dpx)
    #print("dpx",dpx)

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) #index(sumy+1)が座標0
dpy[sumy+1] = True
#print("dpy",dpy)

for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0 and (dpy[i-p] == False):
            dpy[i-p] = dpy_pre[i]
        if i+p < 2*sumy+3 and (dpy[i+p] == False):
            dpy[i+p] = dpy_pre[i]
    #print("dpy",dpy)

if dpx[x+(sumx+1)] == True and dpy[y+(sumy+1)] == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = list(str(input()))
x,y = map(int,input().split())

m = [[0],[0]]
num = 0

for i in range(len(s)):
    if s[i] == "F":
        m[num][-1] += 1
    else:
        num += 1
        num %= 2
        m[num].append(0)

#print("m",m)

sumx = sum(m[0])
dpx = [False]*(2*sumx+3) #index(sumx+1)が座標0
dpx[sumx+1] = True
#print("dpx",dpx)

for p in m[0]:
    dpx_pre = dpx[:]
    dpx = [False]*(2*sumx+3)
    for i in range(2*sumx+3):
        if i-p >= 0 and dpx[i-p] == False:
            dpx[i-p] = dpx_pre[i]
            #print("dpx",dpx)
        if i+p < 2*sumx+3 and dpx[i+p] == False:
            dpx[i+p] = dpx_pre[i]
            #print("dpx",dpx)
    #print("dpx",dpx)

sumy = sum(m[1])
dpy = [False]*(2*sumy+3) #index(sumy+1)が座標0
dpy[sumy+1] = True
#print("dpy",dpy)

for p in m[1]:
    dpy_pre = dpy[:]
    dpy = [False]*(2*sumy+3)
    for i in range(2*sumy+3):
        if i-p >= 0 and dpy[i-p] == False:
            dpy[i-p] = dpy_pre[i]
        if i+p < 2*sumy+3 and dpy[i+p] == False:
            dpy[i+p] = dpy_pre[i]
    #print("dpy",dpy)

if dpx[x+(sumx+1)] == True and dpy[y+(sumy+1)] == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())

mv = [len(e) for e in s.split("T")]
mv_x = mv[2::2]
mv_y = mv[1::2]


def solve_dp(li, start, end):
    l = len(li)
    mx = sum(li)

    left = start - mx
    right = start + mx

    if end > right or end < left:
        return 0

    dp = [[0] * (2 * mx + 1) for _ in range(l + 1)]
    dp[0][start] = 1
    for i, e in enumerate(li, 1):
        for j in range(left, right + 1):
            if left <= j - e <= right:
                dp[i][j] |= dp[i-1][j-e]
            if left <= j + e <= right:
                dp[i][j] |= dp[i-1][j+e]

    return 0#dp[l][end]


bl_x = solve_dp(mv_x, mv[0], x)
bl_y = solve_dp(mv_y, 0, y)

if bl_x and bl_y:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())

mv = [len(e) for e in s.split("T")]
mv_x = mv[2::2]
mv_y = mv[1::2]


def solve_dp(li, start, end):
    l = len(li)
    mx = sum(li)

    left = start - mx
    right = start + mx

    if end > right or end < left:
        return 0

    dp = [[0] * (2 * mx + 1) for _ in range(l + 1)]
    dp[0][start] = 1
    for i, e in enumerate(li, 1):
        for j in range(left, right + 1):
            if left <= j - e <= right:
                dp[i][j] |= dp[i-1][j-e]
            if left <= j + e <= right:
                dp[i][j] |= dp[i-1][j+e]

    return dp[l][end]


bl_x = solve_dp(mv_x, mv[0], x)
bl_y = solve_dp(mv_y, 0, y)

if bl_x and bl_y:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())

mv = [len(e) for e in s.split("T")]
mv_x = mv[2::2]
mv_y = mv[1::2]


def solve_dp(li, start, end):
    l = len(li)
    mx = sum(li)
    
    if end > start + mx or end < start - mx:
        return 0

    dp = [[0] * (2 * mx + 1) for _ in range(l + 1)]
    dp[0][start] = 1
    for i, e in enumerate(li, 1):
        for j in range(-mx + start, mx + start + 1):
            if -mx <= j - e <= mx:
                dp[i][j] |= dp[i-1][j-e]
            if -mx <= j + e <= mx:
                dp[i][j] |= dp[i-1][j+e]

    return dp[l][end]


bl_x = solve_dp(mv_x, mv[0], x)
bl_y = solve_dp(mv_y, 0, y)

if bl_x and bl_y:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
xy=[0,0]
xx=0
f=0
flag=True
for i in s:
  if i=="F":
    if flag and f==0:
      xx+=1
      continue 
    xy[f]+=1
  else:
    f^=1
    flag=False
ans="Yes"
if not(xx-xy[0]<=x<=xx+xy[0]):ans="No"
xy[0]+=xx
if (xy[0]+x)%2==0 and (xy[1]+y)%2==0:print(ans)
  else:print('No')

Submission status: Runtime Error

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(lon, lat)
if sum(lon) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-1], lati[:-1], ans)
    
    
print(ans)

Submission status: Runtime Error

Solution code:
s = str(input())
x, y = map(int, input().split())

axis = 1
count = 0
X, Y = [], []
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    elif s[i] == 'T':
        if axis == 1:
            X.append(count)
            count = 0
        else:
            Y.append(count)
            count = 0
        axis *= -1
if axis == 1:
    X.append(count)
else:
    Y.append(count)


# x軸を先に見る, 値は +- 8*(10**3) が最大最小

max_idou = 8*(10**3)
DP = [[False for _ in range(2*max_idou+1)] for _ in range(len(X))]

for i in range(len(X)):
    DP[i][max_idou + X[i]] = True
    DP[i][max_idou - X[i]] = True
    for j in range(2*max_idou+1):
        if i == 0:
            break
        if j+X[i] > 2*max_idou:
            pass
        elif DP[i-1][j+X[i]] == True:
            DP[i][j] = True
        if j-X[i] < 0:
            pass
        elif DP[i-1][j-X[i]] == True:
            DP[i][j] = True
        
x_check = DP[len(X)-1][max_idou+x]

DP = [[False for _ in range(2*max_idou+1)] for _ in range(len(Y))]

for i in range(len(Y)):
    DP[i][max_idou + Y[i]] = True
    DP[i][max_idou - Y[i]] = True
    for j in range(2*max_idou+1):
        if i == 0:
            break
        if j+Y[i] > 2*max_idou:
            pass
        elif DP[i-1][j+Y[i]] == True:
            DP[i][j] = True
        if j-Y[i] < 0:
            pass
        elif DP[i-1][j-Y[i]] == True:
            DP[i][j] = True
        
y_check = DP[len(Y)-1][max_idou+y]

if x_check and y_check:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))

    s=input()+"T"

    N=len(s)
    x,y=MI()

    F=[[],[]]

    temp=0
    bit=0
    for i in range(N):
        if s[i]=="F":
            temp+=1
        else:
            if temp!=0:
                F[bit].append(temp)
            bit=(bit+1)%2
            temp=0

    Nx=len(F[0])
    Ny=len(F[1])


    #i番目の文字で，位置x [-N~N]につけるかどうか
    dpx=[[False]*(2*N+3) for _ in range(2)]
    dpy=[[False]*(2*N+3) for _ in range(2)]

    dpx[0][N]=True
    if Nx>=1:
        dpx[0][N]=False
        dpx[0][N+F[0][0]]=True
        if s[0]=="T":
            dpx[1][N-F[0][0]]=True
    dpy[0][N]=True

    MA=F[0][0]+1

    for i in range(1,Nx):
        MA+=F[0][i]
        for j in range(N-MA,N+MA):
            if dpx[(i+1)%2][j]:
                dpx[i%2][j+F[0][i]]=True
                dpx[i%2][j-F[0][i]]=True


    MA=0
    for i in range(Ny):
        MA+=F[0][i]
        for j in range(N-MA,N+MA):
            if dpy[i%2][j]:
                dpy[(i+1)%2][j+F[1][i]]=True
                dpy[(i+1)%2][j-F[1][i]]=True

    if dpx[(Nx+1)%2][N+x] and dpy[Ny%2][N+y]:
        print("Yes")
    else:
        print("No")

main()

Submission status: Runtime Error

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            dpx[i+1][jj]=True
            dpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            dpy[i+1][jj]=True
            dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            dpx[i+1][jj]=True
            idpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    a=min(N-MA,0)
    b=max(N+MA+1,2*N+1)
    for j in range(a,b):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            dpy[i+1][jj]=True
            dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    for j in range(N-MA,N+MA+1):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            if jj<=(2*N):
                dpx[i+1][jj]=True
            if jjj>=0:
                dpx[i+1][jjj]=True
                
if Ny>=1:   
    MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    for j in range(N-MA,N+MA+1):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            if jj<=(2*N):
                dpy[i+1][jj]=True
            if jjj>=0:
                dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True

MA=F[0][0]+1

for i in range(1,Nx):
    MA+=F[0][i]
    for j in range(N-MA,N+MA+1):
        if dpx[i][j]:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            if jj<=(2*N):
                dpx[i+1][jj]=True
            if jjj>=0:
                dpx[i+1][jjj]=True
                
                
MA=F[1][0]+1

for i in range(Ny):
    MA+=F[1][i]
    for j in range(N-MA,N+MA+1):
        if dpy[i][j]:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            if jj<=(2*N):
                dpy[i+1][jj]=True
            if jjj>=0:
                dpy[i+1][jjj]=True

if dpx[-1][N+x] and dpy[-1][N+y]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
#%%
mx = []
my = []
mx2 = []
my2 = []


cnt = 0
it = 0
for t in s:
    if t == 'T':
        if cnt:
            if it%2==0:
                mx.append(cnt)
                mx2.append(cnt*2)
            else:
                my.append(cnt)
                my2.append(cnt*2)
        it += 1
        cnt = 0
    else:
        cnt += 1
    
if it%2==0:
    mx.append(cnt)
    mx2.append(cnt*2)
else:
    my.append(cnt)
    my2.append(cnt*2)
    
        
dx = sum(mx)-x
dy = sum(my)-y


# dp[i+1][j] : i個目までの要素の和でjを作れるか？

MAX = max(sum(mx2),sum(my2)) + 10
dpx = [[False]*MAX for _ in range(len(mx2)+1)]
dpy = [[False]*MAX for _ in range(len(my2)+1)]

dpx[0][0] = True
dpy[0][0] = True

for i in range(len(mx2)):
    for j in range(MAX):
        if j<mx2[i]:
            dpx[i+1][j] = dpx[i][j]
        else:
            dpx[i+1][j] = dpx[i][j-mx2[i]] or dpx[i][j]

for i in range(len(my2)):
    for j in range(MAX):
        if j<my2[i]:
            dpy[i+1][j] = dpy[i][j]
        else:
            dpy[i+1][j] = dpy[i][j-my2[i]] or dpy[i][j]


if dx<0 or dy<0:
    print('No')

else:
    if dpx[len(mx2)][dx] and dpy[len(my2)][dy]:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
#%%
mx = []
my = []
mx2 = []
my2 = []


cnt = 0
it = 0
for t in s:
    if t == 'T':
        if cnt:
            if it%2==0:
                mx.append(cnt)
                mx2.append(cnt*2)
            else:
                my.append(cnt)
                my2.append(cnt*2)
        it += 1
        cnt = 0
    else:
        cnt += 1
    
if it%2==0:
    mx.append(cnt)
    mx2.append(cnt*2)
else:
    my.append(cnt)
    my2.append(cnt*2)
    
        
dx = sum(mx)-x
dy = sum(my)-y


# dp[i+1][j] : i個目までの要素の和でjを作れるか？

MAX = max(sum(mx2),sum(my2))+10
dpx = [[False]*MAX for _ in range(len(mx2)+1)]
dpy = [[False]*MAX for _ in range(len(my2)+1)]

dpx[0][0] = True
dpy[0][0] = True

for i in range(len(mx2)):
    for j in range(MAX):
        if j<mx2[i]:
            dpx[i+1][j] = dpx[i][j]
        else:
            dpx[i+1][j] = dpx[i][j-mx2[i]] or dpx[i][j]

for i in range(len(my2)):
    for j in range(MAX):
        if j<my2[i]:
            dpy[i+1][j] = dpy[i][j]
        else:
            dpy[i+1][j] = dpy[i][j-my2[i]] or dpy[i][j]


if len(mx)==0 and len(my)==0:
    if (x,y) == (0,0):
        print('Yes')
    else:
        print('No')
        
elif len(mx)==0:
    if dpy[len(my2)][dy] and x==0:
        print('Yes')
    else:
        print('No')
    
elif len(my)==0:
    if dpx[len(mx2)][dx] and y==0:
        print('Yes')
    else:
        print('No')

else:
    if dpx[len(mx2)][dx] and dpy[len(my2)][dy]:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
#%%
mx = []
my = []
mx2 = []
my2 = []


cnt = 0
it = 0
for t in s:
    if t == 'T':
        if cnt:
            if it%2==0:
                mx.append(cnt)
                mx2.append(cnt*2)
            else:
                my.append(cnt)
                my2.append(cnt*2)
        it += 1
        cnt = 0
    else:
        cnt += 1
    
if it%2==0:
    mx.append(cnt)
    mx2.append(cnt*2)
else:
    my.append(cnt)
    my2.append(cnt*2)
    
        
dx = sum(mx)-x
dy = sum(my)-y


# dp[i+1][j] : i個目までの要素の和でjを作れるか？

MAX = max(sum(mx2),sum(my2))+10
dpx = [[False]*MAX for _ in range(len(mx2)+1)]
dpy = [[False]*MAX for _ in range(len(my2)+1)]

dpx[0][0] = True
dpy[0][0] = True

for i in range(len(mx2)):
    for j in range(MAX):
        if j<mx2[i]:
            dpx[i+1][j] = dpx[i][j]
        else:
            dpx[i+1][j] = dpx[i][j-mx2[i]] or dpx[i][j]

for i in range(len(my2)):
    for j in range(MAX):
        if j<my2[i]:
            dpy[i+1][j] = dpy[i][j]
        else:
            dpy[i+1][j] = dpy[i][j-my2[i]] or dpy[i][j]


if dpx[len(mx2)][dx] and dpy[len(my2)][dy]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
#%%
mx = []
my = []
mx2 = []
my2 = []


cnt = 0
it = 0
for t in s:
    if t == 'T':
        if cnt:
            if it%2==0:
                mx.append(cnt)
                mx2.append(cnt*2)
            else:
                my.append(cnt)
                my2.append(cnt*2)
        it += 1
        cnt = 0
    else:
        cnt += 1
    
if it%2==0:
    mx.append(cnt)
    mx2.append(cnt*2)
else:
    my.append(cnt)
    my2.append(cnt*2)
    
        
dx = sum(mx)-x
dy = sum(my)-y

MAX = len(s)

# dp[i+1][j] : i個目までの要素の和でjを作れるか？

dpx = [[False]*MAX for _ in range(len(mx2)+1)]
dpy = [[False]*MAX for _ in range(len(my2)+1)]

dpx[0][0] = True
dpy[0][0] = True

for i in range(len(mx2)):
    for j in range(MAX):
        if j<mx2[i]:
            dpx[i+1][j] = dpx[i][j]
        else:
            dpx[i+1][j] = dpx[i][j-mx2[i]] or dpx[i][j]

for i in range(len(my2)):
    for j in range(MAX):
        if j<my2[i]:
            dpy[i+1][j] = dpy[i][j]
        else:
            dpy[i+1][j] = dpy[i][j-my2[i]] or dpy[i][j]


if dpx[len(mx2)][dx] and dpy[len(my2)][dy]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def solve():
    S = input()
    X,Y = map(int, input().split())
    
    S_F = S.split('T')
    move_x = list(map(len, S_F[::2]))
    move_y = list(map(len,S_F[1::2]))
    
    # たどりつけない場合
    if sum(move_x) < abs(X) or sum(move_y) < abs(Y):
        print('No')
        return
    
    # →移動しかできない場合
    if not move_y and len(move_x) == 1 
      if sum(move_x) == X and Y == 0:
        print('Yes')
        return
      if not move_y:
        print('No')
        return

    move_x_process = [mx for mx in move_x if mx > 0]
    move_y_process = [my for my in move_y if my > 0]
    X = abs(X); Y = abs(Y)
    len_move_x = len(move_x_process)
    sum_x = sum(move_x_process)
    len_move_y = len(move_y_process)
    sum_y = sum(move_y_process)

    dp_table = [[False for _ in range(sum_x+1)] for _ in range(len_move_x+1)]
    dp_table[0][0] = True
    
    for i in range(0,len_move_x):
        for j in range(0, sum_x+1):
            dp_table[i+1][j] = dp_table[i][abs(j-move_x_process[i])]
            if j+move_x_process[i] <= sum_x: 
                dp_table[i+1][j] = dp_table[i+1][j] or dp_table[i][j+move_x_process[i]]
    
    # print(dp_table)
    ret = dp_table[len_move_x][X]
    dp_table = [[False for _ in range(sum_y+1)] for _ in range(len_move_y+1)]
    dp_table[0][0] = True
    for i in range(0,len_move_y):
        for j in range(0, sum_y+1):
            # if j-move_x_process[i] >= 0:
            dp_table[i+1][j] = dp_table[i][abs(j-move_y_process[i])]
            if j+move_y_process[i] <= sum_y:
                dp_table[i+1][j] = dp_table[i+1][j] or dp_table[i][j+move_y_process[i]]
    
    ret = ret and dp_table[len_move_y][Y]
    print('Yes' if ret else 'No')
    
solve()

Submission status: Runtime Error

Solution code:
def check(s,x_tag,y_tag):
    x = s.split('T')[::2]
    y = s.split('T')[1::2]

    dp_x = [[False]*16001 for _ in range(len(x)+1)]
    dp_y = [[False]*16001 for _ in range(len(y)+1)]
    dp_x[0][8000], dp_y[0][8000] = True, True
 
    for i,x_s in enumerate(x):
    	if x_s == '':
            continue
        for j,boolean in enumerate(dp_x[i]):
            if boolean:
                dp_x[i+1][j+len(x_s)] = True
                dp_x[i+1][j-len(x_s)] = True
    
    for i,y_s in enumerate(y):
    	if y_s == '':
            continue
        for j,boolean in enumerate(dp_y[i]):
            if boolean:
                dp_y[i+1][j+len(y_s)] = True
                dp_y[i+1][j-len(y_s)] = True
    
    print('Yes' if dp_x[len(x)][x_tag+8000] and dp_y[len(y)][y_tag+8000] else 'No')
    
s = input()
x, y = map(int, input().split())
check(s,x,y)

Submission status: Runtime Error

Solution code:
def check(s,x_tag,y_tag):
    x = s.split('T')[::2]
    y = s.split('T')[1::2]
    while '' in x :
        x.remove('')
    while '' in y :
        y.remove('')
        
    dp_x = [[0]*2**len(x) for _ in range(len(x)+1)]
    dp_y = [[0]*2**len(y) for _ in range(len(y)+1)]

    for i,x_s in enumerate(x):
        for j,x_posi in enumerate(dp_x[i][:2**i]):
            dp_x[i+1][2*j] = x_posi + len(x_s)
            dp_x[i+1][2*j+1] = x_posi - len(x_s)

    for i,y_s in enumerate(y):
        for j,y_posi in enumerate(dp_y[i][:2**i]):
            dp_y[i+1][2*j] = y_posi + len(y_s)
            dp_y[i+1][2*j+1] = y_posi - len(y_s)
    
    for x_posi in dp_x[len(x)]:
        if x_posi == x_tag:
            for y_posi in dp_y[len(y)]:
                if y_posi == y_tag:
                    print('Yes')
                    return
    else:
        print('No')
    
s = input()
x, y = map(int, input().split())

check(s,x,y)

Submission status: Runtime Error

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

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
dpx=[[0]*16001 for i in range(len(lst[0])+1)]
dpy=[[0]*16001 for i in range(len(lst[1])+1)]
dpx[0][8000]=1
dpy[0][8000]=1

for i in range(len(lst[0])):
    for j in range(16001):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(16001):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][8000+x]!=0 and dpy[len(lst[0])][8000+y]!=0:
    print("Yes")
else:
    print("No")
# print(x,lst)

Submission status: Runtime Error

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

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
# print(lst)
sumx=sum(lst[0])
sumy=sum(lst[1])
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1
# print(len(lst[1]),len(dpy))
# print(dpy)

for i in range(len(lst[0])):
    for j in range(sumx*2+1):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(sumy*2+1):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
    print("Yes")
else:
    print("No")
# print(x,lst)