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: Time Limit Exceeded

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

#print(s)

susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu[0]

susumu_NS = susumu[1::2]
susumu_EW = susumu[2::2]

x -= syokiti

#print(susumu)
#print(susumu_NS)
#print(susumu_EW)
# ＥＷの部分和でx? NSの部分和でy？

LL = len(s)+2
dp = [[0 for i in range(2*LL)] for j in range(1+len(susumu_NS))]
dp[0][LL] = 1

for j in range(len(susumu_NS)):
    #    print('j='),
    #    print(j)
    for i in range(2*LL):
    #        a=0
    #        print(i+susumu_NS[j])
        try:
            dp[j+1][i] = dp[j][i+susumu_NS[j]] | dp[j][i-susumu_NS[j]]
        except IndexError:
            if i < 0:
                dp[j+1][i] = dp[j][i+susumu_NS[j]]
            else:
                dp[j+1][i] = dp[j][i-susumu_NS[j]]

can_y = 0
if dp[len(susumu_NS)][y+LL] != 0:
    can_y = 1
#print(dp)
#print(susumu_NS)
#print(can_y)
    
#########################################
LL = len(s)+2
dp = [[0 for i in range(2*LL)] for j in range(1+len(susumu_EW))]
dp[0][LL] = 1

for j in range(len(susumu_EW)):
#    print('j='),
#    print(j)
    for i in range(2*LL):
#        a=0
#        print(i+susumu_NS[j])
        try:
            dp[j+1][i] = dp[j][i+susumu_EW[j]] | dp[j][i-susumu_EW[j]]
        except IndexError:
            if i < 0:
                dp[j+1][i] = dp[j][i+susumu_EW[j]]
            else:
                dp[j+1][i] = dp[j][i-susumu_EW[j]]

can_x = 0
if dp[len(susumu_EW)][x+LL] != 0:
    can_x = 1

#print(dp)

#print(can_x)
#print(can_y)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

#print(s)

susumu = [0]
for i in range(len(s)):
    if s[i] == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu.pop(0)

susumu_NS = [i for i in susumu[::2] if i != 0]
susumu_EW = [i for i in susumu[1::2] if i != 0]

x -= syokiti

# ＥＷの部分和でx? NSの部分和でy？

LL = sum(susumu_NS)+2
dp = [[0 for i in range(4*LL+2*len(s))] for j in range(1+len(susumu_NS))]
dp[0][2*LL+len(s)] = 1


for j in range(len(susumu_NS)):
#    print('j='),
#    print(j)
    for i in range(LL+len(s),3*LL+len(s)):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_NS[j]] | dp[j][i-susumu_NS[j]]

can_y = 0
if dp[len(susumu_NS)][y+2*LL+len(s)] != 0:
    can_y = 1
#print(susumu_NS)
#print(can_y)
    
#########################################
LL = sum(susumu_EW)+2
dp = [[0 for i in range(4*LL+len(s))] for j in range(1+len(susumu_EW))]
dp[0][2*LL+len(s)] = 1

for j in range(len(susumu_EW)):
#    print('j='),
#    print(j)
    for i in range(LL+len(s),3*LL+len(s)):
#        a=0
#        print(i+susumu_NS[j])
        dp[j+1][i] = dp[j][i+susumu_EW[j]] | dp[j][i-susumu_EW[j]]

can_x = 0
if dp[len(susumu_EW)][x+2*LL+len(s)] != 0:
    can_x = 1

#print(can_x)

if can_x == 1 & can_y == 1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    for i in range(1<<len(t)):
        z=0
        for j in range(len(t)):
            z+=[1,-1][i>>j&1]*t[j]
        if z==w:
            return True
    return False
print("Yes"if f(s[2::2],x-s[0]) and f(s[1::2],y) else "No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-      

s = input()
dstx, dsty = list(map(int,input().split()))
x = []
y = []
tmp = 0
xy = 0
for i in range(len(s)):
    if(s[i]=='F'):
        tmp += 1
    elif(s[i]=='T' and xy==0):
        x.append(tmp)
        tmp = 0
        xy = 1
    elif(s[i]=='T' and xy==1):
        y.append(tmp)
        tmp = 0
        xy = 0
else:
    if(xy==0):
        x.append(tmp)
    else:
        y.append(tmp)
        
dpx = [{} for i in range(len(x))]
dpy = [{} for i in range(len(y)+1)]
dpx[0][x[0]] = True
dpy[0][0] = True
for i, dx in enumerate(x[1:]):
    for j in dpx[i]:
        dpx[i+1][j+dx] = True
        dpx[i+1][j-dx] = True
for i, dy in enumerate(y):
    for j in dpy[i]:
        dpy[i+1][j+dy] = True
        dpy[i+1][j-dy] = True
    
if(dstx not in dpx[-1] or dsty not in dpy[-1]):
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-        
import numpy as np

s = input()
dstx, dsty = list(map(int,input().split()))
x = []
y = []
tmp = 0
xy = 0
for i in range(len(s)):
    if(s[i]=='F'):
        tmp += 1
    elif(s[i]=='T' and xy==0):
        x.append(tmp)
        tmp = 0
        xy = 1
    elif(s[i]=='T' and xy==1):
        y.append(tmp)
        tmp = 0
        xy = 0
else:
    if(xy==0):
        x.append(tmp)
    else:
        y.append(tmp)
        
dpx = np.zeros((len(x),16002),dtype='bool')
dpy = np.zeros((len(y)+1,16002),dtype='bool')
dpx[0][8001+x[0]] = True
dpy[0][8001] = True
for i in range(1,len(x)):
    for j in range(0,16002):
        if(j-x[i]<0):
            dpx[i][j] = dpx[i-1][j+x[i]]
        elif(j+x[i]>16001):
            dpx[i][j] = dpx[i-1][j-x[i]]
        else:
            dpx[i][j] = dpx[i-1][j-x[i]] or dpx[i-1][j+x[i]]
for i in range(1,len(y)+1):
    for j in range(0,16002):
        if(j-y[i-1]<0):
            dpy[i][j] = dpy[i-1][j+y[i-1]]
        elif(j+y[i-1]>16001):
            dpy[i][j] = dpy[i-1][j-y[i-1]] 
        else:
            dpy[i][j] = dpy[i-1][j-y[i-1]] or dpy[i-1][j+y[i-1]]

if(dpx[-1][8001+dstx] and dpy[-1][8001+dsty]):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8                                                                  

alls = raw_input()
tarx, tary = map(int, raw_input().split())

ss = alls.split("T")

xs = []
ys = []
posx = []
posy = [0]
for i, s in enumerate(ss):
    if i == 0:
        posx.append(len(s))
    elif i % 2 == 0:
        xs.append(len(s))
    else:
        ys.append(len(s))

for x in xs:
    tmpx = []
    for px in posx:
        tmpx.append(px+x)
        tmpx.append(px-x)
    set(tmpx)
    posx = tmpx

for y in ys:
    tmpy = []
    for py in posy:
        tmpy.append(py+y)
        tmpy.append(py-y)
    set(tmpy)
    posy = tmpy

if tarx in posx and tary in posy:
    print "Yes"
else:
    print "No"

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8                                                                  

import copy

alls = raw_input()
tarx, tary = map(int, raw_input().split())

ss = alls.split("T")

xs = []
ys = []
posx = []
posy = [0]
for i, s in enumerate(ss):
    if i == 0:
        posx.append(len(s))
    elif i % 2 == 0:
        xs.append(len(s))
    else:
        ys.append(len(s))

for x in xs:
    tmpx = []
    for px in posx:
        tmpx.append(px+x)
        tmpx.append(px-x)
    set(tmpx)
    posx = copy.deepcopy(tmpx)

for y in ys:
    tmpy = []
    for py in posy:
        tmpy.append(py+y)
        tmpy.append(py-y)
    set(tmpy)
    posy = copy.deepcopy(tmpy)

if tarx in posx and tary in posy:
    print "Yes"
else:
    print "No"

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

S = list(input())
x, y = list(map(int, input().split()))
cand = [[[0, 0], [1, 0]]]


def get_next_face(face, turn=1):
    if face[0] in [1, -1]:
        if turn == 1:
            return [[0, 1], [0, -1]]
        else:
            return [[1, 0], [-1, 0]]
    else:
        if turn == 1:
            return [[1, 0], [-1, 0]]
        else:
            return [[0, 1], [0, -1]]


def print_cand():
    for c in cand:
        for i in range(2):
            for j in range(2):
                print(c[i][j], "", end="")
        print()


nums = [1]
cmds = [S[0]]
for s in S[1:]:
    if cmds[-1] == s:
        nums[-1] += 1
    else:
        cmds.append(s)
        nums.append(1)

for num, cmd in zip(nums, cmds):
    if cmd == 'F':
        for i in range(len(cand)):
            cand[i][0][0] = cand[i][0][0] + cand[i][1][0] * num
            cand[i][0][1] = cand[i][0][1] + cand[i][1][1] * num
    else:
        cand_new = []
        for i in range(len(cand)):
            position0 = deepcopy(cand[i][0])
            position1 = deepcopy(cand[i][0])
            faces = deepcopy(get_next_face(cand[i][1], num))

            flag0 = True
            flag1 = True
            for j in range(len(cand_new)):
                if position0[0] == cand_new[j][0][0] and position0[1] == cand_new[j][0][1] and faces[0][0] == cand_new[j][1][0] and faces[0][1] == cand_new[j][1][1]:
                    flag0 = False
                if position1[0] == cand_new[j][0][0] and position1[1] == cand_new[j][0][1] and faces[1][0] == cand_new[j][1][0] and faces[1][1] == cand_new[j][1][1]:
                    flag1 = False
                if not(flag0 and flag1):
                    break
            if flag0:
                cand_new.append([position0, faces[0]])
            if flag1:
                cand_new.append([position1, faces[1]])
        cand = deepcopy(cand_new)

flag = False
for i in range(len(cand)):
    if cand[i][0][0] == x and cand[i][0][1] == y:
        flag = True
        break


if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

s = list(map(str, input()))
g = list(map(lambda x: int(x),input().split()))

seq = ('R', 'L')

ans = False

count_dict = collections.Counter(s)

g_sum = abs(g[0])+abs(g[1])
if g_sum > count_dict['F']:
    print('No')
else:
    patterns = list(itertools.product(seq, repeat=count_dict['T']))

    for _p in patterns:
        i = 0
        m = [0, 0]
        n = 3
        for _s in s:
            if _s == 'F':
                if n == 3:
                    m[0] = m[0] + 1
                elif n == 1:
                    m[0] = m[0] - 1
                elif n == 0:
                    m[1] = m[1] + 1
                elif n == 2:
                    m[1] = m[1] - 1
            else:
                i = i + 1
                if _p[i-1] == 'R':
                    if n == 0:
                        n = 3
                    else:
                        n = n - 1
                elif _p[i-1] == 'L':
                    if n == 3:
                        n = 0
                    else:
                        n = n + 1

        if m[0] == g[0] and m[1] == g[1]:
            ans = True
            break

    if ans:
        print('Yes')
    else:
        print('No')

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

S = list(input())
x, y = list(map(int, input().split()))
cand = [[[0, 0], [1, 0]]]


def get_next_face(face):
    if face[0] in [1, -1]:
        return [[0, 1], [0, -1]]
    else:
        return [[1, 0], [-1, 0]]


def print_cand():
    for c in cand:
        for i in range(2):
            for j in range(2):
                print(c[i][j], "", end="")
        print()


for s in S:
    if s == 'F':
        for i in range(len(cand)):
            cand[i][0][0] = cand[i][0][0] + cand[i][1][0]
            cand[i][0][1] = cand[i][0][1] + cand[i][1][1]
    else:
        cand_new = []
        for i in range(len(cand)):
            position0 = deepcopy(cand[i][0])
            position1 = deepcopy(cand[i][0])
            faces = deepcopy(get_next_face(cand[i][1]))

            flag0 = True
            flag1 = True
            for j in range(len(cand_new)):
                if position0[0] == cand_new[j][0][0] and position0[1] == cand_new[j][0][1] and faces[0][0] == cand_new[j][1][0] and faces[0][1] == cand_new[j][1][1]:
                    flag0 = False
                if position1[0] == cand_new[j][0][0] and position1[1] == cand_new[j][0][1] and faces[1][0] == cand_new[j][1][0] and faces[1][1] == cand_new[j][1][1]:
                    flag1 = False
                if not(flag0 and flag1):
                    break
            if flag0:
                cand_new.append([position0, faces[0]])
            if flag1:
                cand_new.append([position1, faces[1]])
        cand = deepcopy(cand_new)

flag = False
for i in range(len(cand)):
    if cand[i][0][0] == x and cand[i][0][1] == y:
        flag = True
        break


if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

S = list(input())
x, y = list(map(int, input().split()))
cand = [[[0, 0], [1, 0]]]


def get_next_face(face):
    if face[0] in [1, -1]:
        return [[0, 1], [0, -1]]
    else:
        return [[1, 0], [-1, 0]]


def print_cand():
    for c in cand:
        for i in range(2):
            for j in range(2):
                print(c[i][j], "", end="")
        print()


for s in S:
    if s == 'F':
        for i in range(len(cand)):
            cand[i][0][0] = cand[i][0][0] + cand[i][1][0]
            cand[i][0][1] = cand[i][0][1] + cand[i][1][1]
    else:
        cand_new = []
        for i in range(len(cand)):
            position0 = deepcopy(cand[i][0])
            position1 = deepcopy(cand[i][0])
            faces = deepcopy(get_next_face(cand[i][1]))

            flag = True
            for j in range(len(cand_new)):
                if position0[0] == cand_new[j][0][0] and position0[1] == cand_new[j][0][1] and faces[0][0] == cand_new[j][1][0] and faces[0][1] == cand_new[j][1][1]:
                    flag = False
                    break
            if flag:
                cand_new.append([position0, faces[0]])

            flag = True
            for j in range(len(cand_new)):
                if position1[0] == cand_new[j][0][0] and position1[1] == cand_new[j][0][1] and faces[1][0] == cand_new[j][1][0] and faces[1][1] == cand_new[j][1][1]:
                    flag = False
                    break
            if flag:
                cand_new.append([position1, faces[1]])
        cand = deepcopy(cand_new)

flag = False
for i in range(len(cand)):
    if cand[i][0][0] == x and cand[i][0][1] == y:
        flag = True
        break


if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
x,y = list(map(int,input().split()))
myx,myy = 0,0
vector = "right"
line_x,line_y = x,y

def pt1_turn(vector,myx,myy):
    if vector == "up" or vector == "down":
        if myx <= line_x:
            return "right"
        else:
            return "left"
    else:
        if myy <= line_y:
            return "up"
        else:
            return "down"

def pt2_turn(vector,myx,myy):
    if vector == "up" or vector == "down":
        if myx <= line_x:
            return "right"
        else:
            return "left"
    else:
        if myy <= line_y:
            return "down"
        else:
            return "up"


def go(vector):
    if vector == "up":
        return 0,1
    elif vector == "right":
        return 1,0
    elif vector == "down":
        return 0,-1
    else:
        return -1,0

pt = [[myx,myy,vector]]
for exe in s:
    tmppt = []
    for p in pt:
        tx,ty,tvector = p[0],p[1],p[2]
        if exe == "F":
            plus_x,plus_y = go(tvector)
            tx += plus_x
            ty += plus_y
            tmppt.append([tx,ty,tvector])
        else:
            tmp = pt1_turn(tvector,tx,ty)
            tmppt.append([tx,ty,tmp])
            tmp = pt2_turn(tvector,tx,ty)
            tmppt.append([tx,ty,tmp])

    pt = tmppt
    # print(pt)

flag = False
for p in pt:
    if p[0] == x and p[1] == y:
        flag = True
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

s = list(map(str, input()))
g = list(map(lambda x: int(x),input().split()))

seq = ('R', 'L')

ans = False

count_dict = collections.Counter(s)
patterns = list(itertools.product(seq, repeat=count_dict['T']))


for _p in patterns:
    i = 0
    m = [0, 0]
    n = 3
    for _s in s:
        if _s == 'F':
            if n == 3:
                m[0] = m[0] + 1
            elif n == 1:
                m[0] = m[0] - 1
            elif n == 0:
                m[1] = m[1] + 1
            elif n == 2:
                m[1] = m[1] - 1
        else:
            i = i + 1
            if _p[i-1] == 'R':
                if n == 0:
                    n = 3
                else:
                    n = n - 1
            elif _p[i-1] == 'L':
                if n == 3:
                    n = 0
                else:
                    n = n + 1

    if m[0] == g[0] and m[1] == g[1]:
        ans = True
        break

if ans:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

def adding(sign, lst):
    res = 0
    for i in range(len(sign)):
        if sign[i] == 0:
            res += lst[i]
        else:
            res -= lst[i]
    return res

a = [0, 1]

fs = s.split("T")
f_num = [len(f) for f in fs]

dir_lst = [[], []]

for i in range(len(f_num)):
    dir_lst[i%2].append(f_num[i])

x_lst = dir_lst[0]
y_lst = dir_lst[1]

aosx = product(a, repeat=len(x_lst)-1)
aosy = product(a, repeat=len(y_lst))

flag = True

for signx in aosx:
    if x_lst[0] + adding(signx, x_lst[1:]) == x:
        for signy in aosy:
            if adding(signy, y_lst) == y:
                print("Yes")
                flag = False
                break

if flag:
    print("No")

Submission status: Time Limit Exceeded

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

f_num = 0
t_num = 0
for o in s:
    if o == "F":
        f_num += 1
    else:
        t_num += 1
if f_num == 0:
    if x == 0 and y == 0:
        print("Yes")
    else:
        print("No")
else:
    f = s.split("T")
    rx = len(f[0])
    ry = 0
    rx_list = [rx]
    ry_list = [ry]
    for i in range(1, t_num+1):
        if i % 2 == 0:
            if len(f[i]) != 0:
                tmp_rx = []
                for tmp_x in rx_list:
                    tmp_rx.append(tmp_x + len(f[i]))
                    tmp_rx.append(tmp_x - len(f[i]))
                rx_list = tmp_rx
        else:
            if len(f[i]) != 0:
                tmp_ry = []
                for tmp_y in ry_list:
                    tmp_ry.append(tmp_y + len(f[i]))
                    tmp_ry.append(tmp_y - len(f[i]))
                ry_list = tmp_ry

    if x in rx_list and y in ry_list:
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10000)

s = input()
x, y = [int(x) for x in input().split()]

d = (
    (1, 0),
    (0, 1),
    (-1, 0),
    (0, -1),
)

def next_dr(dr):
    def fix(dr):
        if dr == -1:
            return 3
        if dr == 4:
            return 0
        return dr
    return fix(dr - 1), fix(dr + 1)

def next_dr_set(dr_set, l):
    if l == 0:
        return dr_set
    _next_dr_set = set()
    for dr in dr_set:
        _next_dr_set.update(set(next_dr(dr)))
    return next_dr_set(_next_dr_set, l - 1)

def next_dr_list(dr, l):
    dr_set = next_dr_set(set([dr]), l)
    return list(dr_set)

def _next_dr_list(dr, l):
    if l == 0:
        return [dr]
    if dr % 2 == 0:
        if l % 2 == 0:
            return [0, 2]
        else:
            return [1, 3]
    else:
        if l % 2 == 0:
            return [1, 3]
        else:
            return [0, 2]

def dfs(s, a, b, dr):
    # print("called")
    # print(s)
    # print(a)
    # print(b)
    # print(dr)
    if s == '':
        return x == a and y == b

    if s[0] == 'F':
        dx, dy = d[dr]
        a += dx
        b += dy
        return dfs(s[1:], a, b, dr)
    else:
        l = s.find('F')
        if l == -1:
            return x == a and y == b

        dr_list = _next_dr_list(dr, l)
        for next_dr in dr_list:
            if dfs(s[l:], a, b, next_dr):
                return True

        return False

ans = "Yes" if dfs(s, 0, 0, 0) else "No"
print(ans)

Submission status: Time Limit Exceeded

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

import itertools

def possibility_check(target_value, target_list):
    if len(target_list) == 1:
        if (target_list[0] == target_value) or (target_list[0] * (-1) == target_value):
            return True
        else:
            return False
    #print('target: ', target_value, target_list)
    length = len(target_list)
    for x in range(1<<length):
        check_cnt = 0
        for j in range(length):
            if x & (1<<j):
                check_cnt += target_list[j]
            else:
                check_cnt -= target_list[j]
        if check_cnt == target_value:
            return True
    return False

mvx = []
mvy = []
set_x  = True
cnt = 0
s_base = [i for i in input()]
tx, ty = [int(i) for i in input().split()]

for i, s in enumerate(s_base):
    if s == 'F':
        cnt += 1
        if i == len(s_base)-1:
            if set_x:
                mvx.append(cnt)
            else:
                mvy.append(cnt)
    else:
        if set_x:
            mvx.append(cnt)
            set_x = False
            cnt = 0
        else:
            mvy.append(cnt)
            set_x = True
            cnt = 0

fmove = mvx.pop(0)
tx -= fmove

#print(possibility_check(tx, mvx))
#print(possibility_check(ty, mvy))

if possibility_check(tx, mvx) and possibility_check(ty, mvy):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10000)

s = input()
x, y = [int(x) for x in input().split()]

d = (
    (1, 0),
    (0, 1),
    (-1, 0),
    (0, -1),
)

def next_dr(dr):
    def fix(dr):
        if dr == -1:
            return 3
        if dr == 4:
            return 0
        return dr
    return fix(dr - 1), fix(dr + 1)

def next_dr_set(dr_set, l):
    if l == 0:
        return dr_set
    _next_dr_set = set()
    for dr in dr_set:
        _next_dr_set.update(set(next_dr(dr)))
    return next_dr_set(_next_dr_set, l - 1)

def next_dr_list(dr, l):
    dr_set = next_dr_set(set([dr]), l)
    return list(dr_set)

def _next_dr_list(dr, l):
    if l == 0:
        return [dr]
    if dr % 2 == 0:
        if l % 2 == 0:
            return [0, 2]
        else:
            return [1, 3]
    else:
        if l % 2 == 0:
            return [1, 3]
        else:
            return [0, 2]

def dfs(s, a, b, dr):
    # print("called")
    # print(s)
    # print(a)
    # print(b)
    # print(dr)
    if s == '':
        return x == a and y == b

    if s[0] == 'F':
        dx, dy = d[dr]
        a += dx
        b += dy
        return dfs(s[1:], a, b, dr)
    else:
        l = s.find('F')
        if l == -1:
            return x == a and y == b

        dr_list = next_dr_list(dr, l)
        for next_dr in dr_list:
            if dfs(s[l:], a, b, next_dr):
                return True

        return False

ans = "Yes" if dfs(s, 0, 0, 0) else "No"
print(ans)

Submission status: Time Limit Exceeded

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

#dir:0 右 1 上  左 3 下

ans = [(0,0,0)]

for ch in s:
	if ch == "T":
		tmp = []
		for lis in ans:
			tmp.append((lis[0],lis[1],lis[2]+1))
			tmp.append((lis[0],lis[1],lis[2]-1))

		ans = list(set(tmp))

	else:
		for i in range(len(ans)):
			if (ans[i][2] % 4 == 0):
				ans[i] = (ans[i][0]+1,ans[i][1],ans[i][2])
			elif (ans[i][2] % 4 == 1):
				ans[i] = (ans[i][0],ans[i][1]+1,ans[i][2])
			elif (ans[i][2] % 4 == 2):
				ans[i] = (ans[i][0]-1,ans[i][1],ans[i][2])
			else:
				ans[i] = (ans[i][0],ans[i][1]-1,ans[i][2])


ans = [[lis[0],lis[1]] for lis in ans]

if [x,y] in ans:
	print("Yes")

else:
	print("No")

Submission status: Time Limit Exceeded

Solution code:

S = input()
P = tuple(map(int, input().split()))

dis = abs(P[0]) + abs(P[1])
forward = S.count("F")

S = S.split("T")

def add(p, d, L):
    return (p[0] + L * d[0], p[1] + L * d[1])

if dis > forward or (forward - dis) % 2 == 1:
    print("No")

else:
    now = {((0, 0), (1, 0), forward)} # (X, Y), dir
    for s in S:
        ne = set()
        L = len(s)
        for p, d, f in now:
            #Fのとき
            f -= L
            p = add(p, d, L)
            dis = abs(P[0] - p[0]) + abs(P[1] - p[1])

            if dis <= forward:
                #ne = ne | {(p, d, f)}
                ne = ne | {(p, (d[1], -d[0]), f), (p, (-d[1], d[0]), f) }
        now = ne
    
    for p,d,f in now:
        if p == P:
            print("Yes")
            break
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:

S = input()
P = tuple(map(int, input().split()))

dis = abs(P[0]) + abs(P[1])
forward = S.count("F")

def add(p, d):
    return (p[0] + d[0], p[1] + d[1])

if dis > forward or (forward - dis) % 2 == 1:
    print("No")

else:
    now = {((0, 0), (1, 0), forward)} # (X, Y), dir
    for s in S:
        ne = set()
        for p, d, f in now:
            #Fのとき
            if s == "F":
                f -= 1
                p = add(p, d)
                dis = abs(P[0] - p[0]) + abs(P[1] - p[1])
                if dis <= forward:
                    ne = ne | {(p, d, f)}
            #Tのとき
            elif s == "T":
                ne = ne | {(p, (d[1], -d[0]), f), (p, (-d[1], d[0]), f) }
        now = ne
    
    for p,d,f in now:
        if p == P:
            print("Yes")
            break
    else:
        print("No")

Submission status: Time Limit Exceeded

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

#dir:0 右 1 上  左 3 下

ans = [[0,0,0]]

for ch in s:
	if ch == "T":
		tmp = []
		for lis in ans:
			tmp.append([lis[0],lis[1],lis[2]+1])
			tmp.append([lis[0],lis[1],lis[2]-1])

		ans = tmp[:]

	else:
		for i in range(len(ans)):
			if (ans[i][2] % 4 == 0):
				ans[i][0] += 1
			elif (ans[i][2] % 4 == 1):
				ans[i][1] += 1
			elif (ans[i][2] % 4 == 2):
				ans[i][0] -= 1
			else:
				ans[i][1] -= 1


ans = [lis[0:2] for lis in ans]

if [x,y] in ans:
	print("Yes")

else:
	print("No")

Submission status: Time Limit Exceeded

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

f_num = 0
t_num = 0
for o in s:
    if o == "F":
        f_num += 1
    else:
        t_num += 1
if f_num == 0:
    if x == 0 and y == 0:
        print("Yes")
    else:
        print("No")
else:
    f = s.split("T")
    rx = len(f[0])
    ry = 0
    move_x_list = []
    move_y_list = []
    for i in range(1, t_num+1):
        if i%2 == 0:
            move_x_list.append(len(f[i]))
        else:
            move_y_list.append(len(f[i]))
    rx_list = [rx]
    ry_list = [ry]
    for i in range(max(len(move_x_list), len(move_y_list))):
        if i < len(move_x_list):
            if move_x_list[i] != 0:
                tmp_rx = []
                for tmp_x in rx_list:
                    tmp_rx.append(tmp_x + move_x_list[i])
                    tmp_rx.append(tmp_x - move_x_list[i])
                rx_list = tmp_rx
        if i < len(move_y_list):
            if move_y_list[i] != 0:
                tmp_ry = []
                for tmp_y in ry_list:
                    tmp_ry.append(tmp_y + move_y_list[i])
                    tmp_ry.append(tmp_y - move_y_list[i])
                ry_list = tmp_ry

    if x in rx_list and y in ry_list:
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
S = input()
P = tuple(map(int, input().split()))

def add(p, d):
    return (p[0] + d[0], p[1] + d[1])

now = {((0, 0), (1, 0))} # (X, Y), dir
for s in S:
    ne = set()
    for p, d in now:

        #Fのとき
        if s == "F":
            ne = ne | {(add(p, d), d)}
        
        #Tのとき
        elif s == "T":
            ne = ne | {(p, (d[1], -d[0])), (p, (-d[1], d[0])) }

    now = ne

for p,d in now:
    if p == P:
        print("Yes")
        break
else:
    print("No")

Submission status: Memory Limit Exceeded

Solution code:
S = list(input())
x, y = map(int, input().split())
c = 0
p = 0
q = 0
now = 0
R = []
L = []
for i in range(len(S)):
    if S[i] == "T":
        if p != 0:
            R.append(p)
            p = 0
        elif q != 0:
            L.append(q)
            q = 0
        c += 1
    elif c == 0:
        now += 1
    elif c % 2 == 0:
        p += 1
    else:
        q += 1
if p != 0:
    R.append(p)
if q != 0:
    L.append(q)

dp_x = [[0]*20000 for _ in range(len(R)+2)]
dp_y = [[0]*20000 for _ in range(len(L)+1)]
c = 0
dp_x[0][8000] = 1
dp_y[0][8000] = 1
for i in range(1, len(R)+2):
    for j in range(8000-sum(R)-now, 8000+sum(R)+now+1):
        if i == 1:
            if j - now >= 0:
                if dp_x[i-1][j-now] == 1:
                    dp_x[i][j] = 1
        else:
            if j - R[i-2] >= 0:
                if dp_x[i-1][j-R[i-2]] == 1:
                    dp_x[i][j] = 1
            if j + R[i-2] <= 16001:
                if dp_x[i-1][j+R[i-2]] == 1:
                    dp_x[i][j] = 1

for i in range(1, len(L)+1):
    for j in range(8000-sum(L), 8000+sum(L)+1):
        if j - L[i-1] >= 0:
            if dp_y[i-1][j-L[i-1]] == 1:
                dp_y[i][j] = 1
        if j + L[i-1] <= 16001:
            if dp_y[i-1][j+L[i-1]] == 1:
                dp_y[i][j] = 1

if dp_x[len(R)+1][x+8000] == 1 and dp_y[len(L)][y+8000] == 1:
    print("Yes")
else:
    print("No")