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:
import sys
import itertools
from itertools import accumulate
def main():
    import itertools
    def eratosthenes_sieve(n):
        table = [0] * (n + 1)
        prime_list = []
        for i in range(2, n + 1):
            if table[i] == 0:
                prime_list.append(i)
                for j in range(i + i, n + 1, i):
                    table[j] = 1
        return prime_list
        def inputs():return (int(x) for x in input().split())
    input = sys.stdin.readline
    def inputs():
        return [int(x) for x in input().split()]
    S = list(input())
    x,y=inputs()
    cnt=0
    s =[]
    if S[0]=="T":
        s.append(0)
        cnt+=1
    else:
        cnt+=1
    for i in range(len(S)-2):
        if S[i]==S[i+1]:
            cnt+=1
        else:
            s.append(cnt)
            cnt=1
    s.append(cnt)
    #print(s)
    flag=1
    x1 = []
    y1 = []
    ansx=s[0]
    ansy=0
    flagx=0
    flagy= 0
    for i in range(len(s)):
        if i%2==0:
            if flag==1 and i!=0:
                x1.append(s[i])
            else:
                y1.append(s[i])
        else:
            flag=(flag+s[i])%2
    dpx=[[-1]*(8001) for i in range(len(x1)+1)]
    dpx[0][4000+s[0]]=1
    dpy =[[0]*(8001) for i in range(len(y1)+1)]
    dpy[0][4000]=1
    for i in range(len(x1)):
        for j in range(8000):
            if j+x1[i]<=8000 and dpx[i][j]!=-1:
                dpx[i+1][j+x1[i]]=1
            if j-x1[i]>=0 and dpx[i][j]!=-1:
                dpx[i+1][j-x1[i]]=1      
    for i in range(len(y1)):
        for j in range(8000):
            if j+y1[i]<=8000 and dpy[i][j]!=-1:
                dpy[i+1][j+y1[i]]=1
            elif j-y1[i]>=0 and dpy[i][j]!=-1:
                dpy[i+1][j-y1[i]]=1
    
    if dpx[len(x1)][4000+x]==1 and dpy[len(y1)][4000+y]==1:
        print("Yes")
    else:
        print("No")
main()

Submission status: Runtime Error

Solution code:
#import numpy as np
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

x -= xlist.pop(0)
Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-abs(x))//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-abs(y))//2

#print(Xnum,Ynum)

XDP = [[0]*(Xnum+1) for _ in range(len(xlist)+1)]
YDP = [[0]*(Ynum+1) for _ in range(len(ylist)+1)]

XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(Xnum)
#print(xlist)
#print(XDP)

for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(Ynum)
#print(ylist)
#print(YDP)

if XDP[-1][-1] == 1 and YDP[-1][-1] == 1:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

#print(xlist)
#print(ylist)

Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-x)//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-y)//2

XDP = [[0]*(Xnum+2) for _ in range(len(xlist)+2)]
YDP = [[0]*(Ynum+2) for _ in range(len(ylist)+2)]

XDP[0][0] = 1
XDP[1][0] = 1
if s[0] == "F":
  if xlist[0] <= Xnum+1:
    XDP[1][xlist[0]] = 1
  else:
    print("No")
    exit()
YDP[0][0] = 1

for i in range(2,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(XDP)
for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(YDP)
if XDP[-2][-2] == 1 and YDP[-2][-2] == 1:
  print("Yes")
else:
  print("No")
"""
FFTFFTFFFFTFFFFTFFTFFTFFFFTFFFFTFFTFF
2 2

FFFFFF
2 2
"""

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

#print(xlist)
#print(ylist)

Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-x)//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-y)//2

XDP = [[0]*(Xnum+2) for _ in range(len(xlist)+2)]
YDP = [[0]*(Ynum+2) for _ in range(len(ylist)+2)]

XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum:
        XDP[i][j+xlist[i-1]] = 1
#print(XDP)
for i in range(1,len(ylist)+1):
  for j in range(Ynum):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum:
        YDP[i][j+ylist[i-1]] = 1
#print(YDP)
if XDP[-2][-2] == 1 and YDP[-2][-2] == 1:
  print("Yes")
else:
  print("No")
"""
FFTFFTFFFFTFFFFTFFTFFTFFFFTFFFFTFFTFF
2 2

FFFFFF
2 2
"""

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

#print(xlist)
#print(ylist)

Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-x)//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-y)//2

XDP = [[0]*(Xnum+2) for _ in range(len(xlist)+2)]
YDP = [[0]*(Ynum+2) for _ in range(len(ylist)+2)]

XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(XDP)
for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(YDP)
if XDP[-2][-2] == 1 and YDP[-2][-2] == 1:
  print("Yes")
else:
  print("No")
"""
FFTFFTFFFFTFFFFTFFTFFTFFFFTFFFFTFFTFF
2 2

FFFFFF
2 2
"""

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

#print(xlist)
#print(ylist)

Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-x)//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-y)//2

XDP = [[0]*(Xnum+1) for _ in range(len(xlist)+1)]
YDP = [[0]*(Ynum+1) for _ in range(len(ylist)+1)]
XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(XDP)
for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(YDP)
if XDP[-1][-1] == 1 and YDP[-1][-1] == 1:
  print("Yes")
else:
  print("No")
"""
FFTFFTFFFFTFFFFTFFTFFTFFFFTFFFFTFFTFF
2 2

"""

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
import numpy as np
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

#print(xlist)
#print(ylist)

Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-x)//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-y)//2

XDP = np.array([[0]*(Xnum+1) for _ in range(len(xlist)+1)])
YDP = [[0]*(Ynum+1) for _ in range(len(ylist)+1)]
XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(XDP)
for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(YDP)
if XDP[-1][-1] == 1 and YDP[-1][-1] == 1:
  print("Yes")
else:
  print("No")
"""
FFTFFTFFFFTFFFFTFFTFFTFFFFTFFFFTFFTFF
2 2

"""

Submission status: Runtime Error

Solution code:
S = input()
X, Y = map(int, input().split())
# S = "FT"*4000
# X, Y = 0, 0

m = [len(s) for s in S.split("T")]
X -= m[0]
ud = m[1::2]
lr = m[2::2]

ud_move = 1<<8001
for ud_i in ud:
    ud_move |= ud_move<<ud_i
    ud_move |= ud_move>>ud_i
lr_move = 1<<8001
for lr_i in lr:
    lr_move |= lr_move<<lr_i
    lr_move |= lr_move>>lr_i

# print(ud, lr, (X, Y))

if ud_move>>(8001+Y) == lr_move>>(8001+X) == 1:
    print("Yes")
else:
    print("No")
# print((X, Y), (lr, ud))

Submission status: Runtime Error

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Submission status: Runtime Error

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)

mid = 10
ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Submission status: Runtime Error

Solution code:
s = input()
x,y = map(int,input().split())
 
X = []
Y = []
flag = 0
tmp = 0
for i in s:
    if i == "T":
        if flag == 0:
            if tmp != 0:
                X.append(tmp)
            flag = 1
            tmp = 0
        else:
            if tmp != 0:
                Y.append(tmp)
            flag = 0
            tmp = 0
    else:
        tmp += 1
if tmp != 0:
    if flag == 0:
        X.append(tmp)
    else:
        Y.append(tmp)

if s[0] !="T":
    tmpX = X[0]
    del X[0]
else:
    tmpX = 0

X = sorted(X)
Y = sorted(Y)
sumX = sum(X)
sumY = sum(Y)
tmpY = 0
 
ans = 0
 
if (x+sumX-tmpX)%2 == 1:
    ans = 1
else:
    mokuhyoX = (x+sumX-tmpX)//2
if (y+sumY-tmpY)%2 == 1:
    ans = 1
else:
    mokuhyoY = (y+sumY-tmpY)//2
if mokuhyoX < 0 or mokuhyoY < 0:
    ans = 1

# mokuhyoX
if ans == 0:
    dpX = [[False]*(mokuhyoX+1) for _ in range(len(X)+1)]
    dpX[0][0] = True
    for i in range(len(X)):
        for j in range(mokuhyoX+1):
            dpX[i+1][j] = dpX[i+1][j] or dpX[i][j]
            if j >= X[i]:
                dpX[i+1][j] = dpX[i+1][j] or dpX[i][j-X[i]]
    
    
# mokuhyoY
if ans == 0:
    dpY = [[False]*(mokuhyoY+1) for _ in range(len(Y)+1)]
    dpY[0][0] = True
    for i in range(len(Y)):
        for j in range(mokuhyoY+1):
            dpY[i+1][j] = dpY[i+1][j] or dpY[i][j]
            if j >= Y[i]:
                dpY[i+1][j] = dpY[i+1][j] or dpY[i][j-Y[i]]
 
if ans==0:
    if dpX[len(X)][mokuhyoX] == dpY[len(Y)][mokuhyoY] == True:
        ans = 0
    else:
        ans = 1
    
if ans == 1:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

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

X = []
Y = []
flag = 0
tmp = 0
for i in s:
    if i == "T":
        if flag == 0:
            if tmp != 0:
                X.append(tmp)
            flag = 1
            tmp = 0
        else:
            if tmp != 0:
                Y.append(tmp)
            flag = 0
            tmp = 0
    else:
        tmp += 1
if tmp != 0:
    if flag == 0:
        X.append(tmp)
    else:
        Y.append(tmp)
if s[0] !="T":
    tmpX = X[0]
    del X[0]
else:
    tmpX = 0

X = sorted(X)
Y = sorted(Y)
sumX = sum(X)
sumY = sum(Y)
tmpY = 0

ans = 0

if (x+sumX-tmpX)%2 == 1:
    ans = 1
else:
    mokuhyoX = (x+sumX-tmpX)//2
if (y+sumY-tmpY)%2 == 1:
    ans = 1
else:
    mokuhyoY = (y+sumY-tmpY)//2

# mokuhyoX
if ans == 0:
    dpX = [[False]*(mokuhyoX+1) for _ in range(len(X)+1)]
    dpX[0][0] = True
    for i in range(len(X)):
        for j in range(mokuhyoX+1):
            dpX[i+1][j] = dpX[i+1][j] or dpX[i][j]
            if j >= X[i]:
                dpX[i+1][j] = dpX[i+1][j] or dpX[i][j-X[i]]
    
    
# mokuhyoY
if ans == 0:
    dpY = [[False]*(mokuhyoY+1) for _ in range(len(Y)+1)]
    dpY[0][0] = True
    for i in range(len(Y)):
        for j in range(mokuhyoY+1):
            dpY[i+1][j] = dpY[i+1][j] or dpY[i][j]
            if j >= Y[i]:
                dpY[i+1][j] = dpY[i+1][j] or dpY[i][j-Y[i]]

if ans==0:
    if dpX[len(X)][mokuhyoX] == dpY[len(Y)][mokuhyoY] == True:
        ans = 0
    else:
        ans = 1
    
if ans == 1:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
s = list(map(len,input().split("T")))
x = s[::2]
y = s[1::2]
gx,gy = map(int,input().split())
if sum(x) < abs(gx) or sum(y) < abs(gy):
  print("No")
  exit(0)
dpx = [0]*(len(x)+1)
dpy = [0]*(len(y)+1)
dpx[1] = set(x[0])
dpy[0] = set([0])
for i in range(2,len(x)+1):
  s1 = set([v + x[i-1] for v in dpx[i-1]])
  s2 = set([v - x[i-1] for v in dpx[i-1]])
  dpx[i] = s1|s2
for i in range(1,len(y)+1):
  s1 = set([v + y[i-1] for v in dpy[i-1]])
  s2 = set([v - y[i-1] for v in dpy[i-1]])
  dpy[i] = s1|s2
if gx in dpx[-1] and gy in dpy[-1]:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
## PyPy3 なら通りそう

def ABC082D(Step, Size, advance, Goal):
  ## 初期化
  dp = [[False for j in range(2*Size+1)] for i in range(Step+1)]
  dp[0][Size] = True
  ## DP
  for i in range(Step):
    for j in range(2*Size+1):
      dp[i+1][j] = dp[i][max(j-advance[i],0)] or dp[i][min(j+advance[i],2*Size)] 
  return dp[Step][Goal+Size]


S = input()
X, Y = map(int, input().split())

## 確認用
#S = 'F' *4000
#X, Y = 0, 0

idx_first_T = S.find('T')
if idx_first_T == -1:
  if X == len(S) and Y == 0:
    print('Yes')
  else:
    print('No')
  exit()
else:
  X -= idx_first_T

lst_x = []
lst_y = []
pre_state = 1 ## 0:x-axis, 1:y-axis
advance = 0
for i in range(idx_first_T+1, len(S)):
  if S[i] == 'T':
    if advance > 0:
      if pre_state == 0:
        lst_x.append(advance)
      else:
        lst_y.append(advance)
      advance = 0
    pre_state = (pre_state + 1) % 2
  else:
    advance += 1
else:
  if advance > 0:
    if pre_state == 0:
      lst_x.append(advance)
    else:
      lst_y.append(advance)

if len(lst_x) > 0:
  bool_x = ABC082D(len(lst_x), sum(lst_x), lst_x, X)
else:
  bool_x = (X == 0)

if len(lst_y) > 0:
  bool_y = ABC082D(len(lst_y), sum(lst_y), lst_y, Y)
else:
  bool_y = (Y == 0)
  
if bool_x and bool_y:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
## PyPy3 なら通りそう

def ABC082D(Step, Size, advance, Goal):
  ## 初期化
  dp = [[False for j in range(2*Size+1)] for i in range(Step+1)]
  dp[0][Size] = True
  ## DP
  for i in range(Step):
    for j in range(2*Size+1):
      dp[i+1][j] = dp[i][max(j-advance[i],0)] or dp[i][min(j+advance[i],2*Size)] 
  return dp[Step][Goal+Size]


S = input()
X, Y = map(int, input().split())

idx_first_T = S.find('T')
if idx_first_T == -1:
  if X == len(S) and Y == 0:
    print('Yes')
  else:
    print('No')
  exit()
else:
  X -= idx_first_T

lst_x = []
lst_y = []
pre_state = 1 ## 0:x-axis, 1:y-axis
advance = 0
for i in range(idx_first_T+1, len(S)):
  if S[i] == 'T':
    if advance > 0:
      if pre_state == 0:
        lst_x.append(advance)
      else:
        lst_y.append(advance)
      advance = 0
    pre_state = (pre_state + 1) % 2
  else:
    advance += 1
else:
  if advance > 0:
    if pre_state == 0:
      lst_x.append(advance)
    else:
      lst_y.append(advance)
    
bool_x = ABC082D(len(lst_x), sum(lst_x), lst_x, X)
bool_y = ABC082D(len(lst_y), sum(lst_y), lst_y, Y)
if bool_x and bool_y:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
def main():
    s = list(input())
    s.append("T")
    x,y = map(int,input().split())
    x_list = []
    y_list = []
    count = 0
    n = 0
    for i in range(len(s)+1):
        if s[i] == "F":
            count += 1
        else:
            if n == 0:
                x_list.append(count)
                n = 1
            else:
                y_list.append(count)
                n = 0
            count = 0
    x_def = {0}
    for i in x_list:
        x__def = set()
        for j in x_def:
            x__def.add(j+i)
            x__def.add(j-i)
        x_def = x__def
    if x not in x_def:
        print("No")
        exit()

    y_def = {0}
    for i in y_list:
        y__def = set()
        for j in y_def:
            y__def.add(j+i)
            y__def.add(j-i)
        y_def = y__def
    if y not in y_def:
        print("No")
        exit()
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        xs.append(len(s[i]))
    ys = []
    for i in range(1, len(s), 2):
        ys.append(len(s[i]))
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i-1]
                    dp[i][xs[i-1]:] = dp[i][xs[i-1]] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i-1]
                    dp[i][ys[i-1]:] = dp[i][ys[i-1]] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        xs.append(len(s[i]))
    ys = []
    for i in range(1, len(s), 2):
        ys.append(len(s[i]))
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i-1]
                    dp[i][xs[i-1]:] = dp[i][xs[i-1]] | dp[i-1][:-xs[i-1]]
                    dp[i][:-xs[i-1]] = dp[i][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i-1]
                    dp[i][ys[i-1]:] = dp[i][ys[i-1]] | dp[i-1][:-ys[i-1]]
                    dp[i][:-ys[i-1]] = dp[i][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()
x, y = map(int, input().split())
sx = []
sy = []

#最初の移動は方向が決まってしまっていて邪魔なのでなかったことにします
L = len(s)
s = s.lstrip("F")
x = x-L+len(s)

#この時点で最初の文字は必ずTです
fx = True
c = 0
for i in range(len(s)):
  if s[i] == "T":
    if fx:
      if c != 0:
        sx.append(c)
      c = 0
    else:
      if c != 0:
        sy.append(c)
      c = 0
    fx = not(fx)
  else:
    c += 1
if fx:
  sx.append(c)
else:
  sy.append(c)

sx = sorted(sx)
sy = sorted(sy)
ssx = sum(sx)
ssy = sum(sy)
#print(sx, sy, x, y)

lx = [[0 for i in range(2*ssx+1)] for j in range(len(sx)+1)]
ly = [[0 for i in range(2*ssy+1)] for j in range(len(sy)+1)]

lx[0][ssx] = 1
ly[0][ssy] = 1


for i in range(len(sx)):
  for j in range(2*ssx+1):
    if lx[i][j]==1:
      lx[i+1][j-sx[i]]=1
      lx[i+1][j+sx[i]]=1
for i in range(len(sy)):
  for j in range(2*ssy+1):
    if ly[i][j]==1:
      ly[i+1][j-sy[i]]=1
      ly[i+1][j+sy[i]]=1

if lx[len(sx)][ssx+x]*ly[len(sy)][ssy+y] == 1:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
def isReach( goal, move ):
    msum = sum(move)
    m = len(move)
    dp = [[False]*(msum*2+2) for i in range(m+1)]
    dp[0][0] = True

    for i in range(m):
        for j in range(-msum,msum+1):
            if dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]

s = list( input().split('T') )
x,y = map( int, input().split() )

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move) and isReach(y,y_move):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def isReach( goal, move ):
    msum = sum(move)
    m = len(move)
    dp = [[False]*(msum*2+2) for i in range(m+1)]
    dp[0][0] = True

    for i in range(m):
        for j in range(-msum-1,msum+1):
            if dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]

s = list( input().split('T') )
x,y = map( int, input().split() )

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move) and isReach(y,y_move):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
x+=sum(xarr)
y+=sum(yarr)
if x%2==1 or y%2==1:
  print('No')
else:
  #DP for xarr,yarr
  xdp=[0]*4001
  xdp[0]=1
  for val in xarr:
    for i in range(4000,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*4001
  ydp[0]=1
  for val in yarr:
    for i in range(4000,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Submission status: Runtime Error

Solution code:
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
xarr=sorted(xarr)
yarr=sorted(yarr)
xsums=[0]
for val in xarr:
  xsums.append(xsums[-1]+val)
ysums=[0]
for val in yarr:
  ysums.append(ysums[-1]+val)
if len(xarr)!=0:
  xmax=xarr[-1]
  xsum=xsums[-1]
else:
  xmax=0
  xsum=0
if len(yarr)!=0:
  ymax=yarr[-1]
  ysum=ysums[-1]
else:
  ymax=0
  ysum=0
x+=xsum
y+=ysum
if x%2==1 or y%2==1:
  print('No')
else:
  xdp=[0]*(xsum+xmax+5)
  xdp[0]=1
  for j in range(len(xarr)):
    val=xarr[j]
    for i in range(xsums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*(ysum+ymax+5)
  ydp[0]=1
  for j in range(len(yarr)):
    val=yarr[j]
    for i in range(ysums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Submission status: Runtime Error

Solution code:
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
xarr=sorted(xarr)
yarr=sorted(yarr)
xsums=[0]
for val in xarr:
  xsums.append(xsums[-1]+val)
ysums=[0]
for val in yarr:
  ysums.append(ysums[-1]+val)
xmax=xarr[-1]
ymax=yarr[-1]
xsum=xsums[-1]
ysum=ysums[-1]
x+=xsum
y+=ysum
if x%2==1 or y%2==1:
  print('No')
else:
  xdp=[0]*(xsum+xmax+5)
  xdp[0]=1
  for j in range(len(xarr)):
    val=xarr[j]
    for i in range(xsums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*(ysum+ymax+5)
  ydp[0]=1
  for j in range(len(yarr)):
    val=yarr[j]
    for i in range(ysums[j]+val+1,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Submission status: Runtime Error

Solution code:
s=input()+'T'
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
if len(xarr)!=0:
  xsum=sum(xarr)
else:
  xsum=0
if len(yarr)!=0:
  ysum=sum(yarr)
else:
  ysum=0
x+=xsum
y+=ysum
if x%2==1 or y%2==1:
  print('No')
else:
  xdp=[0]*(xsum+100)
  xdp[0]=1
  for val in xarr:
    for i in range(xsum+99,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*(ysum+100)
  ydp[0]=1
  for val in yarr:
    for i in range(ysum+99,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')