Problem:


Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        dp_x[x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    if not y_move:
        dp_y[0] = True
    else:
        dp_y[y_move[0]] = True
        dp_y[-y_move[0]] = True
        for y in y_move[1:]:
            tmp = defaultdict(bool)
            for key, val in dp_y.items():
                tmp[key+y] = True
                tmp[key-y] = True
            dp_y = tmp

    # print(S_parsed)
    # print(x_move)
    # print(y_move)
    # print(dp_x)
    # print(dp_y)
    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        dp_x[x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    dp_y[0] = True
    if len(y_move) > 0:
        for y in y_move:
            tmp = defaultdict(bool)
            for key, val in dp_y.items():
                tmp[key+y] = True
                tmp[key-y] = True
            dp_y = tmp

    # print(S_parsed)
    # print(x_move)
    # print(y_move)
    # print(dp_x)
    # print(dp_y)
    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        dp_x[x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key] = val
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    dp_y[0] = True
    if len(y_move) > 0:
        for y in y_move:
            tmp = defaultdict(bool)
            for key, val in dp_y.items():
                tmp[key] = val
                tmp[key+y] = True
                tmp[key-y] = True
            dp_y = tmp

    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()

Submission status: Wrong Answer

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

f = 0
o = 0
s = s + "T"
while s[f] == "F":
    o += 1
    f += 1

a = 0
b = 0
muki = 0
while f != len(s):
    if s[f] == "T":
        muki = 1 - muki
    elif muki == 0:
        a += 1
    else:
        b += 1
    f += 1

if o-a <= x <= o+a and -b <= y <= b:
    if (x-o)%2 == a%2 and y%2 == b%2:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
import gc
def dp(l, z):
    length = len(l)
    m=24000
    dp=[[0]*m for i in range(length+1)]
    dp[0][0]=1
    for i in range(1, length+1):
        for j in range(m):
            if dp[i-1][j]==1:
                dp[i][(j+l[i-1])%m]=1
                dp[i][(j-l[i-1])%m]=1
    res = dp[length][z%m]
    del dp
    gc.collect()
    return res
def solve():
    s=input()
    x, y = map(int, input().split())
    lists = []
    tmp=0
    for si in s:
        if si=='F':
            tmp+=1
        else:
            lists.append(tmp)
            tmp=0
    lists.append(tmp)
    if dp(lists[::2], x) and dp(lists[1::2], y):
        print('Yes')
    else:
        print('No')
solve()

Submission status: Wrong Answer

Solution code:
def dp(l, z):
    length = len(l)
    m=16100
    dp=[[0]*m for i in range(length+1)]
    dp[0][0]=1
    for i in range(1, length+1):
        for j in range(m):
            if dp[i-1][j]==1:
                dp[i][(j+l[i-1])%m]=1
                dp[i][(j-l[i-1])%m]=1
    res = dp[length][z%m]
    del dp
    return res
def solve():
    s=input()
    x, y = map(int, input().split())
    lists = []
    tmp=0
    for si in s:
        if si=='F':
            tmp+=1
        else:
            lists.append(tmp)
            tmp=0
    lists.append(tmp)
    if dp(lists[::2], x) and dp(lists[1::2], y):
        print('Yes')
    else:
        print('No')
solve()

Submission status: Wrong Answer

Solution code:
def dp(l, z):
    length = len(l)
    m=16010
    dp=[[0]*m for i in range(length+1)]
    dp[0][0]=1
    for i in range(1, length+1):
        for j in range(m):
            if dp[i-1][j]==1:
                dp[i][(j+l[i-1])%m]=1
                dp[i][(j-l[i-1])%m]=1
    return dp[length][z]
def solve():
    s=input()
    x, y = map(int, input().split())
    lists = []
    tmp=0
    for si in s:
        if si=='F':
            tmp+=1
        else:
            lists.append(tmp)
            tmp=0
    lists.append(tmp)
    if dp(lists[::2], x) and dp(lists[1::2], y):
        print('Yes')
    else:
        print('No')
solve()

Submission status: Wrong Answer

Solution code:
from collections import deque


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

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

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
dxdy=[0,0]
a=0
for i in s:
    if i=='T':
        if a==0:
            a=1
        else:
            a=0
    else:
        dxdy[a]+=1
mod=2
if 'T' not in s and x==len(s) and y==0:
    print('Yes')
elif 'T' in s and dxdy[0]%mod==x%mod and dxdy[1]%mod==y%mod and dxdy[0]>=abs(x) and dxdy[1]>=abs(y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
dxdy=[0,0]
a=0
for i in s:
    if i=='T':
        if a==0:
            a=1
        else:
            a=0
    else:
        dxdy[a]+=1
mod=2
if dxdy[0]%mod==x%mod and dxdy[1]%mod==y%mod and dxdy[0]>=abs(x) and dxdy[1]>=abs(y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
dxdy=[0,0]
a=0
for i in s:
    if i=='T':
        if a==0:
            a=1
        else:
            a=0
    else:
        dxdy[a]+=1
mod=2
if dxdy[0]%mod==x%mod and dxdy[1]%mod==y%mod and dxdy[0]<=x and dxdy[1]<=y:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
dxdy=[0,0]
a=0
for i in s:
    if i=='T':
        if a==0:
            a=1
        else:
            a=0
    else:
        dxdy[a]+=1
mod=2
if dxdy[0]%mod==x%mod and dxdy[1]%mod==y%mod:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int, input().split())
px=[(0,1)]
py=[(0,0)]
for k in s:
    npx=set()
    npy=set()
    for i,ho in px:
        if k=='F':
            npx.add((i+ho,ho))
        else:
            npx|={(i,(ho+1)%2),(i,-((ho+1)%2))}
    for j,ho in py:
        if k=='F':
            npy.add((j+ho,ho))
        else:
            npy|={(j,(ho+1)%2),(j,-((ho+1)%2))}
    px=npx
    py=npy
ans='No'
for (i,ho1),(j,ho2) in zip(px,py):
    if i==x and j==y:ans='Yes'
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			if l != 0:
				X.append(l)
			judge = "y"
		else:
			if l != 0:
				Y.append(l)
			judge = "x"
		l = 0

if judge == "x":
	X.append(l)
else:
	Y.append(l)

jj = "bad"
if len(s) >= 2:
	if s[0] == "T" and s[1] == "T":
		jj = "good"


dx = defaultdict(int)
if X != []:
	if jj == "good":
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])
else:
	dx[0] = 1

for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D


dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
else:
	dy[0] = 1

for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			X.append(l)
			judge = "y"
		else:
			judge == "y"
			Y.append(l)
			judge = "x"
		l =0

if judge == "x":
	X.append(l)
else:
	Y.append(l)

jj = "bad"
if len(s) >= 2:
	if s[0] == "T" and s[1] == "T":
		jj = "good"


dx = defaultdict(int)
if X != []:
	if jj == "good":
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])

for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D

dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

def DP(i, z, Move = list):
    canMove = set([0])
    for j in range(i):
        temp = []
        for item in canMove:
            temp.append(item+Move[j])
            temp.append(item-Move[j])
        canMove = set(temp)
    return z in canMove

if DP(len(MoveX), x, MoveX) and DP(len(MoveY), y, MoveY): print("Yes")
else: print("No")

Submission status: Wrong Answer

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

def Status(z, i):
    return (-1 if z < i else 0 if z == i else 1)

stat = [Status(0, x), Status(0, y)]
pos = [0, 0]
Dir = ["E", "N", "W", "S"]
currentDir = "E"

def Move(cdir, pos):
    if cdir == "E": return [pos[0]+1, pos[1]]
    elif cdir == "W": return [pos[0]-1, pos[1]]
    elif cdir == "N": return [pos[0], pos[1]+1]
    elif cdir == "S": return [pos[0], pos[1]-1]

def Turn(cdir, stat):
    if cdir == "E": return ("L" if stat[1] <= 0 else "R")
    elif cdir == "W": return ("R" if stat[1] <= 0 else "L")
    elif cdir == "N": return ("R" if stat[0] <= 0 else "L")
    else: return ("L" if stat[0] <= 0 else "R")

def ChangeDir(cdir, turn, Dir):
    if turn == "R":
        return Dir[Dir.index(cdir)-1]
    else:
        i = Dir.index(cdir)
        if i < 3: return Dir[i+1]
        else: return Dir[0]

for i in range(len(s)):
    if s[i] == "F":
        pos = Move(currentDir, pos)
        stat = [Status(pos[0], x), Status(pos[1], y)]
    else:
        currentDir = ChangeDir(currentDir, Turn(currentDir, stat), Dir)

print("Yes" if pos == [x, y] else "No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
dp_x = {0}
for i in m[::2]:
    new_dp = set()
    for v in dp_x:
        new_dp.add(v + i)
        new_dp.add(v - i)
    dp_x = new_dp

dp_y = {0}
for i in m[1::2]:
    new_dp = set()
    for v in dp_y:
        new_dp.add(v + i)
        new_dp.add(v - i)
    dp_y = new_dp

print('Yes' if x in dp_x and y in dp_y else 'No')

Submission status: Wrong Answer

Solution code:
s=input()
a,b =map(int,input().split())
table=[[] for i in range(2)]#0が横1が縦
t = 0
k=0
for i in range(len(s)):
    if s[i]=='F':
        k+=1
    else:
        table[t].append(k)
        t=(t+1)%2
        k=0
table[t].append(k)
#booldp [2][x] 
L=2*len(s)+1
dp=[[[False]*(L) for i in range(len(table[0])+1)]]
dp+=[[[False]*(L) for i in range(len(table[1])+1)]]
dp[0][0][len(s)]=True
dp[1][0][len(s)]=True
#print(table)
for k in range(2):
    for i in range(len(table[k])):
        x=table[k][i]
        for z in range(L):
            if 0<= z+x <L:
                dp[k][i+1][z+x] |= dp[k][i][z]
            if 0<= z-x <L:
                dp[k][i+1][z-x] |= dp[k][i][z]
if dp[0][len(table[0])][a+len(s)] and dp[1][len(table[1])][b+len(s)]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
s=input()
[x,yy]=i2()
t=[]
y=[]
k=0
for i in range(len(s)):
  if s[i]=="T":
     if len(t)==len(y):
        y.append(k)
     else:
        t.append(k)
     k=0
  else:
     k+=1
if s[-1]=="F":
     if len(t)==len(y):
        y.append(k)
     else:
        t.append(k)  
dx=[0 for i in range(8001)]
dy=[0 for i in range(8001)]
dx[0]=1
dy[0]=1
t.sort()
y.sort()
t=t[::-1]
y=y[::-1]
for i in t:
 for j in range(8001):
   if j+i<=8000:dy[j+i]=dy[j]
   if j-i>=0:dy[j-i]=dy[j]
   if j!=0:dy[j]=0

for i in y:
 for j in range(8001):
   if j+i<=8000:dx[j+i]=dx[j]
   if j-i>=0:dx[j-i]=dx[j]
   if i!=0:dx[j]=0

if dy[abs(yy)]*dx[abs(x)]:
   print("Yes")
else:
   print("No")

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
s=input()
[x,yy]=i2()
t=[]
y=[]
k=0
for i in range(len(s)):
  if s[i]=="T":
     if len(t)==len(y):
        y.append(k)
     else:
        t.append(k)
     k=0
  else:
     k+=1
if s[-1]=="F":
     if len(t)==len(y):
        y.append(k)
     else:
        t.append(k)  
dx=[0 for i in range(8001)]
dy=[0 for i in range(8001)]
dx[0]=1
dy[0]=1
t.sort()
y.sort()
t=t[::-1]
y=y[::-1]
for i in t:
 for j in range(8001):
   if j+i<=8000:dy[j+i]=dy[j]
   if j-i>=0:dy[j-i]=dy[j]

for i in y:
 for j in range(8001):
   if j+i<=8000:dx[j+i]=dx[j]
   if j-i>=0:dx[j-i]=dx[j]

if dy[abs(yy)]*dx[abs(x)]:
   print("Yes")
else:
   print("No")

Submission status: Wrong Answer

Solution code:
import sys

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

s_yoko = sorted([len(s[i]) for i in range(1, len(s), 2)])
s_tate = sorted([len(s[i]) for i in range(0, len(s), 2)])

for i in range(len(s_yoko)):
	if sum(s_yoko) < x:
		print("No")
		sys.exit()
	elif sum(s_yoko) == x:
		break
	else:
		s_yoko[i] = -s_yoko[i]

if sum(s_yoko) == x:
	for i in range(len(s_tate)):
		if sum(s_tate) < y:
			print("No")
			sys.exit()
		elif sum(s_tate) == y:
			break
		else:
			s_tate[i] = -s_tate[i]

	if sum(s_tate) == y:
		print("Yes")
	else:
		print('No')
else:
	print("No")

Submission status: Wrong Answer

Solution code:
X, Y = range(2)

i = 0
s = raw_input().strip()
n = len(s)
x, y = map(int, raw_input().strip().split())

while i < n and s[i] == "F":
    i += 1

cx, cy = i, 0
cdi = X

for j in xrange(i, n):
    ch = s[j]
    if ch == "T":
        cdi = (cdi + 1) % 2
    else:  # ch == "F"
        if cdi == X:
            if cx <= x:
                cx += 1
            else:  # cx > x:
                cx -= 1
        else:  # cdi == Y
            if cy <= y:
                cy += 1
            else:  # cy > y
                cy -= 1

if cx == x and cy == y:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve(arr, f_lst):
    for f in f_lst:
        if f>0:
            tmp=np.zeros(2*8000+1).astype(int)
            tmp[f:]+=arr[:-f]
            tmp[:-f]+=arr[f:]
            arr=tmp
    return arr

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

xf_lst=[]
yf_lst=[]
for i, e in enumerate(s.split("T")):
    if i%2==0:
        xf_lst.append(len(e))
    else:
        yf_lst.append(len(e))
        
origin=8000
x_arr=np.zeros(2*origin+1).astype(int)
x_arr[origin+xf_lst[0]]=1 # initialize
x_arr=solve(x_arr, xf_lst[1:])

y_arr=np.zeros(2*origin+1).astype(int)
y_arr[origin]=1 # initialize
y_arr=solve(y_arr, yf_lst)

if x_arr[origin+x]>0 and y_arr[origin+y]>0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

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

s = s + "T"

a = []
b = []

cum_len = 0
turn = 0
for command in s:
    if command == "F":
        cum_len += 1
    elif command == "T":
        (a if turn == 0 else b).append(cum_len)
        turn ^= 1
        cum_len = 0

a0 = a.pop(0)

alpha = abs(x-a0)
beta = abs(y)

targetX = sum(a) - alpha
targetY = sum(b) - beta

def search(a, target):
    forwardTable = np.zeros((len(a), target))
    for i_i in xrange(len(a)):
        for i_j in xrange(target):
            local_target = i_j + 1
            new_item = a[i_i]
            if (i_i>0) and (forwardTable[i_i-1, local_target-1]==1):
                status = 1
            else:
                prev_target = local_target - new_item
                if prev_target == 0:
                    status = 1
                elif prev_target < 0:
                    status = 0
                elif i_i == 0:
                    status = 0
                else:
                    status = forwardTable[i_i-1, prev_target-1]
            forwardTable[i_i, local_target-1] = status

    return forwardTable[-1,-1]

if (targetX < 0) or (targetY < 0):
    print "No"
    sys.exit()
else:
    if (targetX > 0):
        status = search(a, targetX)
        if status == 0:
            print "No"
            sys.exit()
    if (targetY > 0):
        status = search(b, targetY)
        if status == 0:
            print "No"
            sys.exit()
    print "Yes"

Submission status: Wrong Answer

Solution code:
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	ss = input().split('T')
	x, y = map(int, input().split())
	 
	dpx = dict()
	dpy = dict()
	 
	dpx[0+len(ss[0])] = True
	dpy[0] = True
	 
	direct = 1 #0:x, 1:y
	 
	 
	for s in ss[1:]:
		tmp = dict()
		n = len(s)
		if direct%2 == 0: 
			for k, v in dpx.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpx = tmp
		else:
			for k, v in dpy.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpy = tmp

		print(dpx, dpy)
		direct += 1
	 	

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


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

ss = input().split('T')
x, y = map(int, input().split())

dpx = dict()
dpy = dict()

dpx[0] = True
dpy[0] = True

direct = 0 #0:x, 1:y

for s in ss:
    if direct%2 == 0:
        tmp = dict()
        n = len(s)
        for k, v in dpx.items():
            tmp[k+n] = True
            tmp[k-n] = True
        direct += 1
        dpx = tmp
    else:
        tmp = dict()
        n = len(s)
        for k, v in dpy.items():
            tmp[k+n] = True
            tmp[k-n] = True
        direct += 1
        dpy = tmp

# print(x, y)
# print(dpx, dpy)
# print(x in dpx)
# print(y in dpy)
if x in dpx and y in dpy:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b

YES = "Yes"
NO = "No"


def check(x, nums):
    ans = set()
    ans.add(0)

    for n in nums:
        tmp = set()
        for v in range(len(ans)):
            tmp.add(v + n)
            tmp.add(v - n)
        ans = tmp
    return x in ans


def solve(s, x, y):
    type_num = [(k, len(list(g))) for k, g in groupby(s)]
    if s[0] == "F":
        x -= type_num[0][1]
        type_num.pop(0)

    h, v = [], []
    now = 0
    for t, n in type_num:
        if t == "F":
            if now == 0:
                h.append(n)
            else:
                v.append(n)
        else:
            if n % 2 != 0:
                now = (now + 1) % 2
    return YES if check(x, h) and check(y, v) else NO


def main():
    s = input()
    x, y = map(int, input().split())

    print(solve(s, x, y))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b
YES = "Yes"
NO = "No"


memo2 = {}
def ok(i, l, now, target):
    if i >= len(l):
        return now == target
    key = (i, now)
    if key in memo2:
        return memo2[key]

    memo2[key] = ok(i + 1, l, now + l[i], target) or ok(i + 1, l, now - l[i], target)
    return memo2[key]

def main():
    s = input()
    x, y = map(int, input().split())
    ss = [(k, len(list(g))) for k, g in groupby(s)]
    x -= ss[0][1]
    ss.pop(0)

    h, v = [], []
    now = 0
    for t, n in ss:
        if t == "F":
            if now == 0:
                h.append(n)
            else:
                v.append(n)
        else:
            if n % 2 != 0:
                now = (now + 1) % 2

    print(YES if ok(0, h, 0, x) and ok(0, v, 0, y) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
string = raw_input()
x_,y_ = map(int, raw_input().split())
x,y = 0,0
face = 1
flag = True
x_from = 0
for c in string:
	if c == "F":
		if flag:
			x_from += 1
			continue
		if face == 1:
			x += 1
		elif face == -1:
			y += 1
	elif c == "T":
		flag = False
		face = -face
#print x, y
if x+x_from >= x_ and x_from - x <= x_ and (x-x_)%2==0 and y >= abs(y_) and (y-y_)%2==0 :
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

Solution code:
string = raw_input()
x_,y_ = map(int, raw_input().split())
x,y = 0,0
face = 1

for c in string:
	if c == "F":
		if face == 1:
			x += 1
		elif face == -1:
			y += 1
	elif c == "T":
		face = -face
#print x, y
if x >= abs(x_) and (x-x_)%2==0 and y >= abs(y_) and (y-y_)%2==0 :
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

Solution code:
string = raw_input()
x_,y_ = map(int, raw_input().split())
x,y = 0,0
face = 1

for c in string:
	if c == "F":
		if face == 1:
			x += 1
		elif face == -1:
			y += 1
	elif c == "T":
		face = -face
print x, y
if x > x_ and (x-x_)%2==0 and y > y_ and (y-y_)%2==0 :
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

Solution code:
string = raw_input()
x_,y_ = map(int, raw_input().split())
x,y = 0,0
face = 0

for c in string:
	if c == "F":
		if face == 0:
			x += 1
		elif face == 1:
			y += 1
		elif face == 2:
			x -= 1
		elif face == 3:
			y -= 1
	elif c == "T":
		face = (face + 1)%4

if x == x_ and y == y_:
	print "YES"
else:
	print "NO"

Submission status: Wrong Answer

Solution code:
def f(m, s, g):
    for i in m:
        if s > g:
            s -= i
        else:
            s += i
    return s == g
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
print(m)
if (f(sorted(m[::2][1::])[::-1], m[0], x)
        and f(sorted(m[1::2])[::-1], 0, y)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def f(m, s, g):
    for i in m:
        if s + i > g:
            s -= i
        else:
            s += i
    return s == g
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
if (f(sorted(m[::2][1::])[::-1], m[0], x)
        and f(sorted(m[1::2])[::-1], 0, y)):
    print('Yes')
else:
    print('No')