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:
from collections import deque
def main():
   s = input()
   x,y = map(int, input().split())

   Fcount = 0
   ff = 0
   Tcount = 0
   S = []
   for ss in s:
      if ss == "F":
         if (Tcount%2==0)and(Tcount!=0):
            S.append("t")
         elif Tcount!=0:
            S.append("T")
         Fcount += 1
         ff += 1
         Tcount = 0
      elif ss=="T":
         if ff!=0:
            S.append(str(ff))
         Tcount += 1
         ff = 0
   if ff!=0:
      S.append(str(ff))
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(S)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if S[now] == "T":
            if vx == 0:
               q.append([xx,yy,1,0,now+1])
               q.append([xx,yy,-1,0,now+1])
            elif vy == 0:
               q.append([xx,yy,0,1,now+1])
               q.append([xx,yy,0,-1,now+1])
         elif S[now] == "t":
            q.append([xx,yy,vx,vy,now+1])
            q.append([xx,yy,-vx,-vy,now+1])
         else :
            q.append([xx+int(S[now])*vx,yy+int(S[now])*vy,vx,vy,now+1])
   return "No"


print(main())

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def main():
   s = input()
   x,y = map(int, input().split())

   Fcount = 0
   Tcount = 0
   S = ""
   for ss in s:
      if ss == "F":
         if (Tcount%2==0)and(Tcount!=0):
            S += "TT"
         elif Tcount!=0:
            S += "T"
         S += "F"
         Fcount += 1
         Tcount = 0
      elif ss=="T":
         Tcount += 1
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(S)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if S[now] == "F":
            q.append([xx+vx,yy+vy,vx,vy,now+1])
         else:
            for vv in [1, -1]:
               if vx == 0:
                  q.append([xx,yy,vv,0,now+1])
               elif vy == 0:
                  q.append([xx,yy,0,vv,now+1])
   return "No"


print(main())

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def main():
   s = input()
   x,y = map(int, input().split())

   Fcount = 0
   for ss in s:
      if ss == "F":
         Fcount += 1
   if Fcount < (abs(x)+abs(y)):
      return "No"

   # BFS
   k = len(s)
   q = deque([[0,0,1,0,0]])
   while q!=deque([]):
      xx,yy,vx,vy,now = q.popleft()
      if (xx==x)and(yy==y)and(now==k):
         return "Yes"
      elif now==k:
         continue
      else: #now != k
         if s[now] == "F":
            q.append([xx+vx,yy+vy,vx,vy,now+1])
         else:
            for vv in [1, -1]:
               if vx == 0:
                  q.append([xx,yy,vv,0,now+1])
               elif vy== 0:
                  q.append([xx,yy,0,vv,now+1])
   return "No"


print(main())

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

def possible(goal, move):
    if len(move) == 0:
        if goal == 0:
            return True
        else:
            return False
            
    sumup = sum(move)
    
    if (sumup+goal)%2 == 1:
        return False
    
    dp = [[False for j in range((goal+sumup)//2+1)] for i in range(len(move))]
    dp[0][0] = True
    dp[0][move[0]] = True
    
    for i in range(1, len(move)):
        for j in range((sumup+goal)//2+1):
            dp[i][j] = dp[i][j] or dp[i-1][j]
            if j >= move[i]:
                dp[i][j] = dp[i][j] or dp[i-1][j-move[i]]
                
    return dp[len(move)-1][(sumup+goal)//2]
    
 
if __name__ == '__main__':
    S = input()
    goalx,goaly = [int(i) for i in input().split()]

    xmove_ind = 0
    ymove_ind = 0
    dir_x = True
    count = 0
    xmove = []
    ymove = []
    
    for i in range(0, len(S)+1):
        if i == len(S) or S[i] == 'T' :
            if dir_x == True:
                xmove.append(count)
            else:
                ymove.append(count)
            count = 0
            dir_x = not dir_x
        else:
            count += 1
    
    #print(xmove)
    #print(ymove)
    
    if possible(abs(goaly) , ymove):
        if len(xmove) == 1:
            if goalx == xmove[0]:
                print("Yes")
            else:
                print("No")
        else:
            if possible(abs(goalx-xmove[0]), xmove[1:]):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)

dir=[[1,0],[0,-1],[-1,0],[0,1]]
s=input()
X,Y=map(int,input().split())
log={}

def walk(x,y,direction,count):
	if (x,y,direction,count) in log:
		return log[(x,y,direction,count)]
	if count==len(s):
		if x==X and y==Y:
			return True
		else: 
			return False
	if s[count]=="F":
		log[(x,y,direction,count)]=walk(x+dir[direction][0],y+dir[direction][1],direction,count+1)
		return log[(x,y,direction,count)]
	else:
		log[(x,y,direction,count)]=walk(x,y,(direction+1)%4,count+1) or walk(x,y,(direction-1+4)%4,count+1)
		return log[(x,y,direction,count)]

if walk(0,0,0,0)==True:
	print('Yes')
else:
	print('No')

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)

dir=[[1,0],[0,-1],[-1,0],[0,1]]
s=input()
X,Y=map(int,input().split())

def walk(x,y,direction,count):
	if count==len(s):
		if x==X and y==Y:
			return True
		else: 
			return False
	if s[count]=="F":
		return walk(x+dir[direction][0],y+dir[direction][1],direction,count+1)
	else:
		return walk(x,y,(direction+1)%4,count+1) or walk(x,y,(direction-1+4)%4,count+1)

if walk(0,0,0,0)==True:
	print('Yes')
else:
	print('No')

Submission status: Time Limit Exceeded

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

import sys

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

    n = len(s)
    stack = [(0, (0, 0), (0, 1))]
    while len(stack) > 0:
        i, (yi, xi), (dy, dx) = stack.pop()

        while i < n:
            if s[i] == 'F':
                yi += dy
                xi += dx
            else:
                stack.append((i + 1, (yi, xi), (dx, -dy)))
                tmp = dy
                dy = -dx
                dx = tmp
            i += 1

        if yi == y and xi == x:
                print('Yes')
                break
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(50000)

UP    = 0
RIGHT = 1
DOWN  = 2
LEFT  = 3

dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

x_dst = None
y_dst = None

def dfs(x, y, d, S):

    if len(S) == 0:
        if x == x_dst and y == y_dst:
            print("Yes")
            sys.exit()
        else:
            return

    if S[0] == "F":
        dfs(x+dx[d], y+dy[d], d, S[1:])
    else:
        dfs(x, y, (d-1)%4, S[1:])
        dfs(x, y, (d+1)%4, S[1:])

def main():
    global x_dst
    global y_dst

    S = input()
    x_dst, y_dst = list(map(int, input().split()))

    x, y = 0, 0
    d = RIGHT

    dfs(x, y, d, S)

    print("No")

main()

Submission status: Time Limit Exceeded

Solution code:
import sys

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
A=len(S)

def check_ans(s,x):
  if len(s)==0:
    return x==0
  
  dp=[[False for i in range(A)] for j in range(len(s)+1)]
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,A):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys

def check_ans(s,x):
  if len(s)==0:
    return x==0
  
  dp=[[False for i in range(8001)] for j in range(len(s)+1)]
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,8001):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys

def check_ans(s,x):
  if len(s)==0 and x!=0:
    return False
  elif len(s)==0 and x==0:
    return True
  dp=[[False for i in range(8002)] for j in range(8002)]
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,8002):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; t = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    t += len(st[i])

T = max([x, y, t])
xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
s = input()
T = len(s)
st = s.split("T")
x, y = map(int, input().split())
XL = []; YL = []
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, gx, gy):
    n = len(s)
    forwards = [len(x) for x in s.split('T')]

    H = len(forwards)
    dpx = [False] * (n * 2 + 2)
    dpy = [False] * (n * 2 + 2)
    dpx[n + forwards[0]] = True
    dpy[n] = True

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False] * f
        p_move = [False] * f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False] * f
        p_move = [False] * f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t

    if dpy[gy + n] is True and dpx[gx + n] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    # s = 'FTFFTFFFT'
    # gx, gy = 4, 2
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s, gx, gy):
    n = len(s)
    forwards = [len(x) for x in s.split('T')]

    H = len(forwards)
    dpx = [False] * (n * 2 + 2)
    dpy = [False] * (n * 2 + 2)
    dpx[n + forwards[0]] = True
    dpy[n] = True

    for f in forwards[2::2]:
        if f == 0:
            continue
        t = [False] * (n * 2 + 2)
        for i in range(n*2 + 1):
            if dpx[i] is True:
                n_move = i - f
                p_move = i + f
                t[n_move] = True
                t[p_move] = True
        dpx = t

    for f in forwards[1::2]:
        if f == 0:
            continue
        t = [False] * (n * 2 + 2)
        for i in range(n * 2 + 1):
            if dpy[i] is True:
                n_move = i - f
                p_move = i + f
                t[n_move] = True
                t[p_move] = True
        dpy = t

    if dpy[gy + n] is True and dpx[gx + n] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    # s = 'FTFFTFFFT'
    # gx, gy = 4, 2

    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
n = max((n, 3))
x, y = map(int, input().split())
dpx = [[False] * 2 * (n + 1) for i in range(n)]
dpy = [[False] * 2 * (n + 1) for i in range(n)]

def c(s, si):
    ret = 0
    while si < len(s) and s[si] == 'F':
        ret += 1
        si += 1
    if si < len(s) and s[si] == 'T':
        si += 1
    return si, ret

si, d = c(s, 0)
dpx[0][n] = True
dpx[1][d+n] = True
dpy[0][n] = True
dp = [dpx, dpy]
turn = 0
while si < len(s):
    si, d = c(s, si)
    turn += 1
    nn = si
    for i in range(-nn, nn+1):
        if -n <= i + d <= n:
            dp[turn%2][turn//2+1][i+d+n] = dp[turn%2][turn//2+1][i+d+n] \
                    or dp[turn%2][turn//2][i+n]
        if -n <= i - d <= n:
            dp[turn%2][turn//2+1][i-d+n] = dp[turn%2][turn//2+1][i-d+n] \
                    or dp[turn%2][turn//2][i+n]

if dpx[(turn-1)//2+2][x+n] and dpy[(turn-1)//2+1][y+n]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
n = max((n, 3))
x, y = map(int, input().split())
dpx = [[False] * 2 * (n + 1) for i in range(n)]
dpy = [[False] * 2 * (n + 1) for i in range(n)]

def c(s):
    ret = 0
    while s and s[0] == 'F':
        ret += 1
        s = s[1:]
    if s and s[0] == 'T':
        s = s[1:]
    return s, ret

s, d = c(s)
dpx[0][n] = True
dpx[1][d+n] = True
dpy[0][n] = True
dp = [dpx, dpy]
turn = 0
while s:
    s, d = c(s)
    turn += 1
    nn = n - len(s)
    for i in range(-nn, nn+1):
        if -n <= i + d <= n:
            dp[turn%2][turn//2+1][i+d+n] = dp[turn%2][turn//2+1][i+d+n] \
                    or dp[turn%2][turn//2][i+n]
        if -n <= i - d <= n:
            dp[turn%2][turn//2+1][i-d+n] = dp[turn%2][turn//2+1][i-d+n] \
                    or dp[turn%2][turn//2][i+n]

if dpx[(turn-1)//2+2][x+n] and dpy[(turn-1)//2+1][y+n]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
n = max((n, 3))
x, y = map(int, input().split())
dpx = [[False] * 2 * (n + 1) for i in range(n)]
dpy = [[False] * 2 * (n + 1) for i in range(n)]

def c(s):
    ret = 0
    while s and s[0] == 'F':
        ret += 1
        s = s[1:]
    if s and s[0] == 'T':
        s = s[1:]
    return s, ret

s, d = c(s)
dpx[0][n] = True
dpx[1][d+n] = True
dpy[0][n] = True
dp = [dpx, dpy]
turn = 0
while s:
    s, d = c(s)
    turn += 1
    for i in range(-n, n+1):
        if -n <= i + d <= n:
            dp[turn%2][turn//2+1][i+d+n] = dp[turn%2][turn//2+1][i+d+n] \
                    or dp[turn%2][turn//2][i+n]
        if -n <= i - d <= n:
            dp[turn%2][turn//2+1][i-d+n] = dp[turn%2][turn//2+1][i-d+n] \
                    or dp[turn%2][turn//2][i+n]

if dpx[(turn-1)//2+2][x+n] and dpy[(turn-1)//2+1][y+n]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:


NORTH = (0, 1)
EAST =  (1, 0)
SOUTH = (0, -1)
WEST = (-1, 0)


def actionF(states):
    new = set()
    for position, direction in states:
        new.add(((position[0] + direction[0], position[1] + direction[1]), direction))
    return new

def actionT(states):
    new = set()
    for position, direction in states:
        if direction == NORTH:
            new.add((position,  EAST))
            new.add((position,  WEST))
        elif direction == EAST:
            new.add((position,  NORTH))
            new.add((position,  SOUTH))
        elif direction == SOUTH:
            new.add((position,  EAST))
            new.add((position,  WEST))
        elif direction == WEST:
            new.add((position,  NORTH))
            new.add((position,  SOUTH))
        else:
            pass
    return new

def foo(instructions, goal):
    states = set([((0,0), EAST)])
    for x in instructions:
        if x == 'T':
            states = actionT(states)
        if x == 'F':
            states = actionF(states)

    if (goal, NORTH) in states or \
            (goal, EAST) in states or \
            (goal, SOUTH) in states or \
            (goal, WEST) in states:
        return "Yes"
    else:
        return "No"


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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
nF = list(map(str, input().split('T')))
finalx, finaly = list(map(int, input().split()))

x = []
y = []
for i in range(len(nF)):
    if i % 2 == 0:
        x.append(len(nF[i]))
    else:
        y.append(len(nF[i]))

posy = [0]
if len(x) == 0:
    posx = [0]
elif len(x) == 1:
    posx = [x[0]]
else:
    posx = [x[0]]
    for i in range(1, len(x)):
        plus_x = list(map(lambda elem: elem + x[i], posx))
        minus_x = list(map(lambda elem: elem - x[i], posx))
        plus_x.extend(minus_x)
        posx = plus_x

if len(y) >= 1:
    for i in range(len(y)):
        plus_y= list(map(lambda elem: elem + y[i], posy))
        minus_y= list(map(lambda elem: elem - y[i], posy))
        plus_y.extend(minus_y)
        posy = plus_y

if finalx in posx and finaly in posy:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s = input()
x , y = map(int,input().split())
 
xlist = []
ylist = []
xory = 1 
xcount,ycount = 0,0 
for i in list(s):
    if i == "T":
        if xcount > 0:
            xlist.append(xcount)
            xcount = 0 
        elif ycount > 0:
            ylist.append(ycount)
            ycount = 0 
        xory = xory * -1
    elif xory == 1:
        xcount += 1
    elif xory == -1: 
        ycount += 1
xlist.append(xcount)
ylist.append(ycount)
 
def check(lis,hi,torf):
    if torf and s[0] == "F":
        numlis = [lis[0]]
    else: 
        numlis = [lis[0],(-1 *lis[0])]
    for i in range(len(lis)-1):
        kari = numlis
        numlis = []
        for i2 in range(len(kari)):
            numlis.append(kari[i2]+lis[i+1])
            numlis.append(kari[i2]-lis[i+1])
    for i in numlis:
        if i == hi: 
            return True
    return False
 
if check(xlist,x,True) and check(ylist,y,False):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
# D - FT Robot
# coding: utf-8

def check(d, to_d):
  meu = [0]
  for i in to_d:
    hoge = []
    for j in meu:
      if not j+i in hoge : hoge.append(j+i) 
      if not j-i in hoge : hoge.append(j-i)
    meu = hoge
  return d in meu

# S = map(len, raw_input().split('T'))
a = raw_input()
S = map(len, a.split('T'))
x, y = map(int, raw_input().split())
to_x, to_y = S[2::2], S[1::2]

print "Yes" if check(x-S[0],to_x) and check(y,to_y) else "No"

Submission status: Time Limit Exceeded

Solution code:
# D - FT Robot
# coding: utf-8

def check(d, to_d):
  meu = [0]
  for i in to_d:
    hoge = []
    for j in meu:
      if not j+i in hoge : hoge.append(j+i) 
      if not j-i in hoge : hoge.append(j-i)
    meu = hoge
  return d in meu

S = map(len, raw_input().split('T'))
x, y = map(int, raw_input().split())
to_x, to_y = S[2::2], S[1::2]

print "Yes" if check(x-S[0],to_x) and check(y,to_y) else "No"

Submission status: Time Limit Exceeded

Solution code:
# D - FT Robot
# coding: utf-8

def check(d, to_d):
  meu = [0]
  for i in to_d:
    hoge = []
    for j in meu:
      hoge.append(j+i), hoge.append(j-i)
    meu = hoge
  return d in meu

S = [ len(F) for F in raw_input().split('T') ]
x, y = map(int, raw_input().split())
to_x, to_y = S[2::2], S[1::2]

print "Yes" if check(x-S[0],to_x) and check(y,to_y) else "No"

Submission status: Time Limit Exceeded

Solution code:
# D - FT Robot
# coding: utf-8

def check(d, to_d):
  meu = [0]
  for i in to_d:
    hoge = []
    for j in meu:
      if not j+i in hoge : hoge.append(j+i) 
      if not j-i in hoge : hoge.append(j-i)
    meu = hoge
  return d in meu

S = [ len(F) for F in raw_input().split('T') ]
x, y = map(int, raw_input().split())
to_x, to_y = S[2::2], S[1::2]

print "Yes" if check(x-S[0],to_x) and check(y,to_y) else "No"

Submission status: Time Limit Exceeded

Solution code:
import math

s=list(input().split('T'))
sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x, y = map(int,input().split(' '))
x = x-sn[0]

snx=[]
sny=[]

for i in range(2,len(sn),2):
    snx.append(sn[i])

for i in range(1,len(sn),2):
    sny.append(sn[i])

#X軸判定
xflg = 0
ansx=[[0]]
for i in range(len(snx)):
    tmpx=[]
    for j in range(len(ansx[i])):
        tmpx.append(ansx[i][j]+snx[i])
        tmpx.append(ansx[i][j]-snx[i])
    ansx.append(tmpx)

if x in ansx[len(snx)]:
    xflg = 1


#y軸判定
yflg = 0
ansy=[[0]]
for i in range(len(sny)):
    tmpy=[]
    for j in range(len(ansy[i])):
        tmpy.append(ansy[i][j]+sny[i])
        tmpy.append(ansy[i][j]-sny[i])
    ansy.append(tmpy)

if y in ansy[len(sny)]:
    yflg = 1

if xflg == 1 and yflg == 1:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

xlist = []
ylist = []
xory = 1 
xcount,ycount = 0,0 
for i in list(s):
    if i == "T":
        if xcount > 0:
            xlist.append(xcount)
            xcount = 0 
        elif ycount > 0:
            ylist.append(ycount)
            ycount = 0 
        xory = xory * -1
    elif xory == 1:
        xcount += 1
    elif xory == -1: 
        ycount += 1
xlist.append(xcount)
ylist.append(ycount)

def check(lis,hi,torf):
    if torf and s[0] == "F":
        numlis = [lis[0]]
    else: 
        numlis = [lis[0],(-1 *lis[0])]
    for i in range(len(lis)-1):
        kari = numlis
        numlis = []
        for i2 in range(len(kari)):
            numlis.append(kari[i2]+lis[i+1])
            numlis.append(kari[i2]-lis[i+1])
    for i in numlis:
        if i == hi: 
            return True
    return False

if check(xlist,x,True) and check(ylist,y,False):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

n = len(s)
dpx = [[False] * (n+1) * 2 for i in range(len(s)+1)]
dpy = [[False] * (n+1) * 2 for i in range(len(s)+1)]
dpxy = [dpx, dpy]
index = 0
origin = len(s)
j = [0, 0]

p = 0
while s and s[0] == 'F':
    p += 1
    s = s[1:]
dpx[0][p+origin] = True
dpy[0][origin] = True
while len(s) > 0:
    p = 0
    while s and s[0] == 'F':
        p += 1
        s = s[1:]
    jj = j[index]
    # print(p)
    # print(dpxy[0][j[0]])
    # print(dpxy[1][j[1]])
    # print('')
    for i, a in enumerate(dpxy[index][jj]):
        if i + p < n + origin:
            dpxy[index][jj+1][i+p] = dpxy[index][jj+1][i+p] or a
        if 0 < i - p:
            dpxy[index][jj+1][i-p] = dpxy[index][jj+1][i-p] or a
    j[index] += 1
    index = (index+1)%2
    if s and s[0] == 'T':
        s = s[1:]

# print(dpxy[0][j[0]])
# print(dpxy[1][j[1]])
if dpxy[0][j[0]][x+origin] and dpxy[1][j[1]][y+origin]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

index = 0
dxys = [(1, 0), (0, -1), (-1, 0), (0, 1)]

ss = set([(0, 0, 0)])
ns = set()
while len(s) > 0:
    c = s[0]
    p = 0
    if c == 'F':
        while len(s) and s[0] == 'F':
            p += 1
            s = s[1:]
    elif c == 'T':
        s = s[1:]
    for e in ss:
        if len(s) + p < abs(e[0] - x) + abs(e[1] - y):
            continue
        if c == 'T':
            ns.add((e[0], e[1], (e[2]+1)%4))
            ns.add((e[0], e[1], (e[2]-1+4)%4))
        elif c == 'F':
            nx, ny = e[0] + p*dxys[e[2]][0], e[1] + p*dxys[e[2]][1]
            ns.add((nx, ny, e[2]))
    ss = ns
    ns = set()

yes = False
for i in range(4):
    if (x, y, i) in ss:
        yes = True
        break
if yes:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

index = 0
dxys = [(1, 0), (0, -1), (-1, 0), (0, 1)]

ss = set([(0, 0, 0)])
ns = set()
while len(s) > 0:
    c = s[0]
    p = 0
    if c == 'F':
        while len(s) and s[0] == 'F':
            p += 1
            s = s[1:]
    elif c == 'T':
        s = s[1:]
    for e in ss:
        if c == 'T':
            ns.add((e[0], e[1], (e[2]+1)%4))
            ns.add((e[0], e[1], (e[2]-1+4)%4))
        elif c == 'F':
            nx, ny = e[0] + p*dxys[e[2]][0], e[1] + p*dxys[e[2]][1]
            ns.add((nx, ny, e[2]))
    ss = ns
    ns = set()

yes = False
for i in range(4):
    if (x, y, i) in ss:
        yes = True
        break
if yes:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
def check(a, numlist):
	goal = a+sum(numlist)
	if goal %2 == 1:
		return False
	goal /=2
	oklist =[0]
	for x in numlist:
		addlist = [ok+x for ok in oklist]
		oklist += addlist
	return goal in oklist



s = [len(x) for x in input().split('T')]
x,y = [int(i) for i in input().split()]
x = x-s[0]
sx = s[2::2]
sy = s[1::2]
if check(x,sx) and check(y,sy):
	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 moji in s:
    if moji == 'F':
        susumu[-1] += 1
    else:
        susumu.append(0)

#print(susumu)

syokiti = susumu[0]

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

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)):
    for i in range(2*LL):
    #        a=0
    #        print(i+susumu_NS[j])
        if dp[j][i] != 0:
            if i + susumu_NS[j] < 2*LL:
                dp[j+1][i+susumu_NS[j]] |= dp[j][i]
            if i >= susumu_NS[j]:
                dp[j+1][i-susumu_NS[j]] |= dp[j][i]
can_y = 0
if dp[len(susumu_NS)][y+LL] != 0:
    can_y = 1
#print(dp)
#print(susumu_NS)

#########################################
LL = len(s)+2
dp = [[0 for i in range(2*LL)] for j in range(1+len(susumu_EW))]
dp[0][LL] = 1
#move = min(LL,(sum(susumu_EW)+1)//2)
for j in range(len(susumu_EW)):
    for i in range(2*LL):
    #        a=0
    #        print(i+susumu_NS[j])
        if dp[j][i] != 0:
            if i + susumu_EW[j] < 2*LL:
                dp[j+1][i+susumu_EW[j]] |= dp[j][i]
            if i >= susumu_EW[j]:
                dp[j+1][i-susumu_EW[j]] |= dp[j][i]
can_x = 0
if dp[len(susumu_EW)][x+LL] != 0:
    can_x = 1

#print(dp)
#print(susumu_EW)

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