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:
def knapsack(target, queue):
    if target == 0 and len(queue) == 0:
        return True
    """
    TLE !!
    
    s = []
    s_new = []
    for i in queue:
        if i == target:
            return True
        elif i > target:
            continue
        else:
            s_new.append(i)
        
            for j in reversed(s):
                if i+j == target:
                    return True
                elif i+j > target:
                    continue
                else:
                    s_new.append(i+j)
            else:
                s.extend(s_new)
                s = list(set(s))

    else:
        return False
    """

    dp = [[0 for _ in range(target+1)]
             for _ in range(len(queue)+1)]
    
    for i in range(len(queue))[::-1]:
        for j in range(target+1):
            if j < queue[i]:
                dp[i][j] = dp[i+1][j]
            else:
                dp[i][j] = max(dp[i+1][j],
                               dp[i+1][j-queue[i]] + queue[i])
            
    if dp[0][target] == target:
        return True
    else:
        return False


string = input()
x,y = map(int, input().split())

x_seg = []
y_seg = []

axis = True #:x, False:y
segment = 0

# init
for char in string:
    if char == "F":
        segment += 1
    else:
        if segment:
            if axis:
                x_seg.append(segment)
            else:
                y_seg.append(segment)
        segment = 0
        axis = not(axis)
else:
    if segment:
        if axis:
            x_seg.append(segment)
        else:
            y_seg.append(segment)

# judge-possible (quick)
x_shrink = sum(x_seg)-x
y_shrink = sum(y_seg)-y
if x_shrink < 0 or x_shrink % 2 or \
   y_shrink < 0 or y_shrink % 2:
       print("No")

# judge-route (01-knapsack)
elif x_shrink == 0:
    if y_shrink == 0:
        print("Yes")
    else:
        y_shrink //= 2
        y_seg.sort()
        if knapsack(y_shrink, y_seg):
            print("Yes")
        else:
            print("No")
else:
    x_shrink //= 2
    x_seg.sort()
    if knapsack(x_shrink, x_seg):
        if y_shrink == 0:
            print("Yes")
        else:
            y_shrink //= 2
            y_seg.sort()
            if knapsack(y_shrink, y_seg):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Wrong Answer

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

firstx = 0
k = 0
while s[k] == 'F':
	firstx += 1
	k += 1
if k == 0:
	while k <= n:
		if s[k] == 'T':
			k += 1
			change = change*(-1)
		else:
			break

nowx = firstx
nowy = 0
counter = 0
for i in range(k,n+1):
	if s[i] == 'F' and change == 1 and nowx <= x:
		counter += 1
	elif s[i] == 'F' and change == 1 and nowx > x:
		counter = counter - 1
	elif s[i] == 'F' and change == -1 and nowy <= y:
		counter = counter + 1
	elif s[i] == 'F' and change == -1 and nowy > y:
		counter = counter - 1
	elif s[i] == 'T':
		if change == 1:
			nowx += counter
			counter = 0
			change = change*(-1)
		else:
			nowy += counter
			counter = 0
			change = change*(-1)

if x == nowx and y == nowy:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
def knapsack(target, queue):
    if target == 0 and len(queue) == 0:
        return True
    s = []
    s_new = []
    for i in queue:
        if i == target:
            return True
        elif i > target:
            continue
        else:
            s_new.append(i)
        
            for j in reversed(s):
                if i+j == target:
                    return True
                elif i+j > target:
                    continue
                else:
                    s_new.append(i+j)
            else:
                s.extend(s_new)
                s = list(set(s))

    else:
        return False


string = input()
x,y = map(int, input().split())

x_seg = []
y_seg = []

axis = True #:x, False:y
segment = 0

# init
for char in string:
    if char == "F":
        segment += 1
    else:
        if segment:
            if axis:
                x_seg.append(segment)
            else:
                y_seg.append(segment)
        segment = 0
        axis = not(axis)
else:
    if segment:
        if axis:
            x_seg.append(segment)
        else:
            y_seg.append(segment)

# judge-possible (quick)
x_shrink = sum(x_seg)-x
y_shrink = sum(y_seg)-y
if x_shrink < 0 or x_shrink % 2 or \
   y_shrink < 0 or y_shrink % 2:
       print("No")

# judge-route (01-knapsack)
elif x_shrink == 0:
    if y_shrink == 0:
        print("Yes")
    else:
        y_shrink //= 2
        y_seg.sort()
        if knapsack(y_shrink, y_seg):
            print("Yes")
        else:
            print("No")
else:
    x_shrink //= 2
    x_seg.sort()
    if knapsack(x_shrink, x_seg):
        if y_shrink == 0:
            print("Yes")
        else:
            y_shrink //= 2
            y_seg.sort()
            if knapsack(y_shrink, y_seg):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import product
def inpl(): return tuple(map(int, input().split()))
   

S = input()
x, y = inpl()
M = []

d = 0
for s in S:
    if s == "F":
        d += 1
    else:
        M.append(d)
        d = 0
M.append(d)

Cx = Counter(M[::2])
Cy = Counter(M[1::2])

Lx = []
Ly = []

for k, v in Cx.items():
    if k == 0:
        pass
    else:
        Lx.append(list(range(-k*v, k*v+1, 2*k)))
        
for k, v in Cy.items():
    if k == 0:
        pass
    else:
        Ly.append(list(range(-k*v, k*v+1, 2*k)))

def bfss(Ls, t):
    N = set([0])
    for L in Ls:
        nN = set()
        nN.update([n+l for n, l in product(N, L)])
        N = nN
    if t in N:
        return True
    else:
        return False

if bfss(Lx, x) and bfss(Ly, y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

firstx = 0
k = 0
while s[k] == 'F':
	firstx += 1
	k += 1

nowx = firstx
nowy = 0
counter = 0
for i in range(k+1,n+1):
	if s[i] == 'F' and change == 0 and nowx <= x:
		counter += 1
	elif s[i] == 'F' and change == 0 and nowx > x:
		counter = counter - 1
	elif s[i] == 'F' and change == 1 and nowy <= y:
		counter = counter + 1
	elif s[i] == 'F' and change == 1 and nowy > y:
		counter = counter - 1
	elif s[i] == 'T':
		if change == 0:
			nowx += counter
			counter = 0
			change = 1
		else:
			nowy += counter
			counter = 0
			change = 0

if x == nowx and y == nowy:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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

n = 8000
fs = list(map(len, s.split('T')))
x -= fs[0]
dx = []
dy = []
for i in range(1, len(fs)):
    if fs[i] == 0:
        continue
    if i % 2 == 0:
        dx.append(fs[i])
    else:
        dy.append(fs[i])
dpx = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpy = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpx[0][2 * n] = True
dpy[0][2 * n] = True
for i in range(len(dx)):
    for j in range(4 * n + 1):
        if dpx[i % 2][j]:
            if 0 <= j - dx[i]:
                dpx[(i + 1) % 2][j - dx[i]] = True
            if j + dx[i] <= 4 * n:
                dpx[(i + 1) % 2][j + dx[i]] = True
for i in range(len(dy)):
    for j in range(4 * n + 1):
        if dpy[i % 2][j]:
            if 0 <= j - dy[i]:
                dpy[(i + 1) % 2][j - dy[i]] = True
            if j + dy[i] <= 4 * n:
                dpy[(i + 1) % 2][j + dy[i]] = True
ix = 2 * n + x
iy = 2 * n + y
if 0 <= ix <= 4 * n and dpx[len(dx) % 2][ix] and 0 <= iy <= 4 * n and dpy[len(dy) % 2][iy]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import collections
S = input()
x,y = list(map(int, input().split()))
f_nums = collections.defaultdict(int)
f_count=0

for i in range(len(S)):
    if S[i] == 'F':
        f_nums[f_count] += 1
    else:
        f_count+=1

x_f = [0 for i in range(f_count+1)]
y_f = [0 for i in range(f_count+1)]
x_count=0
y_count=0

for i in range(f_count+1):
    if i%2 == 0:
        x_f[i//2] = f_nums[i]
        x_count+=1
    else:
        y_f[(i-1)//2] = f_nums[i]
        y_count+=1

x_f.sort(reverse=True)
y_f.sort(reverse=True)
temp_sumx=0
temp_sumy=0

for i in range(x_count):
    if abs(temp_sumx-x+x_f[i]) <= abs(temp_sumx-x-x_f[i]):
        temp_sumx += x_f[i]
    else:
        temp_sumx -= x_f[i]

for i in range(y_count):
    if abs(temp_sumy-y+y_f[i]) <= abs(temp_sumy-y-y_f[i]):
        temp_sumy += y_f[i]
    else:
        temp_sumy -= y_f[i]

if x == temp_sumx and y == temp_sumy:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
s=input()+"T"
x,y=[int(i) for i in input().split()]


dx=[]
dy=[]

dir_is_X=True
step=0
for char in s:
        if char=='F':
                step+=1
        else:
                if dir_is_X:
                        dx.append(step)
                        dir_is_X=False
                        step=0
                else:
                        dy.append(step)
                        step=0
                        dir_is_X=True
#print(dx)
#print(dy)
nowX=set([0])
#print(type(nowX))
nextX=set([])
nowY=set([0])
nextY=set([])

for num in dx:
        #print(type(nextX))
        for now in nowX:
                nextX.add(now+num)
                nextX.add(now-num)
        nowX=deepcopy(nextX)
        nextX=set([])
for num in dy:
        for now in nowY:
                nextY.add(now+num)
                nextY.add(now-num)
        nowY=deepcopy(nextY)
        nextY=set([])
if (x in nowX) and (y in nowY):
        print("Yes")
else:
        print("No")

Submission status: Wrong Answer

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

n = 5
fs = list(map(len, s.split('T')))
x -= fs[0]
dx = []
dy = []
for i in range(1, len(fs)):
    if fs[i] == 0:
        continue
    if i % 2 == 0:
        dx.append(fs[i])
    else:
        dy.append(fs[i])
dpx = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpy = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpx[0][2 * n] = True
dpy[0][2 * n] = True
for i in range(len(dx)):
    for j in range(4 * n + 1):
        if dpx[i % 2][j]:
            if 0 <= j - dx[i]:
                dpx[(i + 1) % 2][j - dx[i]] = True
            if j + dx[i] <= 4 * n:
                dpx[(i + 1) % 2][j + dx[i]] = True
for i in range(len(dy)):
    for j in range(4 * n + 1):
        if dpy[i % 2][j]:
            if 0 <= j - dy[i]:
                dpy[(i + 1) % 2][j - dy[i]] = True
            if j + dy[i] <= 4 * n:
                dpy[(i + 1) % 2][j + dy[i]] = True
ix = 2 * n + x
iy = 2 * n + y
if 0 <= ix <= 4 * n and dpx[len(dx) % 2][ix] and 0 <= iy <= 4 * n and dpy[len(dy) % 2][iy]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    xa, ya = map(int, input().split())
    xset = set([0])
    yset = set([0])

    if "T" not in s:
        print("Yes" if len(s) == xa and ya == 0 else "No")
        return

    fcnt = 0
    tcnt = 0
    for c in s:
        if "T" == c:
            if fcnt > 0:
                if tcnt % 2 == 0:
                    xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
                else:
                    yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
            fcnt = 0
            tcnt += 1
        if "F" == c:
            fcnt += 1

    if fcnt > 0:
        if tcnt % 2 == 0:
            xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
        else:
            yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
    
    print("Yes" if (xa in xset) and (ya in yset) else "No")

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:

def search(arr, start):
    s = set()
    s.add(start)
    for i in arr:
        ns = set()
        for j in s:
            ns.add(j+i)
            ns.add(j-i)
        s = ns
    return s

def main():
    t = 0
    xd, yd = [], []

    inst = list(input())
    x, y = list(map(int, input().split()))

    xcum = 0
    ycum = 0
    first = True

    startx = 0
    for s in inst:
        if s == 'T':
            t += 1
            t %= 2
            if first:
                startx = xcum
                xcum = 0
                first = False
                continue
            if xcum > 0:
                xd.append(xcum)
                xcum = 0
            if ycum > 0:
                yd.append(ycum)
                ycum = 0
        else:
            if t == 0:
                xcum += 1
            else:
                ycum += 1
    if xcum > 0:
        xd.append(xcum)
        xcum = 0
    if ycum > 0:
        yd.append(ycum)
        ycum = 0

    # print(startx)
    # print(xd, yd)
    # print(search(xd, startx), search(yd, 0))
    if x in search(xd, startx) and y in search(yd, 0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = 5
fs = list(map(len, s.split('T')))
x -= fs[0]
dx = []
dy = []
for i in range(1, len(fs)):
    if fs[i] == 0:
        continue
    if i % 2 == 0:
        dx.append(fs[i])
    else:
        dy.append(fs[i])
dpx = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpy = [[False for _ in range(4 * n + 1)] for _ in range(2)]
dpx[0][2 * n] = True
dpy[0][2 * n] = True
for i in range(len(dx)):
    for j in range(4 * n + 1):
        if dpx[i % 2][j]:
            dpx[(i + 1) % 2][j] = True
            if 0 <= j - dx[i]:
                dpx[(i + 1) % 2][j - dx[i]] = True
            if j + dx[i] <= 4 * n:
                dpx[(i + 1) % 2][j + dx[i]] = True
for i in range(len(dy)):
    for j in range(4 * n + 1):
        if dpy[i % 2][j]:
            dpy[(i + 1) % 2][j] = True
            if 0 <= j - dy[i]:
                dpy[(i + 1) % 2][j - dy[i]] = True
            if j + dy[i] <= 4 * n:
                dpy[(i + 1) % 2][j + dy[i]] = True
ix = 2 * n + x
iy = 2 * n + y
if 0 <= ix <= 4 * n and dpx[len(dx) % 2][ix] and 0 <= iy <= 4 * n and dpy[len(dy) % 2][iy]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    xa, ya = map(int, input().split())
    xset = set([0])
    yset = set([0])

    if s not in "T":
        print("Yes" if len(s) == xa and ya == 0 else "No")
        return

    fcnt = 0
    tcnt = 0
    for c in s:
        if "T" == c:
            if fcnt > 0:
                if tcnt % 2 == 0:
                    xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
                else:
                    yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
            fcnt = 0
            tcnt += 1
        if "F" == c:
            fcnt += 1

    if fcnt > 0:
        if tcnt % 2 == 0:
            xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
        else:
            yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
    
    print("Yes" if (xa in xset) and (ya in yset) else "No")

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    xa, ya = map(int, input().split())
    xset = set([0])
    yset = set([0])

    fcnt = 0
    tcnt = 0
    for c in s:
        if "T" == c:
            if fcnt > 0:
                if tcnt % 2 == 0:
                    xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
                else:
                    yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
            fcnt = 0
            tcnt += 1
        if "F" == c:
            fcnt += 1

    if fcnt > 0:
        if tcnt % 2 == 0:
            xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
        else:
            yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
    
    print("Yes" if (xa in xset) and (ya in yset) else "No")

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:

def search(arr, start):
    lst = [start]
    for i in arr:
        new_list = []
        for j in lst:
            new_list.append(j+i)
            new_list.append(j-i)
        lst = new_list
    return lst

def main():
    t = 0
    xd, yd = [], []

    inst = list(input())
    x, y = list(map(int, input().split()))

    xcum = 0
    ycum = 0
    first = True

    startx = 0
    for s in inst:
        if s == 'T':
            t += 1
            t %= 2
            if first:
                startx = xcum
                xcum = 0
                first = False
                continue
            if xcum > 0:
                xd.append(xcum)
                xcum = 0
            if ycum > 0:
                yd.append(ycum)
                ycum = 0
        else:
            if t == 0:
                xcum += 1
            else:
                ycum += 1
    if xcum > 0:
        xd.append(xcum)
        xcum = 0
    if ycum > 0:
        yd.append(ycum)
        ycum = 0

    # print(startx)
    # print(xd, yd)
    # print(search(xd, startx), search(yd, 0))
    if x in search(xd, startx) and y in search(yd, 0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()+"T"
x,y=[int(i) for i in input().split()]


dx=[]
dy=[]

dir_is_X=True
step=0
for char in s:
        if char=='F':
                step+=1
        else:
                if dir_is_X:
                        dx.append(step)
                        dir_is_X=False
                        step=0
                else:
                        dy.append(step)
                        step=0
                        dir_is_X=True
#print(dx)
#print(dy)
bpos=8001 #原点の位置
dpX=[[False for j in range(bpos*2+1)] for i in range(len(dx)+1)]
dpY=[[False for j in range(bpos*2+1)] for i in range(len(dy)+1)]

#10^7なら行けるっしょ
dpX[0][bpos]=True
dpY[0][bpos]=True

for i in range(len(dx)):
        for j in range(bpos*2+1):
                if dpX[i][j]:
                        dpX[i+1][j-dx[i]]=True
                        dpX[i+1][j+dx[i]]=True
for i in range(len(dy)):
        for j in range(bpos*2+1):
                if dpY[i][j]:
                        dpY[i+1][j-dy[i]]=True
                        dpY[i+1][j+dy[i]]=True
#print()
#for nums in dpX:
#       print(nums)
#rint()
#       print(nums)
if dpX[len(dx)][bpos+x] and dpY[len(dy)][bpos+y]:
        print("Yes")
else:
        print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    xa, ya = map(int, input().split())
    xset = set([0])
    yset = set([0])

    fcnt = 0
    tcnt = 0
    for c in s:
        if "T" == c:
            if fcnt > 0:
                if tcnt % 2 == 0:
                    xset = set(x + fcnt for x in xset) | set(x - fcnt for x in xset)
                else:
                    yset = set(y + fcnt for y in yset) | set(y - fcnt for y in yset)
            fcnt = 0
            tcnt += 1
        else:
            fcnt += 1

    if fcnt > 0:
        if tcnt % 2 == 0:
            xset = set(x + fcnt for x in xset) | set(x - fcnt for x in xset)
        else:
            yset = set(y + fcnt for y in yset) | set(y - fcnt for y in yset)
    print("Yes" if (xa in xset) and (ya in yset) else "No")



if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def get_candidates(s):
    is_x = 0
    prev = -1
    cxy = [{0}, {0}]

    def update(move):
        ncx = set()
        cx = cxy[is_x]
        for x in cx:
            ncx.add(x + move)
            ncx.add(x - move)
        cxy[is_x] = ncx

    for i, c in enumerate(s):
        if c == 'T':
            move = i - prev - 1
            update(move)
            is_x ^= 1
            prev = i
    update(len(s) - prev - 1)

    return cxy


def solve(s, x, y):
    cx, cy = get_candidates(s)
    return x in cx and y in cy


s = input()
x, y = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')

Submission status: Wrong Answer

Solution code:
def get_indices(s):
    x = True
    prev = -1
    cnt = 0
    ans_x, ans_y = 0, 0
    for i, c in enumerate(s):
        if c == 'T':
            cnt += 1
            if x:
                ans_x += i - prev - 1
            else:
                ans_y += i - prev - 1
            x = not x
            prev = i
    if x:
        ans_x += len(s) - prev - 1
    else:
        ans_y += len(s) - prev - 1

    return cnt, ans_x, ans_y


def solve(s, x, y):
    cnt, mx, my = get_indices(s)
    if cnt == 0:
        return x == mx and y == 0
    if cnt == 1:
        return x == mx and abs(y) == my
    if cnt == 2:
        return (x & 1) == (mx & 1) and abs(y) == my
    if cnt > 3:
        return (x & 1) == (mx & 1) and (y & 1) == (my & 1)


s = input()
x, y = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')

Submission status: Time Limit Exceeded

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

z = [0]
for i in s:
    if i=='F':
        z[-1] += 1
    else:
        z.append(0)
_y = len(z)//2
_x = len(z) - _y
len_s = len(s)
dp_x = [0 for _i in range((2*len_s+2))]
dp_x_to = [0 for _i in range((2*len_s+2))]
dp_y = [0 for _i in range((2*len_s+2))]
dp_y_to = [0 for _i in range((2*len_s+2))]

dp_x[z[0]] = 1
dp_y[0] = 1

for i in range(1, len(z)):
    if i%2==0:
        for j in range(-len_s, len_s+1):
            dp_x_to[j] = max(
                dp_x[j-z[i]],
                dp_x[j+z[i]]
            )
        dp_x = dp_x_to.copy()
    else:
        for j in range(-len_s, len_s+1):
            dp_y_to[j] = max(
                dp_y[j-z[i]],
                dp_y[j+z[i]]
            )
        dp_y = dp_y_to.copy()

if dp_x[x] == dp_y[y] == 1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=input()
xin,yin=map(int,input().split())
S+="T"
cnt=0
fl=0
Count=[]
for s in S:
    if s=="F":
        cnt+=1
    else:
        fl+=1
        Count.append([cnt,fl])
        cnt=0
ans=deque([])
ans.append([[0,0]])

for count,dist in Count:
    t=ans.pop()
    tmp=[]
    if dist==1:
        tmp.append([t[0][0]+count,t[0][1]])
    else:
        for x,y in t:
            if dist % 2 == 1:
                nx=x+count
                nnx=x-count
                tmp.append([nx,y])
                tmp.append([nnx,y])
            else:
                ny=y+count
                nny=y-count
                tmp.append([x,ny])
                tmp.append([x,nny])
    ans.append(tmp)
t=ans.pop()
if [xin,yin] in t:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=input()
x,y=map(int,input().split())
ans=deque([])
S+="T"
cnt=0
fl=0
ans.append([[0,0]])
for s in S:
    if s=="F":
        cnt+=1
    elif s=="T" :
        fl+=1
        t=ans.pop()
        tmp = []
        if fl==1:
            tmp.append([t[0][0]+cnt,t[0][0]])
            ans.append(tmp)
        else:
            for j in t:
                nx = j[0]
                ny = j[1]
                if fl%2==1:
                    tmp.append([nx+cnt,ny])
                    tmp.append([nx-cnt,ny])
                else:
                    tmp.append([nx, ny+cnt])
                    tmp.append([nx, ny-cnt])
            ans.append(tmp)
        cnt=0
g=ans.pop()
if [x,y] in g:
     print("Yes")
     exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
S=input()
x,y=map(int,input().split())
ans=[]
S+="T"
cnt=0
fl=0
ans.append([[0,0]])
for s in S:
    if s=="F":
        cnt+=1
    elif s=="T" :
        fl+=1
        tmp = []
        if fl==1:
            tmp.append([ans[0][0][0]+cnt,ans[0][0][0]])
            ans.append(tmp)
        else:
            for j in range(len(ans[fl-1])):
                nx = ans[fl - 1][j][0]
                ny = ans[fl - 1][j][1]
                if fl%2==1:
                    tmp.append([nx+cnt,ny])
                    tmp.append([nx-cnt,ny])
                else:
                    tmp.append([nx, ny+cnt])
                    tmp.append([nx, ny-cnt])
            ans.append(tmp)
        cnt=0

if [x,y] in ans[-1]:
     print("Yes")
     exit()
print("No")

Submission status: Time Limit Exceeded

Solution code:
#FT Robot_2
import numpy as np
s = input()
x, y = map(int, input().split())

L = []
stack = 0
p = np.array([0])
q = np.array([0])

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = p + L[i]
    elif i % 2 == 0:
        pa = p + L[i]
        pb = p - L[i]
        p = np.concatenate([pa,pb])
    elif i % 2 == 1:
        qa = q + L[i]
        qb = q - L[i]
        q = np.concatenate([qa,qb])

if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

L = []
stack = 0
p = [0]
q = [0]

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = [L[i]]
    elif i % 2 == 0:
        pa = []
        for j in range(len(p)):
            pa.append(p[j]+L[i])
            pa.append(p[j]-L[i])
        p = pa
    elif i % 2 == 1:
        qa = []
        for j in range(len(q)):
            qa.append(q[j]+L[i])
            qa.append(q[j]-L[i])
        q = qa

if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

L = []
stack = 0
p = [0]
q = [0]

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = [L[i]]
    elif i % 2 == 0:
        while len(p) < 2**(i//2):
            p.append(p[0]+L[i])
            p.append(p[0]-L[i])
            p.remove(p[0])
    elif i % 2 == 1:
        while len(q) < 2**(i//2 + 1):
            q.append(q[0]+L[i])
            q.append(q[0]-L[i])
            q.remove(q[0])

if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

L = []
stack = 0
p = [0]
q = [0]

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    else:
        L.append(stack)
        stack = 0

if stack != 0:
    L.append(stack)

for i in range(len(L)):
    if i == 0:
        p = [L[i]]
    elif i % 2 == 0:
        pa = []
        for j in range(len(p)):
            pa.append(p[j]+L[i])
            pa.append(p[j]-L[i])
        p = pa
    elif i % 2 == 1:
        qa = []
        for j in range(len(q)):
            qa.append(q[j]+L[i])
            qa.append(q[j]-L[i])
        q = qa

if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s = input()
x, y = map(int, input().split())
cnt = 0
l = []
for c in s:
    if c == 'T':
        l.append(cnt)
        cnt = 0
    else:
        cnt += 1
l.append(cnt)
x -= l[0]
xf = l[2::2]
yf = l[1::2]
dpx = [[0] * 16001 for _ in range(len(xf) + 1)]
dpy = [[0] * 16001 for _ in range(len(yf) + 1)]
dpx[0][0] = 1
dpy[0][0] = 1
for i in range(len(xf)):
    for j in range(-8000, 8001):
        if -8000 <= j + xf[i] <= 8000:
            dpx[i + 1][j + xf[i]] |= dpx[i][j]
        if -8000 <= j - xf[i] <= 8000:
            dpx[i + 1][j - xf[i]] |= dpx[i][j]
for i in range(len(yf)):
    for j in range(-8000, 8001):
        if -8000 <= j + yf[i] <= 8000:
            dpy[i + 1][j + yf[i]] |= dpy[i][j]
        if -8000 <= j - yf[i] <= 8000:
            dpy[i + 1][j - yf[i]] |= dpy[i][j]
if dpx[len(xf)][x] & dpy[len(yf)][y]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s = input().split("T")
x,y = map(int,input().split())
xmove = []
ymove = []
for i in range(1,len(s)):
    if i % 2 == 0:
        xmove.append(s[i].count("F"))
    else:
        ymove.append(s[i].count("F"))
dpx = [[False]*(16001) for i in range(len(xmove)+1)]
dpy = [[False]*(16001) for i in range(len(ymove)+1)]
dpx[0][s[0].count("F")+8000] = True
dpy[0][8000] = True
for i in range(len(xmove)):
    for j in range(16001):
        if dpx[i][j]:
            if 0<=j-xmove[i]:
                dpx[i+1][j-xmove[i]] = True
            if j+xmove[i] <= 16001:
                dpx[i+1][j+xmove[i]] = True
for i in range(len(ymove)):
    for j in range(16001):
        if dpy[i][j]:
            if 0<=j-ymove[i]:
                dpy[i+1][j-ymove[i]] = True
            if j+ymove[i] <= 16001:
                dpy[i+1][j+ymove[i]] = True

if dpx[len(xmove)][x+8000] and dpy[len(ymove)][y+8000]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque


s=input()
s+='T'
ansx,ansy=map(int,input().split())

dx=deque()
dy=deque()
dy.append(0)
lenf=0
for i in s:
    if i=='T':
        break
    lenf+=1
dx.append(lenf)
check=1
cnt=0
lens=len(s)
for i in range(lenf+1,lens):
    if s[i]=='T':
        if check==-1:
            l=len(dx)
            for k in range(l):
                x=dx.popleft()
                dx.append(x+cnt)
                dx.append(x-cnt)
        else:
            l=len(dy)
            for k in range(l):
                y=dy.popleft()
                dy.append(y+cnt)
                dy.append(y-cnt)
        check*=-1
        cnt=0
    else:
        cnt+=1
if ansx in dx and ansy in dy:
    print('Yes')
else:
    print('No')