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:
# https://atcoder.jp/contests/abc082/tasks/arc087_b


def run_length_encoding(s):
    '''
    連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx
    '''
    s_composed = []
    s_sum = []
    s_idx = [0]
    pre = s[0]
    cnt = 1
    for i, ss in enumerate(s[1:], start=1):
        if pre == ss:
            cnt += 1
        else:
            s_sum.append(cnt)
            s_composed.append(pre)
            s_idx.append(i)
            cnt = 1
            pre = ss
    s_sum.append(cnt)
    s_composed.append(pre)
    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx

# データに関しては事前にランレングス圧縮しておくと楽かもね


s = input()
x, y = map(int, input().split())
s_composed, s_sum, _ = run_length_encoding(s)

if s_composed[0] == 'T':  # 必ずTから始まるようにしたい
    s_composed.insert(0, 'F')
    s_sum.insert(0, 0)
# 前処理 xの移動履歴とyの移動履歴を作る
is_x = True
hist_x = []
hist_y = []
for s, n in zip(s_composed, s_sum):
    if s == 'T':
        if n & 1:  # xyの状態を反転させる
            is_x = not is_x
    else:
        if is_x:
            hist_x.append(n)
        else:
            hist_y.append(n)

'''
dpx[i][j]...x座標がjであることが可能か？ x方向の移動についてi回目の移動のあとに。
dpy[i][j]...y座標がjであることが可能か？ y方向の移動についてi回目の移動のあとに。

更新則
xについての移動,距離d移動するとすると
dpx[i+1][j+d]=dpx[i+1][j+d] or dpx[i][j]
dpx[i+1][j-d]=dpx[i+1][j-d] or dpx[i][j]
(配るDP)で更新すると楽かな？
yも同様

初期条件
dpx[:][:]=False
dpx[0][d_x0]=True #xの0回目の移動。

dpy[:][:] = False
dpy[0][d_y0]=True 簡単のために
dpy[0][-d_y0]=True
'''

# if hist_x:
#     x_range = 2 * sum(hist_x) + 100
#     shift = x_range // 2
#     dpx = [[False] * x_range for _ in range(len(hist_x))]
#     dpx[0][hist_x[0] + shift] = True
#     for i in range(1, len(hist_x)):
#         d = hist_x[i]
#         for j in range(x_range):
#             if j + d < x_range:
#                 dpx[i][j] = dpx[i][j] or dpx[i - 1][j + d]
#             if -1 < j - d:
#                 dpx[i][j] = dpx[i][j] or dpx[i - 1][j - d]
#     ansx = dpx[-1][x + shift]

# if hist_y:
#     y_range = 2 * sum(hist_y) + 100
#     shift = y_range // 2
#     dpy = [[False] * y_range for _ in range(len(hist_y))]
#     dpy[0][hist_y[0] + shift] = True
#     dpy[0][-hist_y[0] + shift] = True
#     for i in range(1, len(hist_y)):
#         d = hist_y[i]
#         for j in range(y_range):
#             if j + d < y_range:
#                 dpy[i][j] = dpy[i][j] or dpy[i - 1][j + d]
#             if -1 < j - d:
#                 dpy[i][j] = dpy[i][j] or dpy[i - 1][j - d]
#     ansy = dpy[-1][y + shift]
# else:
#     ansy = True if y == 0 else False

# print('Yes' if ansx and ansy else 'No')


# print(ansx, ansy)
# print(*dpy, sep='\n')

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x_list,y_list = [],[]
l = s.split('T')

for i in range(0,len(l),2):
  x_list.append(len(l[i]))
for i in range(1,len(l),2):
  y_list.append(len(l[i]))

ans_x,ans_y = [],[]

if s[0]=='F':
  ans_x.append(x_list[0])
  x_list=x_list[1:]
else:
  ans_x.append(0)
ans_y.append(0)

for i in x_list:
  for j in ans_x:
    ans = []
    ans.append(i+j)
    ans.append(j-i)
  ans_x = ans
for i in y_list:
  for j in ans_y:
    ans = []
    ans.append(i+j)
    ans.append(j-i)
  ans_y = ans
if x in ans_x and y in ans_y:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x_list,y_list = [],[]
l = s.split('T')

for i in range(0,len(l),2):
  x_list.append(len(l[i]))
for i in range(1,len(l),2):
  y_list.append(len(l[i]))

ans,ans_x,ans_y = [],[],[]

for i in x_list:
  for j in x_list:
    ans.append(i+j)
    ans.append(j-i)
  ans_x = ans
for i in y_list:
  for j in y_list:
    ans.append(i+j)
    ans.append(j-i)
  ans_y = ans
if x in ans_x and y in ans_y:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x_list,y_list = [],[]
l = s.split('T')

for i in range(0,len(l),2):
  x_list.append(len(l[i]))
for i in range(1,len(l),2):
  y_list.append(len(l[i]))

ans,ans_x,ans_y = [],[],[]

for i in x_list:
  for j in x_list:
    ans.append(i+j)
    ans.append(i-j)
  ans_x = ans
for i in y_list:
  for j in y_list:
    ans.append(i+j)
    ans.append(i-j)
  ans_y = ans
if x in ans_x and y in ans_y:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x_list,y_list = [],[]
l = s.split('T')
lenS = len(s)
for i in range(0,len(l),2):
  x_list.append(len(l[i]))
for i in range(1,len(l),2):
  y_list.append(len(l[i]))

x,y = abs(x),abs(y)

succes = 0
lenX = len(x_list)

for b in range(2**lenX):
  ans = 0
  b = bin(b)[2:].zfill(lenX)
  for i in range(lenX):
    if b[i] == "1":
      ans += x_list[i]
    else:
      ans -= x_list[i]
  if abs(ans) == x:
    succes += 1
    break

lenY = len(y_list)

for b in range(2**lenY):
  ans = 0
  b = bin(b)[2:].zfill(lenY)
  for i in range(lenY):
    if b[i] == "1":
      ans += y_list[i]
    else:
      ans -= y_list[i]
  if abs(ans) == y:
    succes += 1
    break

if succes == 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x,y = abs(x),abs(y)
lenS = len(s)
x_list,y_list = [10000]*lenS,[10000]*lenS
f_count,t_count = 0,0
for i in range(lenS):
  if s[i] == "F" and i == lenS-1:
    if t_count%2 == 0:
      x_list[i] = f_count+1
    else:
      y_list[i] = f_count+1
  elif s[i] == "T" or i == lenS-1:
    if t_count%2 == 0:
      x_list[i] = f_count
    else:
      y_list[i] = f_count
    t_count += 1
    f_count = 0
  else:
    f_count += 1
x_list = [s for s in x_list if s != 10000]
y_list = [s for s in y_list if s != 10000]
succes = 0
lenX = len(x_list)

for b in range(2**lenX):
  ans = 0
  b = bin(b)[2:].zfill(lenX)
  for i in range(lenX):
    if b[i] == "1":
      ans += x_list[i]
    else:
      ans -= x_list[i]
  if abs(ans) == x:
    succes += 1
    break

lenY = len(y_list)

for b in range(2**lenY):
  ans = 0
  b = bin(b)[2:].zfill(lenY)
  for i in range(lenY):
    if b[i] == "1":
      ans += y_list[i]
    else:
      ans -= y_list[i]
  if abs(ans) == y:
    succes += 1
    break

if succes == 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
x,y = map(int,input().split())
x,y = abs(x),abs(y)
x_list,y_list = [],[]
f_count,t_count = 0,0

for i in range(len(s)):
  if s[i] == "F" and i == len(s)-1:
    if t_count%2 == 0:
      x_list.append(f_count+1)
    else:
      y_list.append(f_count+1)
  elif s[i] == "T" or i == len(s)-1:
    if t_count%2 == 0:
      x_list.append(f_count)
    else:
      y_list.append(f_count)
    t_count += 1
    f_count = 0
  else:
    f_count += 1

succes = 0
lenX = len(x_list)

for b in range(2**lenX):
  ans = 0
  b = bin(b)[2:].zfill(lenX)
  for i in range(lenX):
    if b[i] == "1":
      ans += x_list[i]
    else:
      ans -= x_list[i]
  if abs(ans) == x:
    succes += 1
    break

lenY = len(y_list)

for b in range(2**lenY):
  ans = 0
  b = bin(b)[2:].zfill(lenY)
  for i in range(lenY):
    if b[i] == "1":
      ans += y_list[i]
    else:
      ans -= y_list[i]
  if abs(ans) == y:
    succes += 1
    break

if succes == 2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = list(input())
x, y = list(map(int, input().split()))
to_x = True
count = 0
xf, yf = [], []
for i in s:
    if i == 'T':
        if count == 0:
            to_x = not to_x
            continue
        elif to_x:
            xf.append(count)
            to_x = not to_x
            count = 0
            continue
        else:
            yf.append(count)
            to_x = not to_x
            count = 0
            continue
    else:
        count += 1
if s[-1] == 'F':
    if to_x:
        xf.append(count)
    else:
        yf.append(count)

x_can, y_can = False, False
for i in range(2 ** len(xf)):
    xfp = [xf[j] if i >> j & 1 else -xf[j] for j in range(len(xf))]
    if sum(xfp) == x:
        x_can = True
        break
for i in range(2 ** len(yf)):
    yfp = [yf[j] if i >> j & 1 else -yf[j] for j in range(len(yf))]
    if sum(yfp) == y:
        y_can = True
        break
if x_can and y_can:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int, input().split())
xy = [0,0]
now = 0
mode = 1
for i in s:
  if mode:
    if i == "F":
      x -= 1
    else:
      mode = 0
      now ^= 1
  else:
    if i == "F":
      xy[now] += 1
    else:
      now ^= 1
X,Y = xy
if (X >= abs(x)) and (X % 2 == x % 2) and (Y >= abs(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())
xy = [0,0]
now = 0
for i in s:
  if i == "F":
    xy[now] += 1
  else:
    now ^= 1
X,Y = xy
if (X >= abs(x)) and (X % 2 == x % 2) and (Y >= abs(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())
    
fn = [len(n) for n in s.split("T")]
l = []
r = []
for i in range(len(fn)):
    if i%2 == 0:
        l.append(fn[i])
    else:
        r.append(fn[i])
x -= l[0]
l.pop(0)

l.sort()
r.sort()

for i in l:
    if x > 0:
        x -= i
    else:
        x += i
for i in r:
    if y > 0:
        y -= i
    else:
        y += i

if x != 0 or y != 0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
    
fn = [len(n) for n in s.split("T")]
l = []
r = []
for i in range(len(fn)):
    if i%2 == 0:
        l.append(fn[i])
    else:
        r.append(fn[i])
x -= l[0]
l.pop(0)

l.sort()
r.sort()

for i in l:
    if x > i:
        x -= i
    else:
        x += i
for i in r:
    if y > i:
        y -= i
    else:
        y += i

if x != 0 or y != 0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int,input().split())
L = [len(i) for i in s.split('T')]
X = sum(L[2::2])
Y = sum(L[1::2])
x -= L[0]
if X >= abs(x) and Y >= abs(y) and (X - x) % 2 == 0 and (Y - y) % 2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    X, Y = map(int, input().split())
    D = [(1, 0), (0, -1), (-1, 0), (0, 1)]
    L = [[0], [0]]
    d = 0
    for s in S:
        if s == 'T':
            d = 1 - d
            if L[d][-1] != 0:
                L[d].append(0)
        else:
            L[d][-1] += 1
    xs, ys = set([0]), set([0])
    for i in L[0]:
        xs = set(x + i for x in xs) | set(x - i for x in xs)
    for i in L[1]:
        ys = set(y + i for y in ys) | set(y - i for y in ys)
    return X in xs and Y in ys

print('Yes' if main() else 'No')

Submission status: Wrong Answer

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

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])

startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
start_i = 0 # Fで始まる場合は後続処理で2つ目の要素から見ていく
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  start_i = 1

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(start_i,len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
        dpXcur = dpXnex
        dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
        dpYcur = dpYnex
        dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
MOD=10**9+7
def divc(x,y): return -(-x//y)
def divf(x,y): return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers"""
    is_prime = [True] * MAX_NUM
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(MAX_NUM):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_NUM, i):
                is_prime[j] = False
    return primes
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    s = IS()
    x, y = MII()
    ff = s.split('T')
    ffx = [len(f) for f in ff[::2]]
    ffy = [len(f) for f in ff[1::2]]

    nx = ffx.pop(0)
    ny = 0

    for fx in ffx:
        if x >= nx: nx += fx
        else: nx -= fx
    for fy in ffy:
        if y >= ny: ny += fy
        else: ny -= fy

    if nx == x and ny == y: print('Yes')
    else: print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
MOD=10**9+7
def divc(x,y): return -(-x//y)
def divf(x,y): return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers"""
    is_prime = [True] * MAX_NUM
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(MAX_NUM):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_NUM, i):
                is_prime[j] = False
    return primes
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    s = IS()
    x, y = MII()
    ff = s.split('T')
    ffx = [len(f) for f in ff[::2]]
    ffy = [len(f) for f in ff[1::2]]

    nx = ffx.pop(0)
    ny = 0

    ffx.sort(reverse=True)
    ffy.sort(reverse=True)

    for fx in ffx:
        if x >= nx: nx += fx
        else: nx -= fx
    for fy in ffy:
        if y >= fy: ny += fy
        else: ny -= fy

    if nx == x and ny == y: print('Yes')
    else: print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
MOD=10**9+7
def divc(x,y): return -(-x//y)
def divf(x,y): return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers"""
    is_prime = [True] * MAX_NUM
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(MAX_NUM):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_NUM, i):
                is_prime[j] = False
    return primes
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    s = IS()
    x, y = MII()
    ff = s.split('T')
    ffx = [len(f) for f in ff[::2]]
    ffy = [len(f) for f in ff[1::2]]

    nx = ffx.pop(0)
    ny = 0

    for fx in ffx:
        if x >= nx: nx += fx
        else: nx -= fx
    for fy in ffy:
        if y >= fy: ny += fy
        else: ny -= fy

    if nx == x and ny == y: print('Yes')
    else: print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if S.find("F") < 0:
    if X != 0 or Y != 0:
        print("No")
    else:
        print("Yes")
    exit()

n = len(S)
d = list(map(len, S.split("T")))
xs = d[::2]
ys = d[1::2]

dpx = [set() for _ in range(len(xs) + 1)]
dpx[0].add(0)
for i in range(len(xs)):
    for j in dpx[i]:
        dpx[i + 1].add(j + xs[i])
        dpx[i + 1].add(j - xs[i])

dpy = [set() for _ in range(len(ys) + 1)]
dpy[0].add(0)
for i in range(len(ys)):
    for j in dpy[i]:
        dpy[i + 1].add(j + ys[i])
        dpy[i + 1].add(j - ys[i])

ans = (X in dpx[-1]) & (Y in dpy[-1])
print("Yes" if ans else "No")

Submission status: Wrong Answer

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

if S.find("F") < 0:
    if X != 0 or Y != 0:
        print("No")
    else:
        print("Yes")
    exit()

n = len(S)
d = list(map(len, S.split("T")))
xs = d[::2]
ys = d[1::2]

ans = True
print("Yes" if ans else "No")

Submission status: Wrong Answer

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

n = len(S)
xs = list(map(len, S.split("T")[::2]))
ys = list(map(len, S.split("T")[1::2]))

if all(v == 0 for v in xs):
    xs = []

dpx = [[False] * (2 * n + 1) for _ in range(len(xs))]
for i in range(len(xs)):
    if i == 0:
        d = (-1) ** S.find("F")
        dpx[i][d * xs[i] + n] = True
        continue

    for j in range(2 * n + 1):
        if j + xs[i] <= 2 * n:
            dpx[i][j] |= dpx[i - 1][j + xs[i]]
        if 0 <= j - xs[i] <= 2 * n:
            dpx[i][j] |= dpx[i - 1][j - xs[i]]

ys = [0] + ys
if all(v == 0 for v in ys):
    ys = []

dpy = [[False] * (2 * n + 1) for _ in range(len(ys))]
for i in range(len(ys)):
    if i == 0:
        dpy[i][n] = True
        continue

    for j in range(2 * n + 1):
        if j + ys[i] <= 2 * n:
            dpy[i][j] |= dpy[i - 1][j + ys[i]]
        if 0 <= j - ys[i] <= 2 * n:
            dpy[i][j] |= dpy[i - 1][j - ys[i]]

ans = True
if dpx:
    ans &= dpx[-1][X + n]
if dpy:
    ans &= dpy[-1][Y + n]
if not dpx and not dpy:
    ans = False
print("Yes" if ans else "No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
cur_x = 0
cur_y = 0
L_x = []
L_y = []
s += 'K'
temp = 0
dirc = 'yoko'
for i in range(len(s)):
    if s[i] == 'F':
        temp += 1
    elif s[i] == 'T':
        if temp == 0:
            if dirc == 'yoko':
                dirc = 'tate'
            else:
                dirc = 'yoko'
        else:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
    else:
        if temp != 0:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
dp_x = [[False]*8001 for i in range(len(L_x)+1)]
dp_y = [[False]*8001 for i in range(len(L_y)+1)]
dp_x[0][0] = True
dp_y[0][0] = True
if s[0] != 'F':
    for i in range(1,len(L_x)+1):
        for j in range(8001):
            if j+L_x[i-1] <= 8000:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])] or dp_x[i-1][j+L_x[i-1]]
            else:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])]
    for i in range(1,len(L_y)+1):
        for j in range(8001):
            if j+L_y[i-1] <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
            else:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
    if dp_x[len(L_x)][abs(x)] == True and dp_y[len(L_y)][abs(y)] == True:
        print('Yes')
    else:
        print('No')
else:
    for i in range(2,len(L_x)+1):
        for j in range(8001):
            if j+L_x[i-1] <= 8000:
                dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])] or dp_x[i-2][j+L_x[i-1]]
            else:
                dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])]
    for i in range(1,len(L_y)+1):
        for j in range(8001):
            if j+L_y[i-1] <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
            else:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
    if 1 == 2:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
cur_x = 0
cur_y = 0
L_x = []
L_y = []
s += 'K'
temp = 0
dirc = 'yoko'
for i in range(len(s)):
    if s[i] == 'F':
        temp += 1
    elif s[i] == 'T':
        if temp == 0:
            if dirc == 'yoko':
                dirc = 'tate'
            else:
                dirc = 'yoko'
        else:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
    else:
        if temp != 0:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
dp_x = [[False]*8001 for i in range(len(L_x)+1)]
dp_y = [[False]*8001 for i in range(len(L_y)+1)]
dp_x[0][0] = True
dp_y[0][0] = True
if s[0] != 'F':
    for i in range(1,len(L_x)+1):
        for j in range(8001):
            if j+L_x[i-1] <= 8000:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])] or dp_x[i-1][j+L_x[i-1]]
            else:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])]
    for i in range(1,len(L_y)+1):
        for j in range(8001):
            if j+L_y[i-1] <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
            else:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
    if dp_x[len(L_x)][abs(x)] == True and dp_y[len(L_y)][abs(y)] == True:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
cur_x = 0
cur_y = 0
L_x = []
L_y = []
s += 'K'
temp = 0
dirc = 'yoko'
for i in range(len(s)):
    if s[i] == 'F':
        temp += 1
    elif s[i] == 'T':
        if temp == 0:
            if dirc == 'yoko':
                dirc = 'tate'
            else:
                dirc = 'yoko'
        else:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
    else:
        if temp != 0:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
dp_x = [[False]*8001 for i in range(len(L_x)+1)]
dp_y = [[False]*8001 for i in range(len(L_y)+1)]
dp_x[0][0] = True
dp_y[0][0] = True
if s[0] != 'F':
    print(1)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
"""Knapsack"""
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
s = input().rstrip()
gx, gy = map(int, input().split())
rx, ry = 0, 0
head, inst = 0, []
while head < len(s) and s[head] == "F":
    head += 1
    rx += 1

xlist, ylist = [], []
heading_x = True
while head < len(s):
    tcnt = 0
    while head < len(s) and s[head] == "T":
        tcnt += 1
        head += 1
    if head == len(s):
        break
    fcnt = 0
    while head < len(s) and s[head] == "F":
        fcnt += 1
        head += 1
    if ((tcnt % 2) == 1) ^ heading_x:
        heading_x = True
        xlist.append(fcnt)
    else:
        heading_x = False
        ylist.append(fcnt)


def fill(fs, goal_offset):
    f_total = sum(fs)
    if f_total < goal_offset:
        return False
    if f_total == goal_offset:
        return True
    f_diff = f_total - goal_offset
    diffs = {0}
    for f in fs:
        for d in list(diffs):
            d2 = f + d
            if d2 > f_diff:
                continue
            if d2 == f_diff:
                return True
            diffs.add(d2)
    return False


if fill(xlist, abs(gx - rx)) and fill(ylist, abs(gy - ry)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import heapq
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
s = input().rstrip()
gx, gy = map(int, input().split())
rx, ry = 0, 0
head, inst = 0, []
while head < len(s) and s[head] == "F":
    head += 1
    rx += 1
while head < len(s):
    tcnt = 0
    while head < len(s) and s[head] == "T":
        tcnt += 1
        head += 1
    fcnt = 0
    while head < len(s) and s[head] == "F":
        fcnt += 1
        head += 1
    inst.append((tcnt % 2, fcnt))

f_total = sum([f for (_, f) in inst])
f_rem = [0] * (len(inst) + 1)
f_rem[len(inst)] = 0
for i in range(len(inst) - 1, -1, -1):
    f_rem[i] = f_rem[i + 1] + inst[i][1]
assert f_rem[0] == f_total


visited = set()


def reach():
    hp = [(abs(gx) + abs(gy), 0, rx, ry, 1, 0)]
    while hp:
        dist, i, x, y, dx, dy = heapq.heappop(hp)
        # print(f"i={i} ({x},{y}) dist={dist}: inst={inst[i:]}")
        if i == len(inst):
            if dist == 0:
                return True
            continue
        if (i, x, y, dx, dy) in visited:
            continue
        visited.add((i, x, y, dx, dy))
        if dist > f_rem[i]:
            continue
        t, f = inst[i]
        if t:
            dy, dx = dx, -dy
        for sdx, sdy in [(dx, dy), (-dx, -dy)]:
            dist = abs(gx - x - f * sdx) + abs(gy - y - f * sdy)
            heapq.heappush(hp, (dist, i + 1, x + f * sdx, y + f * sdy, sdx, sdy))
    return False


print("Yes" if reach() else "No")

Submission status: Wrong Answer

Solution code:
from itertools import groupby


s=input()
x,y=map(int,input().split())
data=[s[i] for i in range(0,len(s))]
data=groupby(data)
LR=[]
UD=[]
point='LR'
flag=0
checkx=2**8000
for key,group in data:
    g=len(list(group))
    if key=='F':
        if flag==0:
            checkx<<g
            flag=1
        else:
            if point=='LR':
                LR.append(g)
            else:
                UD.append(g)
    else:
        if g%2==1:
            if point=='LR':
                point='UD'
            else:
                point='LR'
        flag=1


for i in range(0,len(LR)):
    checkx=(checkx<<LR[i])|(checkx>>LR[i])

checky=2**8000
for i in range(0,len(UD)):
    checky=(checky<<UD[i])|(checky>>UD[i])


if checkx>>(x+8000) &1==1 and checky>>(y+8000) &1==1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
x,y=map(int,input().split())
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    elif s[i]=="T":
        if kaisi==0:
            kaisi=1
            x-=tmp
        elif flag==0:
            flag=1
            yoko.append(tmp)
        else:
            flag=0
            tate.append(tmp)
        tmp=0


if kaisi==0:
    kaisi=1
    x-=tmp
elif flag==0:
    flag=1
    yoko.append(tmp)
else:
    flag=0
    tate.append(tmp)

if sum(yoko)==0 and sum(tate)==0:
    if x==0 and y==0:
        print("Yes")
    else:
        print("No")
    quit()
# print(yoko,tate)

if x>sum(yoko) or y>sum(tate):
    print("No")
    quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1
# print(yokolst)
# print(tatelst)
for i in range(len(tate)):
    for j in range(len(tatelst[0])):
        if tatelst[i][j]==1:
            tatelst[i+1][j+tate[i]]=1
            tatelst[i+1][j-tate[i]]=1


for i in range(len(yoko)):
    for j in range(len(yokolst[0])):
        if yokolst[i][j]==1:
            yokolst[i+1][j+yoko[i]]=1
            yokolst[i+1][j-yoko[i]]=1


# print(yokolst)
# print(tatelst)

if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
    print("Yes")
else:
    print("No")