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:
s=input()
x,y=map(int, input().split())
x += 9000
y += 9000
cx=[]
cy=[]
dirx=1
l=0
ini=1
for i in range(len(s)):
  if s[i] == "F":
    l += 1
  else:
    if ini:
      x -= l
      ini = 0
    else:
      if dirx:
        cx.append(l)
      else:
        cy.append(l)
    l = 0
    dirx = not dirx

if ini == 0:
  if dirx:
    cx.append(l)
  else:
    cy.append(l)

#print(cx)
#print(cy)


ng = 0
dp = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cx) ):
  dpn = [0 for i in range(18000)] 
  for j in range( 18000 ):
    if j+cx[i] < 18000:
      dpn[j+cx[i]] |= dp[j]
    if j-cx[i] > 0:
      dpn[j-cx[i]] |= dp[j]
#  for j in range( 8995,9005 ):
#    print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[x] == 0:
  ng = 1
  print(x, dp[x])
  
dp = [0 for i in range(18000)] 
dp[9000] = 1;
for i in range( len(cx) ):
  dpn = [0 for i in range(18000)] 
  for j in range( 18000 ):
    if j+cy[i] < 18000:
      dpn[j+cy[i]] |= dp[j]
    if j-cy[i] > 0:
      dpn[j-cy[i]] |= dp[j]
#  for j in range( 8995,9005 ):
#    print( str(dpn[j])+" ", end="")
#  print("")
  dpn, dp = dp, dpn
  
if dp[y] == 0:
  ng = 1
  print(y, dp[y])

if ng==0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
dic={"x":"y","y":"x"}

a = list(input())
X,Y = map(int,input().split())

direction = "x"
cersol = 0
while cersol < len(a) and a[cersol] == "F":
    cersol+=1
    X -= 1#これは確定した動きなので目的地をずらす方が楽

move = {"x":[],"y":[]}

while cersol < len(a):
    if a[cersol]=="T":#ターンならターン
        direction=dic[direction]
        cersol+=1

    count = 0
    while cersol < len(a) and a[cersol] == "F":
        count+=1
        cersol+=1
    
    move[direction].append(count)


able = {}
preable = {0:0}
for i in move["x"]:
    able={}
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable=able


ableX = able

able = {0:0}
preable = {0:0}
for i in move["y"]:
    able = {}
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable=able

if (X in ableX)and(Y in able):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
dic={"x":"y","y":"x"}

a = list(input())
X,Y = map(int,input().split())

direction = "x"
cersol = 0
while cersol < len(a) and a[cersol] == "F":
    cersol+=1
    X -= 1#これは確定した動きなので目的地をずらす方が楽

move = {"x":[],"y":[]}

while cersol < len(a):
    if a[cersol]=="T":#ターンならターン
        direction=dic[direction]
        cersol+=1

    count = 0
    while cersol < len(a) and a[cersol] == "F":
        count+=1
        cersol+=1
    
    move[direction].append(count)


able = {}
preable = {0:0}
for i in move["x"]:
    able={}
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable=able


ableX = able

able = {}
preable = {0:0}
for i in move["y"]:
    able = {}
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable=able

if (X in ableX)and(Y in able):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
dic={"x":"y","y":"x"}

a = list(input())
X,Y = map(int,input().split())

direction = "x"
cersol = 0
while cersol < len(a) and a[cersol] == "F":
    cersol+=1
    X -= 1#これは確定した動きなので目的地をずらす方が楽

move = {"x":[],"y":[]}

while cersol < len(a):
    if a[cersol]=="T":#ターンならターン
        direction=dic[direction]
        cersol+=1

    count = 0
    while cersol < len(a) and a[cersol] == "F":
        count+=1
        cersol+=1
    
    move[direction].append(count)


able = {}
preable = {0:0}
for i in move["x"]:
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable={}

ableX = able

able = {}
preable = {0:0}
for i in move["y"]:
    for j in preable:
        able[j+i]=0
        able[j-i]=0
    preable={}

if (X in ableX)and(Y in able):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().strip()
x, y = map(int, sys.stdin.readline().split())

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
x_init = 0
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            if x_init == 0:
                x_init = d
            else:
                dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    cand = set()
    if mode == "x":
        cand.add(x_init)
    else:
        cand.add(0)
    for i in range(len_d):
        next_cand = set()
        for d in cand:
            next_cand.add(d + dist[mode][i])
            next_cand.add(d - dist[mode][i])
        cand = next_cand

    if goal[mode] not in cand:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().strip()
x, y = map(int, sys.stdin.readline().split())

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    cand = set([0])
    for i in range(len_d):
        next_cand = set()
        for d in cand:
            next_cand.add(d + dist[mode][i])
            next_cand.add(d - dist[mode][i])
        cand = next_cand

    if goal[mode] not in cand:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
s=input()+'T'
x,y=list(map(int,input().split()))
x+=8000
y+=8000
n=len(s)
i=0

while i<n and s[i]=='F':
    i+=1

dx=[[0]*16001 for _ in range(2)]
dy=[[0]*16001 for _ in range(2)]

dx[0][i+8000]=1
dy[0][8000]=1

lstx=[]
lsty=[]
d='x'
cnt=0

while i<n:
    if s[i]=='F':
        cnt+=1
    else:
        if cnt>0:
            if d=='x':
                lstx.append(cnt)
            else:
                lsty.append(cnt)
        
        if d=='x':
            d='y'
        else:
            d='x'
        cnt=0
    
    i+=1

for i,cx in enumerate(lstx):
    for j in range(16001):
        if dx[i%2][j]==0:
            continue
        if j+cx<16001:
            dx[(i+1)%2][j+cx]=1
        if j-cx>-1:
            dx[(i+1)%2][j-cx]=1

for i,cy in enumerate(lsty):
    for j in range(16001):
        if dy[i%2][j]==0:
            continue
        if j+cy<16001:
            dy[(i+1)%2][j+cy]=1
        if j-cy>-1:
            dy[(i+1)%2][j-cy]=1

if dx[(len(lstx))%2][x]==1 and dy[(len(lsty))%2][y]==1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from copy import copy
s = input() + "T"
x,y = map(int, input().split())
 
d = [len(p) for p in s.split("T")]
x = d[0]
d_x = d[2::2]
d_y = d[1::2]
 
xs = set([x])
ys = set([0])
dpx = [x in xs]
for d in d_x:
  xs_ = set()
  for x in xs:
    xs_.add(x+d)
    xs_.add(x-d)
  dpx.append(x in xs_)
  xs = copy(xs_)

dpy = []
for d in d_y:
  ys_ = set()
  for y in ys:
    ys_.add(y+d)
    ys_.add(y-d)
  dpy.append(y in ys_)
  ys = copy(ys_)

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

Submission status: Wrong Answer

Solution code:
s = input().strip()
N = len(s)
x,y = map(int,input().split())
flag0 = 0
for i in range(N):
    if s[i]=="T":
        ind = i
        flag0 = 1
        break
if flag0==0:
    if y==0 and x==N:
        print("Yes")
    else:
        print("No")
else:
    C={"x":[],"y":[]}
    flag=0
    cnt = 0
    for i in range(ind+1,N):
        if s[i]!="T":
            cnt += 1
        else:
            if flag==0 and cnt>0:
                C["y"].append(cnt)
            elif flag==1 and cnt>0:
                C["x"].append(cnt)
            cnt = 0
            flag = 1-flag
    if flag==0:
        C["y"].append(cnt)
    else:
        C["x"].append(cnt)
    nx = len(C["x"])
    xlim = 0
    for i in range(nx):
        xlim += C["x"][i]
    ny = len(C["y"])
    ylim = 0
    for i in range(ny):
        ylim += C["y"][i]
    x = x-ind  #x>=-N
    if x<=-xlim-1 or x>=xlim+1 or y<=-ylim-1 or y>=ylim+1:
        print("No")
    else:
        dp1 = {(i,j):0 for i in range(nx+1) for j in range(-xlim,xlim+1)}
        dp1[(0,0)]=1
        for i in range(1,nx+1):
            for j in range(-xlim,xlim+1):
                dp1[(i,j)] = dp1[(i-1,j)]
                if j-C["x"][i-1]>=-xlim:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j-C["x"][i-1])]
                if j+C["x"][i-1]<=xlim:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j+C["x"][i-1])]
        dp0 = {(i,j):0 for i in range(ny+1) for j in range(-ylim,ylim+1)}
        dp0[(0,0)] = 1
        for i in range(1,ny+1):
            for j in range(-ylim,ylim+1):
                dp0[(i,j)] = dp0[(i-1,j)]
                if j-C["y"][i-1]>=-ylim:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j-C["y"][i-1])]
                if j+C["y"][i-1]<=ylim:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j+C["y"][i-1])]
        if dp1[(nx,x)]==1 and dp0[(ny,y)]==1:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
s = input().strip()
N = len(s)
x,y = map(int,input().split())
flag0 = 0
for i in range(N):
    if s[i]=="T":
        ind = i
        flag0 = 1
        break
if flag0==0:
    if y==0 and x==N:
        print("Yes")
    else:
        print("No")
else:
    C={"x":[],"y":[]}
    flag=0
    cnt = 0
    for i in range(ind+1,N):
        if s[i]!="T":
            cnt += 1
        else:
            if flag==0 and cnt>0:
                C["y"].append(cnt)
            elif flag==1 and cnt>0:
                C["x"].append(cnt)
            cnt = 0
            flag = 1-flag
    if flag==0:
        C["y"].append(cnt)
    else:
        C["x"].append(cnt)
    nx = len(C["x"])
    x = x-ind  #x>=-N
    if x<-N:
        print("No")
    else:
        dp1 = {(i,j):0 for i in range(nx+1) for j in range(-N,N+1)}
        dp1[(0,0)]=1
        for i in range(1,nx+1):
            for j in range(-N,N+1):
                dp1[(i,j)] = dp1[(i-1,j)]
                if j-C["x"][i-1]>=-N:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j-C["x"][i-1])]
                if j+C["x"][i-1]<=N:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j+C["x"][i-1])]
        ny = len(C["y"])
        dp0 = {(i,j):0 for i in range(ny+1) for j in range(-N,N+1)}
        dp0[(0,0)] = 1
        for i in range(1,ny+1):
            for j in range(-N,N+1):
                dp0[(i,j)] = dp0[(i-1,j)]
                if j-C["y"][i-1]>=-N:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j-C["y"][i-1])]
                if j+C["y"][i-1]<=N:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j+C["y"][i-1])]
        if dp1[(nx,x)]==1 and dp0[(ny,y)]==1:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
x,y = map(int,input().split())
X = []; Y =[]
Flag = True #Trueならx軸、Falseならy軸
seq = 0
for i in range(N):
  if S[i] == "T":
    if Flag and seq != 0:
      X.append(seq)
    if not Flag and seq != 0:
      Y.append(seq)
    Flag = not Flag
    seq = 0
  else:
    seq += 1
    if i == N-1:
      if Flag and seq != 0:
        X.append(seq)
      if not Flag and seq != 0:
        Y.append(seq)
#print(X,Y)
num = 8100 #真ん中
MAX = num*2+1
#X方向i回目でjにいる
dpx = [0 for _ in range(MAX)]
dpx[num] = 1
dpy = [0 for _ in range(MAX)]
dpy[num] = 1
for i in range(len(X)):
  px = [0 for _ in range(MAX)]
  px,dpx = dpx,px
  step = X[i]
  for j in range(MAX):
    if j -step >= 0:
      dpx[j] = max(dpx[j],px[j-step])
    if j + step < MAX:
      dpx[j] = max(dpx[j],px[j+step])
for i in range(len(Y)):
  py = [0 for _ in range(MAX)]
  py,dpy = dpy,py
  step = Y[i]
  for j in range(MAX):
    if j -step >= 0:
      dpy[j] = max(dpy[j],py[j-step])
    if j + step < MAX:
      dpy[j] = max(dpy[j],py[j+step])
x += num;y+= num
#print(dpx)
#print(dpy)
if dpx[x] == 1 and dpy[y] == 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
x,y = map(int,input().split())
X = []; Y =[]
Flag = True #Trueならx軸、Falseならy軸
seq = 0
for i in range(N):
  if S[i] == "T":
    if Flag:
      X.append(seq)
    else:
      Y.append(seq)
    Flag = not Flag
    seq = 0
  else:
    seq += 1
    if i == N-1:
      if Flag:
        X.append(seq)
      else:
        Y.append(seq)
#print(X,Y)
num = 8100 #真ん中
MAX = num*2+1
#X方向i回目でjにいる
dpx = [[0 for _ in range(MAX)] for _ in range(len(X)+1)]
dpx[0][num] = 1
dpy = [[0 for _ in range(MAX)] for _ in range(len(Y)+1)]
dpy[0][num] = 1
for i in range(len(X)):
  step = X[i]
  for j in range(MAX):
    if j -step >= 0:
      dpx[i+1][j] = max(dpx[i+1][j],dpx[i][j-step])
    if j + step < MAX:
      dpx[i+1][j] = max(dpx[i+1][j],dpx[i][j+step])
for i in range(len(Y)):
  step = Y[i]
  for j in range(MAX):
    if j -step >= 0:
      dpy[i+1][j] = max(dpy[i+1][j],dpy[i][j-step])
    if j + step < MAX:
      dpy[i+1][j] = max(dpy[i+1][j],dpy[i][j+step])
x += num;y+= num
#print(dpx)
#print(dpy)
if dpx[-1][x] == 1 and dpy[-1][y] == 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import copy

def main():
  s = input()
  x, y = map(int, input().split())
  
  n = len(s)
  
  X = [False]*(2*n+1)
  Y = [False]*(2*n+1)
  
  judge = True
  judge2 = True
  count = 0
  X[n] = True
  Y[n] = True
  
  for j in range(n+1):
    if j == n or s[j] == "T":
      if judge:
        if judge2:
          X[n+count] = True
          X[n] = False
        else:
          X2 = [False]*(2*n+1)
          for i in range(2*n+1):
            if i-count >= 0 and X[i-count]:
              X2[i] = True
            if i+count <= 2*n and X[i+count]:
              X2[i] = True
          X = copy.deepcopy(X2)
      else:
        Y2 = [False]*(2*n+1)
        for i in range(2*n+1):
          if i-count >= 0 and Y[i-count]:
            Y2[i] = True
          if i+count <= 2*n and Y[i+count]:
            Y2[i] = True
        Y = copy.deepcopy(Y2)
      judge = False if judge else True
      judge2 = False
      count = 0
      continue
    
    count += 1
  
  if X[n+x] and Y[n+y]:
    print("Yes")
  else:
    print("No")
    
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

n = len(s)

X, Y = 0, 0
key = 0
judge = True
judge2 = True

for i in range(n):
  if s[i] == "T":
    judge = False if judge else True
    judge2 = False
    continue

  if judge:
    if judge2:
      key += 1
    else:
      X += 1
  else:
    Y += 1

x -= key

if abs(x) <= X and x%2 == X%2 and abs(y) <= Y and y%2 == Y%2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

n = len(s)

X, Y = 0, 0
key = 0
judge = True
judge2 = True

for i in range(n):
  if s[i] == "T":
    judge = False if judge else True
    judge2 = False
    continue

  if judge:
    if judge2:
      key += 1
    else:
      X += 1
  else:
    Y += 1

if abs(x-key) <= X and (x-key)%2 == X%2 and abs(y) <= Y and y%2 == Y%2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

n = len(s)

X, Y = 0, 0
key = 0
judge = True
judge2 = True

for i in range(n):
  if s[i] == "T":
    judge = False if judge else True
    judge2 = False
    continue

  if judge:
    if judge2:
      key += 1
    else:
      X += 1
  else:
    Y += 1
print(X, Y, key)
if abs(x-key) <= X and (x-key)%2 == X%2 and abs(y) <= Y and y%2 == Y%2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

n = len(s)

X, Y = 0, 0
key = 0
judge = True
judge2 = True
for i in range(n):
  if s[i] == "T":
    judge = False if judge else True
    if not judge:
      judge2 = False
    continue
  if judge:
    if judge2:
      key += 1
    else:
      X += 1
  else:
    Y += 1

if abs(x-key) <= X and (x-key)%2 == X%2 and abs(y) <= Y and y%2 == Y%2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import copy
Ss = input() + "T"
X,Y = map(int, input().split())

d = [len(s) for s in Ss.split("T")]
x = d[0]
# x,y方向に分解
d_x = d[2::2]
d_y = d[1::2]
# print(d_x,d_y)

xs = set([x])
ys = set([0])
blx = [X in xs]
from copy import copy
for d in d_x:
    xs_ = set()
    for x in xs:
        xs_.add(x+d)
        xs_.add(x-d)
    blx.append(X in xs_)
    xs = copy(xs_)
bly = []
for d in d_y:
    ys_ = set()
    for y in ys:
        ys_.add(y+d)
        ys_.add(y-d)
    bly.append(Y in ys_)
    ys = copy(ys_)


bx = blx[0]
for i in range(1,len(Ss.split("T"))):
    if i % 2 == 0:
        bx = blx[i//2]
    elif i % 2 == 1:
        by = bly[i//2]
    if bx and by: 
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
import copy
Ss = input()
X,Y = map(int, input().split())

d = [len(s) for s in Ss.split("T")]
x = d[0]
# x,y方向に分解
d_x = d[2::2]
d_y = d[1::2]
# print(d_x,d_y)

xs = set([x])
ys = set([0])
blx = [X in xs]
from copy import copy
for d in d_x:
    xs_ = set()
    for x in xs:
        xs_.add(x+d)
        xs_.add(x-d)
    blx.append(X in xs_)
    xs = copy(xs_)

bly = []
for d in d_y:
    ys_ = set()
    for y in ys:
        ys_.add(y+d)
        ys_.add(y-d)
    bly.append(Y in ys_)
    ys = copy(ys_)


bx = blx[0]
for i in range(1,len(Ss.split("T"))):
    if i % 2 == 0:
        bx = blx[i//2]
    elif i % 2 == 1:
        by = bly[i//2]
    if bx and by: 
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
import copy
Ss = input()
x,y = map(int, input().split())

direc = 0 #x軸方向
Ss = Ss + "T"
prev = Ss[0]

if prev == "F":
    cnt = 1
    direc = -1 #初回はx正のみ
else:
    cnt = 0
    direc = 1
mvs = []
for S in Ss[1:]:
    if prev == "F" and S == "F":
        cnt += 1
    elif prev == "F" and S == "T":
        mvs.append((direc, cnt))
        if direc == -1:
            direc = 1
        else:
            direc ^= 1
        cnt = 0
    elif prev == "T" and S == "F":
        cnt += 1
    else:
        direc ^= 1
    prev = S
cs = set()
cs.add(0) #初期
for direc, dist in mvs:
    cs_tmp = copy.copy(cs)
    for c in cs_tmp:
        if direc == -1:
            cs.add(c+dist)
        if direc == 0:
            cs.add(c+dist)
            cs.add(c-dist)
        else:
            cs.add(c+8000*dist)
            cs.add(c-8000*dist)
# print(cs)
# print(y*8000+x)
if y*8000+x in cs:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

direc = 0 #x軸方向
Ss = Ss + "T"
prev = Ss[0]
if prev == "F":
    cnt = 1
    direc = 0
else:
    cnt = 0
    direc = 1
mvs = []
for S in Ss[1:]:
    if prev == "F" and S == "F":
        cnt += 1
    elif prev == "F" and S == "T":
        mvs.append((direc, cnt))
        direc ^= 1
        cnt = 0
    elif prev == "T" and S == "F":
        cnt += 1
    else:
        direc ^= 1
    prev = S
print(mvs)
import copy
cs = set()
cs.add(0) #初期
for direc, dist in mvs:
    cs_tmp = copy.copy(cs)
    for c in cs_tmp:
        if direc == 0:
            cs.add(c+dist)
            cs.add(c-dist)
        else:
            cs.add(c+8000*dist)
            cs.add(c-8000*dist)
print(cs)
print(y*8000+x)
if y*8000+x in cs:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(3000)


Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = list(filter(lambda x:x>0, sorted(Fseq[0::2])))[::-1]
Fseq_y = list(filter(lambda x:x>0, sorted(Fseq[1::2])))[::-1]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0 or target < 0 or target > sum(seq):
        return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Wrong Answer

Solution code:
s=input()+'T'
N=len(s)
x, y=map(int, input().split())

X=[]
Y=[]
i=0
j=0
k=0
while i<N:
  if s[i]=='F':
    k+=1
  else:
    if j==0:
      X.append(k)
    else:
      Y.append(k)
    j=(j+1)%2
    k=0
  i+=1

dp=set([0])
for s in X:
  tmp=set()
  for t in dp:
    tmp.add(t-s)
    tmp.add(t+s)
  dp=tmp
  
if x in dp:
  pass
else:
  print('No')
  exit()
  
dp=set([0])
for s in Y:
  tmp=set()
  for t in dp:
    tmp.add(t-s)
    tmp.add(t+s)
  dp=tmp
  
if y in dp:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s=input()+'T'
N=len(s)
x, y=map(int, input().split())

X=[]
Y=[]
i=0
j=0
k=0
while i<N:
  if s[i]=='F':
    k+=1
  else:
    if j==0:
      X.append(k)
    else:
      Y.append(k)
    j=(j+1)%2
    k=0
  i+=1

X=sorted(X, reverse=True)
Xnums=[0, abs(x)]
for s in X:
  if Xnums[0]>Xnums[1]:
    Xnums[1]+=s
  else:
    Xnums[0]+=s
    
Y=sorted(Y, reverse=True)
Ynums=[0, abs(y)]
for t in Y:
  if Ynums[0]>Ynums[1]:
    Ynums[1]+=t
  else:
    Ynums[0]+=t
    
if Xnums[0]==Xnums[1] and Ynums[0]==Ynums[1]:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
def main():

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

    n = len(s)

    cnt = 0
    nx = 0
    ny = 0
    for i in range(n):
        if s[i] == 'F':
            if cnt%2 == 0:
                nx += 1
            else:
                ny += 1
        else:
            cnt += 1

    D = 8000*2+1
    d = 8000

    import numpy as np
    dpx = [0]*(nx+1)
    dpy = [0]*(ny+1)
    dpx[0] = np.zeros(D, np.bool)
    dpy[0] = np.zeros(D, np.bool)
    dpx[0][d] = 1
    dpy[0][d] = 1
    for i in range(nx):
        if i == 0:
            b = np.zeros(D, np.bool)
            b[1:] |= dpx[i][:D-1]
            dpx[i+1] = b
        else:
            b = np.zeros(D, np.bool)
            b[1:] |= dpx[i][:D-1]
            b[:D-1] |= dpx[i][1:]
            dpx[i+1] = b

    for i in range(ny):
        b = np.zeros(D, np.bool)
        b[1:] |= dpy[i][:D-1]
        b[:D-1] |= dpy[i][1:]
        dpy[i+1] = b

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()+"T"
x,y=map(int,input().split())
n=len(s)
prev=-1
cnt=0
x_,y_=[],[]
for i in range(n):
    if s[i]=="T":
        if cnt%2:
            if i-prev>1:
                y_.append(i-prev-1)
        else:
            if i-prev>1:
                x_.append(i-prev-1)
        cnt+=1
        prev=i
prevx=[0]*(2*n+1)
prevy=[0]*(2*n+1)
prevx[n]=1
prevy[n]=1
for num in x_:
    curx=[0]*(2*n+1)
    for i in range(2*n+1):
        if prevx[i]:
            if i-num>=0:
                curx[i-num]=1
            if i+num<=2*n:
                curx[i+num]=1
    prevx=curx
for num in y_:
    cury=[0]*(2*n+1)
    for i in range(2*n+1):
        if prevy[i]:
            if i-num>=0:
                cury[i-num]=1
            if i+num<=2*n:
                cury[i+num]=1
    prevy=cury
if prevy[y+n] and prevx[x+n]:
    print("Yes")
else:
    print("No")
#print(x_)
#print(y_)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

now_x = [0]
now_y = [0]

if len(s1) > 0:
    x-= s1[0]
    s1 = s1[1:]

for i in s1:
    nx = set()
    for j in now_x:
        nx.add(j-i)
        nx.add(j+i)
    now_x = nx

for i in s2:
    ny = set()
    for j in now_y:
        ny.add(j-i)
        ny.add(j+i)
    now_y = ny

if x in now_x and y in now_y:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = list(input())
x, y = map(int, input().split())
cs = Counter(s)

ss = []
idx = 0
cnt = 0
while idx < len(s):
    if s[idx] == 'F':
        cnt += 1
    else:
        if cnt != 0:
            ss += [cnt]
        ss += [0]
        cnt = 0

    idx += 1

    if idx == len(s):
        if cnt != 0:
            ss += [cnt]

p = [[], []]
now = 0

for i in ss:
    if i == 0:
        now = abs(1-now)
    else:
        p[now] += [i]

s1 = p[0]
s2 = p[1]

now_x = [0]
now_y = [0]

for i in s1:
    nx = set()
    for j in now_x:
        nx.add(j-i)
        nx.add(j+i)
    now_x = nx

for i in s2:
    ny = set()
    for j in now_y:
        ny.add(j-i)
        ny.add(j+i)
    now_y = ny

if x in now_x and y in now_y:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
MAX_SIZE = 16_001
OFFSET = 8_000

X = [[False for _ in range(MAX_SIZE)] for _ in range(2)]
Y = [[False for _ in range(MAX_SIZE)] for _ in range(2)]

s = input()
x, y = input().split()
N = len(s)
x, y = int(x), int(y)

i = 0
d = 0
j = 0
while i < N and s[i] == 'F':
    d += 1
    i += 1
X[j][d + OFFSET] = True

i += 1
d = 0
while i < N and s[i] == 'F':
    d += 1
    i += 1
i += 1
Y[j][d + OFFSET] = True
Y[j][-d + OFFSET] = True

j += 1
while i < N:
    d = 0
    while i < N and s[i] == 'F':
        d += 1
        i += 1
    for k in range(MAX_SIZE):
        if k - d >= 0 and k + d < MAX_SIZE:
            X[j % 2][k] = X[(j - 1) % 2][k - d] or X[(j - 1) % 2][k + d]
        elif k - d >= 0:
            X[j % 2][k] = X[(j - 1) % 2][k - d]
        elif k + d < MAX_SIZE:
            X[j % 2][k] = X[(j - 1) % 2][k + d]
    i += 1
    d = 0
    while i < N and s[i] == 'F':
        d += 1
        i += 1
    for k in range(MAX_SIZE):
        if k - d >= 0 and k + d < MAX_SIZE:
            Y[j % 2][k] = Y[(j - 1) % 2][k - d] or Y[(j - 1) % 2][k + d]
        elif k - d >= 0:
            Y[j % 2][k] = Y[(j - 1) % 2][k - d]
        elif k + d < MAX_SIZE:
            Y[j % 2][k] = Y[(j - 1) % 2][k + d]
    i += 1
    j += 1

if (X[(j - 1) % 2][x + OFFSET] and Y[j % 2][y + OFFSET]):
    print('Yes')
else:
    print('No')