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: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()[: -1]
t = s.split("T")
x, y = map(int, input().split())

xm = t[: : 2]
ym = t[1: : 2]
#print(xm, ym)
dp = [[0] * 16001 for _ in range(len(xm) + 1)]
dp[0][8000] = 1
for i in range(len(xm)):
  for j in range(16001):
    z = len(xm[i])
    if (j + z) in range(16001):
      dp[i + 1][j + z] |= dp[i][j]
    if (j - z) in range(16001):
      dp[i + 1][j - z] |= dp[i][j]
if dp[-1][8000 + x] == 0:
  print("No")
  exit(0)
dp = [[0] * 16001 for _ in range(len(ym) + 1)]
dp[0][8000] = 1
for i in range(len(ym)):
  for j in range(16001):
    z = len(ym[i])
    if (j + z) in range(16001):
      dp[i + 1][j + z] |= dp[i][j]
    if (j - z) in range(16001):
      dp[i + 1][j - z] |= dp[i][j]
if dp[-1][8000 + y] == 0:
  print("No")
  exit(0)
print("Yes")

Submission status: Wrong Answer

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+1) for _ in range(2)]
    dpy=[[False]*(2*N+1) for _ in range(2)]

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

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


    MA=0
    for i in range(Ny):
        MA+=F[1][i]
        for j in range(N-MA,N+MA+1):
            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%2][N+x] and dpy[Ny%2][N+y]:
        print("Yes")
    else:
        print("No")
        
    

main()

Submission status: Wrong Answer

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+1) for _ in range(2)]
    dpy=[[False]*(2*N+1) for _ in range(2)]

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

    for i in range(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
                if i==0 and s[0]=="T":
                    dpx[i%2][j-F[0][i]]=False


    MA=0
    for i in range(Ny):
        MA+=F[1][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%2][N+x] and dpy[Ny%2][N+y]:
        print("Yes")
    else:
        print("No")

main()

Submission status: Wrong Answer

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
    
    if Nx>=1:
        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[1][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: Wrong Answer

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

import copy

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(2)]
dpy=[[False]*(2*N+1) for _ in range(2)]


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

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


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

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

Submission status: Wrong Answer

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=[[0]*(2*N+1) for _ in range(Nx+1)]
dpy=[[0]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=1
if Nx>=1:
    dpx[1][N+F[0][0]]=1
dpy[0][N]=1


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

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

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    s += "T"
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    move = 0
    init = True
    xPossible = {0}
    yPossible = {0}
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: 
                    newSet = set()
                    for item in xPossible:
                        if init:
                            newSet |= {item + move}
                        else:
                            newSet |= {item + move}
                            newSet |= {item - move}
                    xPossible = newSet
                    init = False

                else: 
                    newSet = set()
                    for item in yPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    yPossible = newSet
            move = 0
            direc = (direc + 1) % 2
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    move = 0
    init = True
    xPossible = {0}
    yPossible = {0}
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: 
                    newSet = set()
                    for item in xPossible:
                        if init:
                            newSet |= {item + move}
                        else:
                            newSet |= {item + move}
                            newSet |= {item - move}
                    xPossible = newSet
                    init = False

                else: 
                    newSet = set()
                    for item in yPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    yPossible = newSet
            move = 0
            direc = (direc + 1) % 2
    if move > 0:
        if direc == 0:
            newSet = set()
            for item in xPossible:
                if init: newSet |= {item + move}
                else:
                    newSet |= {item + move}
                    newSet |= {item - move}
            xPossible = newSet
        else: 
            newSet = set()
            for item in yPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            yPossible = newSet
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    move = 0
    init = True
    xPossible = {0}
    yPossible = {0}
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: 
                    newSet = set()
                    for item in xPossible:
                        if init:
                            newSet |= {item + move}
                        else:
                            newSet |= {item + move}
                            newSet |= {item - move}
                    xPossible = newSet
                    init = False

                else: 
                    newSet = set()
                    for item in yPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    yPossible = newSet
            move = 0
            direc = (direc + 1) % 2
    if move > 0:
        if direc == 0:
            newSet = set()
            for item in xPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            xPossible = newSet
        else: 
            newSet = set()
            for item in yPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            yPossible = newSet
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    move = 0
    xPossible = {0}
    yPossible = {0}
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: 
                    newSet = set()
                    for item in xPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    xPossible = newSet

                else: 
                    newSet = set()
                    for item in yPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    yPossible = newSet
            move = 0
            direc = (direc + 1) % 2
    if move > 0:
        if direc == 0:
            newSet = set()
            for item in xPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            xPossible = newSet
        else: 
            newSet = set()
            for item in yPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            yPossible = newSet
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    move = 0
    xPossible = {0}
    yPossible = {0}
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: 
                    newSet = set()
                    for item in xPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    xPossible = newSet

                else: 
                    newSet = set()
                    for item in yPossible:
                        newSet |= {item + move}
                        newSet |= {item - move}
                    yPossible = newSet
            move = 0
            direc = (direc + 1) % 2
    if move > 0:
        if direc == 0:
            newSet = set()
            for item in xPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            xPossible = newSet
        else: 
            newSet = set()
            for item in xPossible:
                newSet |= {item + move}
                newSet |= {item - move}
            Possible = newSet
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    lens = len(s)
    x, y = map(int, input().split())
    direc = 0 #0はx軸方向、１はy軸方向への移動
    xMove, yMove = [], []
    move = 0
    for i in range(lens):
        if s[i] == "F": move += 1
        else:
            if move > 0:
                if direc == 0: xMove.append(move)
                else: yMove.append(move)
            move = 0
            direc = (direc + 1) % 2
    if move > 0:
        if direc == 0: xMove.append(move)
        else: yMove.append(move)

    xPossible = {0}
    yPossible = {0}
    for i, xn in enumerate(xMove):
        newSet = set()
        for item in xPossible:
            newSet |= {item + xn}
            newSet |= {item - xn}
        xPossible = set()
        xPossible |= newSet
    
    for i, yn in enumerate(xMove):
        newSet = set()
        for item in yPossible:
            newSet |= {item + yn}
            newSet |= {item - yn}
        yPossible = set()
        yPossible |= newSet
    
    #print(xPossible)
    #print(yPossible)

    if x in xPossible and y in yPossible: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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)

if len(mx):
    x -= mx[0]
    mx[0] = 0
    mx2[0] = 0
        
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')

elif dx>sum(mx2) or dy>sum(my2):
    print('No')

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

Submission status: Wrong Answer

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)

if len(mx):
    x -= mx[0]
    mx[0] = 0
    mx2[0] = 0
if len(my):
    y -= my[0]
    my[0] = 0
    my2[0] = 0
    
        
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')

elif dx>sum(mx2) or dy>sum(my2):
    print('No')

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

Submission status: Wrong Answer

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')

elif dx>sum(mx2) or dy>sum(my2):
    print('No')

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

Submission status: Wrong Answer

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 = len(s)*2 + 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: Wrong Answer

Solution code:
def get_move(S):
    S = S.split("T")
    x_move = [len(x) for x in S[0::2]]
    y_move = [len(x) for x in S[1::2]]
    return x_move, y_move


def check(x, move):
    move.sort()
    while move:
        m = move.pop()
        if x >= 0:
            x -= m
        else:
            x += m
    return x == 0


if __name__ == "__main__":
    S = input()
    x, y = map(int, input().split())

    x_move, y_move = get_move(S)

    if check(x, x_move) and check(y, y_move):
        ans = "Yes"
    else:
        ans = "No"

    print(ans)

Submission status: Wrong Answer

Solution code:
def get_move(S):
    x_move = [0]
    y_move = [0]

    now = 0
    yoko = 1
    for i, s in enumerate(S, start=1):
        if s == "T":
            if yoko:
                x_move.append(i - now - 1)
            else:
                y_move.append(i - now - 1)
            now = i
            yoko = 1 - yoko
    return x_move, y_move
    

def check(x, move):
    move.sort()
    while move:
        m = move.pop()
        if x >= 0:
            x -= m
        else:
            x += m
    return x == 0


if __name__ == "__main__":
    S = input() + "T"    #結果に関係ないやつを入れておくと良い感じになる
    x, y = map(int, input().split())

    x_move, y_move = get_move(S)

    if check(x, x_move) and check(y, y_move):
        ans = "Yes"
    else:
        ans = "No"

    print(ans)

Submission status: Wrong Answer

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 len(move_x) == 1:
        if sum(move_x) != X:
            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: Wrong Answer

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
      else:
        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: Wrong Answer

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 sum(move_x) == X and Y == 0:
      print('Yes')
      return
    elif 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: Wrong Answer

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
    
    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: Wrong Answer

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

S = list(map(len, s.split("T")))
Sx = []
Sy = []

for i in range(len(S)):
  if i % 2 == 0:
    Sx.append(S[i])
  else:
    Sy.append(S[i])

maxX = sum(Sx)
maxY = sum(Sy)

setX = set([maxX])
for i in Sx:
  li = list(setX)
  for a in li:
    setX.add(a - 2*i)
    
setY = set([maxY])
for i in Sy:
  li = list(setY)
  for a in li:
    setY.add(a - 2*i)
    
if x in setX and y in setY:
  print("Yes")
else:
  print("No")