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()
l = len(s)
X, Y = (int(x) for x in input().split())
F = s.split("T")
X -= F[0].count("F")
y_move = [f.count("F") for f in F[1::2]]
x_move = [f.count("F") for f in F[2::2]]

dpy = [[False] * (2 * l + 5) for _ in range(len(y_move) + 1)]
dpx = [[False] * (2 * l + 5) for _ in range(len(x_move) + 1)]
dpx[0][0] = dpy[0][0] = True

for i in range(1, len(x_move) + 1):
    for x in range(-l - 2, l + 2):
        if -l <= x - x_move[i - 1] <= l:
            dpx[i][x] |= dpx[i - 1][x - x_move[i - 1]]
        if -l <= x + x_move[i - 1] <= l:
            dpx[i][x] |= dpx[i - 1][x + x_move[i - 1]]

for i in range(1, len(y_move) + 1):
    for y in range(-l - 2, l + 2):
        if -l <= y - y_move[i - 1] <= l:
            dpy[i][y] |= dpy[i - 1][y - y_move[i - 1]]
        if -l <= y + y_move[i - 1] <= l:
            dpy[i][y] |= dpy[i - 1][y + y_move[i - 1]]

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
x,y=map(int,input().split())
t=s.split("T")
x-=len(t[0])
dx,dy=[],[]

for i,tt in enumerate(t[1:]):
  if i%2==1:
    dx.append(len(tt))
  else:
    dy.append(len(tt))
x=abs(x)
y=abs(y)
if max(x,y)>8000:
  print("No")
  exit(0)
def is_ok(n,l):
  dp=[[0]*16001 for _ in range(len(l)+1)]
  n+=8000
  dp[0][8000]=1
  for i in range(1,len(l)+1):
    for j in range(16001):
      if j+l[i-1]<=16000:
        dp[i][j+l[i-1]]|=dp[i-1][j]
      if j-l[i-1]>=0:
        dp[i][j-l[i-1]]|=dp[i-1][j]
  if dp[len(l)][n]==1:
    return True
  else:
    return False

if is_ok(abs(x),dx) and is_ok(abs(y),dy):
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=input().rstrip().split("T")
x,y=MI()
#print(s)
lisx=[]
lisy=[]
x-=len(s[0])
for i in range(1,len(s)):
    if i%2==0:
        lisx.append(len(s[i]))
    else:
        lisy.append(len(s[i]))
resx=[[] for i in range(len(lisx)+1)]
resy=[[] for i in range(len(lisy)+1)]
resx[0]=[0]
resy[0]=[0]
#print(lisx)
for i in range(len(lisx)):
    for j in range(len(resx[i])):
        resx[i+1].append(resx[i][j]+lisx[i])
        resx[i+1].append(resx[i][j]-lisx[i])
    #resx[i+1]=list(set(resx[i+1]))
#print(resx)
for i in range(len(lisy)):
    for j in range(len(resy[i])):
        resy[i+1].append(resy[i][j]+lisy[i])
        resy[i+1].append(resy[i][j]-lisy[i])
    #resy[i+1]=list(set(resy[i+1]))
#print(lisy)
#print(resy)
if x in resx[-1] and y in resy[-1]:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import deque
    import numpy as np

    s = input() + 'T'
    x, y = map(int, input().split())
    m = [[], []]
    i = 0
    c = 0
    for k in s:
        if k == 'F':
            c += 1
        else:
            m[i].append(c)
            c = 0
            i = 1 - i

    xs = deque(m[0][1:])
    ys = deque(m[1])
    p = np.array([m[0][0]])
    while xs:
        k = xs.popleft()
        p = np.concatenate([p + k, p - k])

    if x not in p:
        print('No')
        exit()

    q = np.array([0])
    while ys:
        k = ys.popleft()
        q = np.concatenate([q + k, q - k])

    if y not in q:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
MAX_SIZE = 16_001
OFFSET = 8_000

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

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
MAX_SIZE = 16_001
OFFSET = 8_000

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

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

s = input() + "T"
x, y = map(int, input().split())

stepx = []
stepy = []

headx = True
step = 0
for c in s:
    if c == "F":
        step += 1
    else:
        if headx:
            stepx.append(step)
        else:
            stepy.append(step)
        headx = not headx
        step = 0

x -= stepx[0]
stepx = stepx[1:]


class Reachable:
    def __init__(self, steps):
        self.steps = steps

        self.maxs = sum(steps)
        self.r = [{} for _ in range(len(steps))]

    def __call__(self, i, s):
        if i == -1:
            return s == 0
        elif not -self.maxs <= s <= self.maxs:
            return False
        elif self.r[i].get(s, None) is not None:
            return self.r[i][s]
        else:
            step = self.steps[i]
            r = self(i - 1, s - step) or self(i - 1, s + step)
            self.r[i][s] = r
            return r


answer = Reachable(stepx)(len(stepx) - 1, x) and Reachable(stepy)(len(stepy) - 1, y)

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

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

s = input() + "T"
x, y = map(int, input().split())

stepx = []
stepy = []

headx = True
step = 0
for c in s:
    if c == "F":
        step += 1
    else:
        if headx:
            stepx.append(step)
        else:
            stepy.append(step)
        headx = not headx
        step = 0

x -= stepx[0]
stepx = stepx[1:]


class Reachable:
    def __init__(self, steps):
        self.steps = steps

        self.maxs = sum(steps)
        self.r = {
            i: {s: None for s in range(-self.maxs, self.maxs + 1)}
            for i in range(len(steps))
        }

    def __call__(self, i, s):
        if i == -1:
            return s == 0
        elif not -self.maxs <= s <= self.maxs:
            return False
        elif self.r[i][s] is not None:
            return self.r[i][s]
        else:
            step = self.steps[i]
            r = self(i - 1, s - step) or self(i - 1, s + step)
            self.r[i][s] = r
            return r


answer = Reachable(stepx)(len(stepx) - 1, x) and Reachable(stepy)(len(stepy) - 1, y)

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

Submission status: Time Limit Exceeded

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
gx,gy = IL()

data = [0]
flag = 0
for s in S:
  if s == "F":
    if flag:
      flag = 0
      data.append(1)
    else:
      data[-1] = data[-1]+1
  else:
    if flag == 0:
      flag = 1
      data.append(1)
    else:
      data[-1] = 1-data[-1]

if len(data)%2 == 0:
  data.pop()
data = data[::-1]
shote = data.pop()
gx -= shote
D = [[0],[0]]
f = 0


while data:
  f ^= data.pop()
  D[f].append(data.pop())
  
  
dpx =  [[0 for i in range(20000)] for j in range(len(D[0]))]
dpy =  [[0 for i in range(20000)] for j in range(len(D[1]))]
dpx[0][10000] = 1
dpy[0][10000] = 1
for j in range(1,len(D[0])):
  d = D[0][j]
  for i in range(20000):
    if i+d < 20000:
      if dpx[j-1][i+d]:
        dpx[j][i] = 1
    if 0 <= i-j:
      if dpx[j-1][i-d]:
        dpx[j][i] = 1
for j in range(1,len(D[1])):
  d = D[1][j]
  for i in range(20000):
    if i+d < 20000:
      if dpy[j-1][i+d]:
        dpy[j][i] = 1
    if 0 <= i-j:
      if dpy[j-1][i-d]:
        dpy[j][i] = 1
        
if dpx[-1][10000+gx] and dpy[-1][10000+gy]: 
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    step = C[i][1]
    nex = set()
    if dirX:
      for n in now:
        if n[0] + step <= 8000:
          nex.add((n[0] + step,n[1]))
        if n[0] - step >= -8000:
          nex.add((n[0] - step,n[1]))
    else:
      for n in now:
        if n[1] + step <= 8000:
          nex.add((n[0],n[1] + step))
        if n[1] - step >= -8000:
          nex.add((n[0],n[1] - step))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    step = C[i][1]
    nex = set()
    if dirX:
      for n in now:
        nex.add((n[0] + step,n[1]))
        nex.add((n[0] - step,n[1]))
    else:
      for n in now:
        nex.add((n[0],n[1] + step))
        nex.add((n[0],n[1] - step))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline

S = readline().rstrip()
gx,gy = map(int,readline().split())

C = []

import itertools
for key,g in itertools.groupby(S):
  C.append([key,len(list(g))])
  
x,y = 0,0
ind = 0
if C[0][0] == "F":
  x += C[0][1]
  ind = 1

# Xの方向を向いている
dirX = True
now = set([(x,y)])
for i in range(ind,len(C)):
  if C[i][0] == "F":
    nex = set()
    for n in now:
      if dirX:
        nex.add((n[0] + C[i][1],n[1]))
        nex.add((n[0] - C[i][1],n[1]))
      else:
        nex.add((n[0],n[1] + C[i][1]))
        nex.add((n[0],n[1] - C[i][1]))
    now = nex
  else:
    if C[i][1] % 2 == 1:
      dirX ^= True
    
if (gx,gy) in now:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

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

dpx = [0 for i in range(17000)]
dpy = [0 for i in range(17000)]

dpx[8500] = 1
dpy[8500] = 1

f = s.split("T")

fx = []
fy = []

for i, fi in enumerate(f):
    if i % 2:
        fy.append(len(fi))
    else:
        fx.append(len(fi))

for i, fxi in enumerate(fx):
    nex = [0] * 17000
    for j in range(17000):
        if dpx[j]:
            if fxi + j < 17000:
                nex[fxi + j] = 1
            if i > 0 and j - fxi >= 0:
                nex[j - fxi] = 1
    dpx = nex
        
for fyi in fy:
    nex = [0] * 17000
    for j in range(17000):
        if dpy[j]:
            if fyi + j < 17000:
                nex[fyi + j] = 1
            if j - fyi >= 0:
                nex[j - fyi] = 1
    dpy = nex

if dpx[x] and dpy[y]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

dpx = [0 for i in range(17000)]
dpy = [0 for i in range(17000)]

dpx[8500] = 1
dpy[8500] = 1

f = s.split("T")

fx = []
fy = []

for i, fi in enumerate(f):
    if i % 2:
        fy.append(len(fi))
    else:
        fx.append(len(fi))

for i, fxi in enumerate(fx):
    nex = [0] * 17000
    for j in range(17000):
        if dpx[j]:
            if fxi + j < 17000:
                nex[fxi + j] = 1
            if i > 0 and j - fxi >= 0:
                nex[j - fxi] = 1
    dpx = nex[:]
        
for fyi in fy:
    nex = [0] * 17000
    for j in range(17000):
        if dpy[j]:
            if fyi + j < 17000:
                nex[fyi + j] = 1
            if j - fyi >= 0:
                nex[j - fyi] = 1
    dpy = nex[:]

if dpx[x] and dpy[y]:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
s += "T"
x,y = map(int,input().split())
mvx = []
mvy = []
now = "x"
cnt = 0
for c in s:
    if c == "F": cnt += 1
    else:
        if now == "x":
            mvx.append(cnt)
            now = "y"
        else:
            mvy.append(cnt)
            now = "x"
        cnt = 0

lx = len(mvx)
dpx = [[False]*(2*l+1) for _ in range(lx+1)]
dpx[0][l] = True
dpx[1][l+mvx[0]] = True
for i in range(1,lx):
    for j in range(2*l+1):
        if j-mvx[i] >= 0: dpx[i+1][j] = dpx[i+1][j] | dpx[i][j-mvx[i]]
        if j+mvx[i] <= 2*l: dpx[i+1][j] = dpx[i+1][j] | dpx[i][j+mvx[i]]

ly = len(mvy)
dpy = [[False]*(2*l+1) for _ in range(ly+1)]
dpy[0][l] = True
for i in range(ly):
    for j in range(2*l+1):
        if j-mvy[i] >= 0: dpy[i+1][j] = dpy[i+1][j] | dpy[i][j-mvy[i]]
        if j+mvy[i] <= 2*l: dpy[i+1][j] = dpy[i+1][j] | dpy[i][j+mvy[i]]

print("Yes" if dpx[-1][x+l] and dpy[-1][y+l] else "No")

Submission status: Time Limit Exceeded

Solution code:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    OFS = 8000
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
S = input()
gx, gy = map(int, input().split())

from collections import deque
# 命令, x, y, 向き
q = deque([[-1, 0, 0, (1, 0)]])

ans = 'No'
while q:
    i, x, y, rot = q.popleft()
    if i == len(S)-1 and x==gx and y == gy:
        ans = 'Yes'
        break
    elif i == len(S)-1:
        continue
    ind = S[i+1]

    if ind == 'T':
        q.append((i+1, x, y, (-rot[1], rot[0])))
        q.append((i+1, x, y, (rot[1], -rot[0])))
    else:
        if abs(gx-x-rot[0]) + abs(gy-y-rot[1]) < len(S)-i:
            q.append((i+1, x+rot[0], y+rot[1], rot))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
gx, gy = map(int, input().split())

from collections import deque
q = deque([[-1, 0, 0, (1, 0)]])

ans = 'No'
while q:
    i, x, y, rot = q.popleft()

    if i == len(s)-1 and x==gx and y == gy:
        ans = 'Yes'
        break
    elif i == len(s)-1:
        continue
    
    ind = s[i+1]

    if ind == 'F':
        q.append((i+1, x+rot[0], y+rot[1], rot))
    else:
        q.append((i+1, x, y, (-rot[1], rot[0])))
        q.append((i+1, x, y, (rot[1], -rot[0])))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
x,y=map(int,input().split())
xpossible=[0]
ypossible=[0]
j=0
while s[j]=='F':
  xpossible[0]+=1
  if j==len(s):
    break
counter=0
for i in range(j,len(s)):
  current=0
  while s[i]=='F':
    current+=1
    if i==len(s):
      break
  r=set()
  if counter==0:
    for j in xpossible:
      r.add(j+current)
      r.add(j-current)
    xpossible=[]
    for j in r:
      xpossible.append(j)
  else:
    for j in ypossible:
      r.add(j+current)
      r.add(j-current)
    ypossible=[]
    for j in r:
      ypossible.append(j)
  current=0
  while s[i]=='T':
    i+=1
    current+=1
    if i==len(s):
      break
  counter=(counter+current)%2
if x in xpossible and y in ypossible:
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
s=input()
x,y=map(int,input().split())
xpossible=[0]
ypossible=[0]
j=0
while s[j]=='F':
  xpossible[0]+=1
  if j==len(s):
    break
counter=0
for i in range(j,len(s)):
  current=0
  while s[i]=='F':
    current+=1
    if i==len(s):
      break
  r=set()
  if counter==0:
    for j in xpossible:
      r.add(j+current)
      r.add(j-current)
    xpossible=[]
    for j in r:
      xpossible.append(j)
  else:
    for j in ypossible:
      r.add(j+current)
      r.add(j-current)
    ypossible=[]
    for j in r:
      ypossible.append(j)
  current=0
  while s[i]=='T':
    current+=1
  counter=(counter+current)%2
if x in xpossible and y in ypossible:
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
s=input()
x,y=map(int,input().split())
ss=[len(i) for i in s.split("T")]
x-=ss[0]
a=[]
b=[]
for i in range(1,len(ss)):
  if ss[i]==0:continue
  if i%2==1:b.append(ss[i])
  else:a.append(ss[i])
x=abs(x)
y=abs(y)
def check(n,a):
  dp=[[0]*40001 for _ in range(len(a)+1)]
  n+=20000
  dp[0][20000]=1
  for i in range(1,len(a)+1):
    for j in range(40001):
      if j+a[i-1]<=40000:dp[i][j+a[i-1]]|=dp[i-1][j]
      if j-a[i-1]>=0:dp[i][j-a[i-1]]|=dp[i-1][j]
  if dp[len(a)][n]==1:return True
  return False
if check(x,a) and check(y,b):print("Yes")
else:print("No")

Submission status: Time Limit Exceeded

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

ver = []
hor = []
ini = 0
flag = 'h1'
tmp = 0

for i in range(len(s)):
    if s[i] == 'T':
        if flag == 'h':
            if tmp > 0:
                hor.append(tmp)
            tmp = 0
            flag = 'v'
        elif flag == 'v':
            if tmp > 0:
                ver.append(tmp)
            flag = 'h'
            tmp = 0
        elif flag == 'h1':
            if tmp > 0:
                ini = tmp
            flag = 'v'
            tmp = 0
    else:
        tmp += 1

if tmp > 0:
    if flag == 'h1':
        ini = tmp
    elif flag == 'h':
        hor.append(tmp)
    elif flag == 'v':
        ver.append(tmp)

num = 8000
        
ver_li = [[0 for i in range(2)] for j in range(num*2+1)]
hor_li = [[0 for i in range(2)] for j in range(num*2+1)]

hor_li[num+ini][0] = 1
#print(sum(hor))
#exit()

for i in range(len(hor)):
    #c_hor = copy.deepcopy(hor_li)
    for j in range(num*2+1):
        if hor_li[j][0] == 1:
            #print(j,hor[i],i)
            hor_li[j][1] = 0
            hor_li[j+hor[i]][1] = 1
            hor_li[j-hor[i]][1] = 1
    for j in range(num*2+1):
        hor_li[j][0] = hor_li[j][1]

ver_li[num][0] = 1
for i in range(len(ver)):
    #c_ver = copy.deepcopy(ver_li)
    for j in range(num*2+1):
        if ver_li[j][0] == 1:
            ver_li[j][1] = 0
            #print(hor[i])
            ver_li[j+ver[i]][1] = 1
            ver_li[j-ver[i]][1] = 1
    for j in range(num*2+1):
        ver_li[j][0] = ver_li[j][1]
    
if hor_li[num+x][0] == 1 and ver_li[num+y][0] == 1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from itertools import groupby
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = input()

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

d = [len(i) for i in s.split('T')]

x_li = d[2::2]
X = len(x_li)
y_li = d[1::2]
Y = len(y_li)

x -= d[0]

x_flag = False
y_flag = False

def x_kumi(n,now):
    global x_flag
    if n == X:
        if now == x:
            x_flag = True
    else:
        return x_kumi(n+1,now+x_li[n]),x_kumi(n+1,now-x_li[n])

def y_kumi(n,now):
    global y_flag
    if n == Y:
        if now == y:
            y_flag = True
    else:
        return y_kumi(n+1,now+y_li[n]),y_kumi(n+1,now-y_li[n])

x_kumi(0,0)
y_kumi(0,0)

if x_flag and y_flag:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7


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

N = 8010

X = [0]
Y = [0]
flag = True
for s in S:
    if s == 'F':
        if flag:
            X[-1] += 1
        else:
            Y[-1] += 1
    else:
        if flag:
            if Y[-1] != 0:
                Y.append(0)
        else:
            if X[-1] != 0:
                X.append(0)
        flag = not flag

dp = [[0] * (2 * N) for _ in range(2)]
if S[0] == 'F':
    dp[0][X[0] + N] = 1
else:
    dp[0][X[0] + N] = 1
    dp[0][-X[0] + N] = 1

for i in range(1, len(X)):
    x_ = X[i]
    for j in range(2 * N):
        dp[i % 2][j] = 0
        if j >= x_:
            if dp[(i - 1) % 2][j - x_]:
                dp[i % 2][j] = 1
        if j + x_ < 2 * N:
            if dp[(i - 1) % 2][j + x_]:
                dp[i % 2][j] = 1

# print (dp)
if dp[(len(X) - 1) % 2][x + N] == 0:
    print ('No')
    exit()

dp = [[0] * (2 * N) for _ in range(2)]
dp[0][Y[0] + N] = 1
dp[0][-Y[0] + N] = 1

for i in range(1, len(Y)):
    y_ = Y[i]
    for j in range(2 * N):
        dp[i % 2][j] = 0
        if j >= y_:
            if dp[(i - 1) % 2][j - y_]:
                dp[i % 2][j] = 1
        if j + y_ < 2 * N:
            if dp[(i - 1) % 2][j + y_]:
                dp[i % 2][j] = 1

if dp[(len(Y)-1) % 2][y + N] == 0:
    print ('No')
    exit()

print ('Yes')

Submission status: Time Limit Exceeded

Solution code:
order = list(input())
X, Y = map(int, input().split())
lis = []
now = 0
import sys
sys.setrecursionlimit(4100000)
from functools import lru_cache
for s in order:
    if s=='T':
        now = 0
        lis.append(0)
    else:
        if now:
            lis[-1] += 1
        else:
            lis.append(1)
            now = 1

N = len(lis)
dirc = ((0, 1), (1, 0), (0, -1), (-1, 0))
@lru_cache(maxsize=1000)
def dfs(idx, v, d):
    x, y = v
    if idx==N:
        if x==X and y==Y:
            return 1
        else:
            return 0
    ret = 0
    if lis[idx]==0:
        if d==0:
            nd = [1, 3]
        elif d==3:
            nd = [0, 2]
        else:
            nd = [d-1, d+1]
        for i in nd:
            ret += dfs(idx+1, v, i)
    else:
        num = lis[idx]
        dx, dy = dirc[d]
        ret += dfs(idx+1, (x+dx*num, y+dy*num), d)
    return ret

if dfs(0, (0, 0), 1):
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7


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

N = 8010

X = [0]
Y = [0]
flag = True
for s in S:
    if s == 'F':
        if flag:
            X[-1] += 1
        else:
            Y[-1] += 1
    else:
        if flag:
            if Y[-1] != 0:
                Y.append(0)
        else:
            if X[-1] != 0:
                X.append(0)
        flag = not flag

dp = [[False] * (2 * N) for _ in range(len(X))]
if S[0] == 'F':
    dp[0][X[0] + N] = True
else:
    dp[0][X[0] + N] = True
    dp[0][-X[0] + N] = True

for i in range(1, len(X)):
    x_ = X[i]
    for j in range(2 * N):
        if j >= x_:
            if dp[i - 1][j - x_]:
                dp[i][j] = True
        if j + x_ < 2 * N:
            if dp[i - 1][j + x_]:
                dp[i][j] = True

# print (dp)
if not dp[-1][x + N]:
    print ('No')
    exit()

dp = [[False] * (2 * N) for _ in range(len(Y))]
dp[0][Y[0] + N] = True
dp[0][-Y[0] + N] = True

for i in range(1, len(Y)):
    y_ = Y[i]
    for j in range(2 * N):
        if j >= y_:
            if dp[i - 1][j - y_]:
                dp[i][j] = True
        if j + y_ < 2 * N:
            if dp[i - 1][j + y_]:
                dp[i][j] = True

if not dp[-1][y + N]:
    print ('No')
    exit()

print ('Yes')