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:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0
for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
cx=0
cy=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=cx:
        cx+=i
    else:
        cx-=i

for i in sorted(dy,reverse=True):
    if y>=cy:
        cy+=i
    else:
        cy-=i
#print(sorted(dx,reverse=True),sorted(dy,reverse=True))
if(cx==x and cy==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def can_make(steps, t, init):
    cur = {init}
    for s in steps:
        nex = set()
        for c in cur:
            nex.add(c + s)
            nex.add(c - s)
        cur = nex
    if t in cur:
        return True
    return False


def solve(s: str, x: int, y: int):
    steps = [[], []]
    flg = 0
    tmp = 0
    for c in s:
        if c == 'T':
            if tmp > 0:
                steps[flg].append(tmp)
            flg = (flg + 1) % 2
            tmp = 0
        else:
            tmp += 1
    steps[flg].append(tmp)
    #print(steps)
    init_x = steps[0][0] if len(steps[0]) > 0 else 0
    if can_make(steps[0][1:], x, init_x) and can_make(steps[1], y, 0):
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def can_make(steps, t):
    cur = {0}
    for s in steps:
        nex = set()
        for c in cur:
            nex.add(c + s)
            nex.add(c - s)
        cur = nex
    if t in cur:
        return True
    return False


def solve(s: str, x: int, y: int):
    steps = [[], []]
    flg = 0
    tmp = 0
    for c in s:
        if c == 'T':
            if tmp > 0:
                steps[flg].append(tmp)
            flg = (flg + 1) % 2
            tmp = 0
        else:
            tmp += 1
    steps[flg].append(tmp)
    #print(steps)
    if can_make(steps[0], x) and can_make(steps[1], y):
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from queue import Queue

YES = "Yes"  # type: str
NO = "No"  # type: str

def can_make(steps, t):
    q = Queue()
    cur = [0]
    for s in steps:
        nex = []
        for c in cur:
            nex.append(c + s)
            nex.append(c - s)
        cur = nex
    if t in cur:
        return True
    return False


def solve(s: str, x: int, y: int):
    steps = [[], []]
    flg = 0
    tmp = 0
    for c in s:
        if c == 'T':
            steps[flg].append(tmp)
            flg = (flg + 1) % 2
            tmp = 0
        else:
            tmp += 1
    steps[flg].append(tmp)
    #print(steps)
    if can_make(steps[0], x) and can_make(steps[1], y):
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
cx=0
cy=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>cx:
        cx+=i
    else:
        cx-=i

for i in sorted(dy,reverse=True):
    if y>cy:
        cy+=i
    else:
        cy-=i
#print(sorted(dx,reverse=True),sorted(dy,reverse=True))
if(cx==x and cy==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
cx=0
cy=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=cx:
        cx+=i
    else:
        cx-=i

for i in sorted(dy,reverse=True):
    if y>=cy:
        cy+=i
    else:
        cy-=i
#print(sorted(dx,reverse=True),sorted(dy,reverse=True))
if(cx==x and cy==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
cx=0
cy=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=cx:
        cx+=i
    else:
        cx-=i

for i in sorted(dy,reverse=True):
    if y>=cy:
        cy+=i
    else:
        cy-=i
print(sorted(dx,reverse=True),sorted(dy,reverse=True))
if(cx==x and cy==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dy.append(move)
            else:
                dx.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dy.append(move)
else:
    dx.append(move)
tmp=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=tmp:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if y>=tmp:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(adx==x and ady==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0
print(s.split("T"))

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dy.append(move)
            else:
                dx.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dy.append(move)
else:
    dx.append(move)
tmp=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=tmp:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if y>=tmp:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(adx==x and ady==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0
print(s.split("T"))

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dy.append(move)
            else:
                dx.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
tmp=0
x-=xf
for i in sorted(dx,reverse=True):
    if x>=tmp:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if y>=tmp:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(adx==x and ady==y):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
tmp=0
x-=xf
for i in sorted(dx,reverse=True):
    if tmp<=x:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if tmp<=y:
        tmp+=i
    else:
        tmp-=i
ady=tmp
if(ady==y and adx==x):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)

tmp=xf
for i in sorted(dx,reverse=True):
    if tmp<=x:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if tmp<=y:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(ady==y and adx==x):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)

tmp=xf
for i in sorted(dx,reverse=True):
    if tmp<x:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in sorted(dy,reverse=True):
    if tmp<y:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(ady==y and adx==x):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0

for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
if(dir%2==0):
    dx.append(move)
else:
    dy.append(move)
'''
for i in s:
    if(i=="F"):
        move+=1
    else:
        if(dir%2==0):
            dx.append(move)
        else:
            dy.append(move)
    dir+=1
    move=0
'''
tmp=xf
for i in dx:
    if tmp<x:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in dy:
    if tmp<y:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(ady==y and adx==x):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=list(map(int,input().split()))
dx=[]
dy=[]
first=True
move=0
xf=0
dir=0
'''
for i in s:
    if(i=="F"):
        move+=1
    else:
        if(first):
            xf = move
            first=False
        else:
            if(dir%2==0):
                dx.append(move)
            else:
                dy.append(move)
        dir+=1
        move=0
'''
for i in s:
    if(i=="F"):
        move+=1
    else:
        if(dir%2==0):
            dx.append(move)
        else:
            dy.append(move)
    dir+=1
    move=0
tmp=xf
for i in dx:
    if tmp<x:
        tmp+=i
    else:
        tmp-=i
adx=tmp
tmp=0
for i in dy:
    if tmp<y:
        tmp+=i
    else:
        tmp-=i
ady=tmp

if(ady==y and adx==x):
    print("Yes")
else:
    print('No')

Submission status: Wrong Answer

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

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def isBitOn(value, n):
	return (value & (2 ** n)) > 0
	
def isMake(l,v):
	if len(l)==0 and v ==0:
		return True
		
	for i in range(2 ** len(l)):
		r=sum([v * (1-2*isBitOn(i,j)) for j,v in enumerate(l)])
		if r == v:
			return True
	return False
	
def move_next(v,i):
	rv = (v | 2 ** (i))
	ri = i+1
	return rv, ri
	
def buck(v,i):
	#111,3->101,3
	#101,3->010,2
	for j in range(i-1):
		n=i-1-j
		d=(v & 2** (n - 1))
		if d > 0:
			nv=(v & (2**(n-1) - 1))
			nnv,ni = move_next(nv, n)
			return True,nnv,ni
	return False, -1, -1
	
def isMake3(l,a_target):
	tree=0
	ii=0
	l.sort(reverse = True)
	est=lambda al,av:sum([v * isBitOn(av,j) for j,v in enumerate(l)])
	cc=True
	
	while cc:
		ccv=est(l, tree)
		#print(bin(tree),ii, est(l,tree),a_target)
		while ccv < a_target:
			tree, ii = move_next(tree,ii)
			#print(bin(tree),ii, est(l,tree),a_target)
			if ii > len(l):
				return False, -1
			ccv += l[ii-1]
			
		if ccv == a_target:
			return True, tree
		else:
			cc,tree,ii=buck(tree, ii)
			
	return False, -1
	
def isMake2(l, a_target):
	off=sum(l)
	if abs(a_target) > off:
		return False
	elif abs(a_target) == off:
		return True
	
	ll=[2*i for i in l]
	ret, _ = isMake3(ll, off + a_target)
	return ret
	
#def isMakeDp(l, a_target, ttl):

def next(a_xy):
	return (a_xy+1)%2
	
def main(io):
	ft=io()
	goal = list(map(int, io().split()))
	
	isFirstMove=True
	init_pos=[0,0]
	xy=0
	mm=0
	ml=[[],[]]
	for c in ft:
		if isFirstMove and c=='F':
			init_pos[0]+=1
		elif isFirstMove and c=='T':
			isFirstMove=False
			xy = next(xy)
			mm=0
		elif c == 'F':
			mm+=1
		elif c== 'T':
			if mm > 0:
				ml[xy].append(mm)
			xy=next(xy)
			mm=0
	if mm>0:
		ml[xy].append(mm)

	is_debug=False
	if is_debug:
		print(ml)
		print(init_pos)
		print(goal)
	for i in range(2):
		if not isMake2(ml[i], goal[i] - init_pos[i]):
			return 'No'
	return 'Yes'

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Wrong Answer

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

def io_generator():
	return input()

#+++++++++++++++++++


def isBitOn(value, n):
	return (value & (2 ** n)) > 0
	
def isMake(l,v):
	if len(l)==0 and v ==0:
		return True
		
	for i in range(2 ** len(l)):
		r=sum([v * (1-2*isBitOn(i,j)) for j,v in enumerate(l)])
		if r == v:
			return True
	return False
	
def next(a_xy):
	return (a_xy+1)%2
	
def main(io):
	ft=io()
	goal = list(map(int, io().split()))
	
	isFirstMove=True
	init_pos=[0,0]
	xy=0
	mm=0
	ml=[[],[]]
	for c in ft:
		if isFirstMove and c=='F':
			init_pos[0]+=1
		elif isFirstMove and c=='T':
			isFirstMove=False
			xy = next(xy)
			mm=0
		elif c == 'F':
			mm+=1
		elif c== 'T':
			if mm > 0:
				ml[xy].append(mm)
			xy=next(xy)
			mm=0
	if mm>0:
		ml[xy].append(mm)

	is_debug=False
	if is_debug:
		print(ml)
		print(init_pos)
		print(goal)
	for i in range(2):
		if not isMake(ml[i], goal[i] - init_pos[i]):
			print(i)
			return 'No'
	return 'Yes'

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Wrong Answer

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

def io_generator():
	return input()

#+++++++++++++++++++


def isBitOn(value, n):
	return (value & (2 ** n)) > 0
	
def isMake(l,v):
	if len(l)==0 and v ==0:
		return True
		
	for i in range(2 ** len(l)):
		r=sum([v * (1-2*isBitOn(i,j)) for j,v in enumerate(l)])
		if r == v:
			return True
	return False
	
def next(a_xy):
	return (a_xy+1)%2
	
def main(io):
	ft=io()
	goal_x, goal_y = map(int, io().split())
	
	isFirstMove=True
	init_pos=[0,0]
	xy=0
	mm=0
	ml=[[],[]]
	for c in ft:
		if isFirstMove and c=='F':
			init_pos[0]+=1
		elif isFirstMove and c=='T':
			isFirstMove=False
			xy = next(xy)
			mm=0
		elif c == 'F':
			mm+=1
		elif c== 'T':
			if mm > 0:
				ml[xy].append(mm)
			xy=next(xy)
			mm=0
	if mm>0:
		ml[xy].append(mm)

	is_debug=False
	if is_debug:
		print(ml)
		print(init_pos)
		print(goal_x,goal_y)
	for i in range(2):
		if not isMake(ml[i], goal_x - init_pos[i]):
			return 'No'
	return 'Yes'

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Wrong Answer

Solution code:
s = input()

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

l = []

for c in s:
    if l==[]:
        l.append([c,1])
    else:
        if c==l[-1][0]:
            l[-1][1]+=1
        else:
            l.append([c,1])

hori = True

h = []
v = []
if l[0][0]=='F':
    x-=l[0][1]
    l = l[1:]

for p in l:
    d = p[0]
    r = p[1]
    if d == 'T':
        hori ^= r%2
    
    elif d == 'F':
        if hori:
            h.append(r)
        else:
            v.append(r)

h.sort(reverse=True)
v.sort(reverse=True)
h.append(abs(x))
v.append(abs(y))
sh,sv = 0,0

for a in h:
    if sh > 0:
        sh -= a
    else:
        sh += a

if sh!=0:
    print("No")
    exit(0)

for b in v:
    if sv > 0:
        sv -= b
    else:
        sv += b

if sv!=0:
    print("No")
    exit(0)

print("Yes")

Submission status: Wrong Answer

Solution code:
s = input()

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

l = []

for c in s:
    if l==[]:
        l.append([c,1])
    else:
        if c==l[-1][0]:
            l[-1][1]+=1
        else:
            l.append([c,1])

hori = True

h = []
v = []
if l[0][0]=='F':
    x-=l[0][1]
    l = l[1:]

for p in l:
    d = p[0]
    r = p[1]
    if d == 'T':
        hori ^= r%2
    
    elif d == 'F':
        if hori:
            h.append(r)
        else:
            v.append(r)

h.sort(reverse=True)
v.sort(reverse=True)

sh,sv = 0,0

for a in h:
    if sh > 0:
        sh -= a
    else:
        sh += a

if abs(sh)!=abs(x):
    print("No")
    exit(0)

for b in v:
    if sv > 0:
        sv -= b
    else:
        sv += b

if abs(sv)!=abs(y):
    print("No")
    exit(0)

print("Yes")

Submission status: Wrong Answer

Solution code:
s = input()

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

l = []

for c in s:
    if l==[]:
        l.append([c,1])
    else:
        if c==l[-1][0]:
            l[-1][1]+=1
        else:
            l.append([c,1])

hori = True

h = []
v = []
dp = [False]*(8000*2+1)
if l[0][0]=='F':
    dp[l[0][1]]=True
l = l[1:]
for p in l:
    d = p[0]
    r = p[1]
    if d == 'T':
        hori ^= r%2
    
    elif d == 'F':
        if hori:
            h.append(r)
        else:
            v.append(r)

for step in h:
    new_dp = [False]*16001
    for i in range(-8000,8001):
        if i+step<=8000:
            new_dp[i] = new_dp[i] or dp[i+step]
        if i-step>=-8000:
            new_dp[i] = new_dp[i] or dp[i-step]
    dp = new_dp
if not dp[x]:
    print("No")
    exit(0)
dp = [False]*16001
dp[0] = 1
for step in v:
    new_dp = [False]*16001
    for i in range(-8000,8001):
        if i + step<=8000:
            new_dp[i] = new_dp[i] or dp[i+step]
        if i - step>=-8000:
            new_dp[i] = new_dp[i] or dp[i-step]
    dp = new_dp

if not dp[y]:
    print("No")
    exit(0)
print("Yes")

Submission status: Wrong Answer

Solution code:
def solve(string):
    s, x, y = string.split()
    x, y = int(x), int(y)
    move_all = [len(_s) for _s in s]
    pos_x = set([move_all[0]])
    pos_y = set([0])
    move_x = move_all[2::2] or None
    move_y = move_all[1::2] or None
    if move_x:
        for move in move_x:
            pos_x = {_x + move for _x in pos_x} | {_x - move for _x in pos_x}
    if move_y:
        for move in move_y:
            pos_y = {_y + move for _y in pos_y} | {_y - move for _y in pos_y}
    return "Yes" if x in pos_x and y in pos_y else "No"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Wrong Answer

Solution code:
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
f=0
d=0
xx=[]
yy=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else: #=='T'
        if f==0:
            0
        else:
            if d==0:
                xx.append(f)
                f=0
            else:
                yy.append(f)
                f=0
        d=1-d


#print(xx,yy)
def judg(a,b):
    if len(a)==0 and b==0:
        return True
    else:
        dp=set()
        pdp=set()
        for i in a:
            pdp=dp
            if len(pdp)==0:
                pdp.add(i)
                pdp.add(-i)
            else:
                dp=set()
                for j in pdp:
                    dp.add(j-i)
                    dp.add(j+i)
                    #print(dp)
        if b in dp:
            return True
        else:
            return False

    
if len(xx)>0:
    t=xx[0]
    xx.remove(xx[0])
else:
    t=0



if judg(xx,x-t) and judg(yy,y):
    ans='Yes'
else:
    ans='No'
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
f=0
d=0
xx=[]
yy=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else: #=='T'
        if f==0:
            0
        else:
            if d==0:
                xx.append(f)
                f=0
            else:
                yy.append(f)
                f=0
        d=1-d

if len(xx)>0:
    t=xx[0]
    xx.remove(xx[0])
    xx.append(abs(x-t))
else:
    xx.append(abs(x))
yy.append(abs(y))

#rint(xx,yy)
def judg(a):
    tot=sum(a)
    if tot%2==1:
        return False
    else:
        dp=[0]*(tot+1)
        for i in a:
            dp[i]=1
            for j in range(tot+1):
                if dp[j]==1 and j+i<=tot:
                    dp[j+i]=1
        if dp[int(tot/2)]==1:
            return True
        else:
            return False
if judg(xx) and judg(yy):
    ans='Yes'
else:
    ans='No'
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
f=0
d=0
xx=[]
yy=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else: #=='T'
        if f==0:
            0
        else:
            if d==0:
                xx.append(f)
                f=0
            else:
                yy.append(f)
                f=0
        d=1-d

xx.append(abs(x))
yy.append(abs(y))

#rint(xx,yy)
def judg(a):
    tot=sum(a)
    if tot%2==1:
        return False
    else:
        dp=[0]*(tot+1)
        for i in a:
            dp[i]=1
            for j in range(tot+1):
                if dp[j]==1 and j+i<=tot:
                    dp[j+i]=1
        if dp[int(tot/2)]==1:
            return True
        else:
            return False
if judg(xx) and judg(yy):
    ans='Yes'
else:
    ans='No'
print(ans)

Submission status: Wrong Answer

Solution code:
def ft_robot(s: str, x: int, y: int) -> int:
    # 各方向への一回に移動可能な距離のリストをもつ。
    # ds[0] が x 軸方向用。ds[1] が y軸方向用。
    ds = [[], []]
    axis = 0
    cur_dis = 0
    for c in s:
        if c == 'T':
            if cur_dis > 0:
                ds[axis].append(cur_dis)
            axis = 1 - axis
            cur_dis = 0
        else:
            cur_dis += 1

    if cur_dis > 0:
        ds[axis].append(cur_dis)

    if len(ds[0]) > 0 and ds[0][0] != x:
        # 最初だけは方向が決まっているのでスタート位置に補正を入れることで対応する。
        ds[0][0] = abs(ds[0][0] - x)
    elif x != 0:
        ds[0].append(abs(x))

    ds[1].append(abs(y))

    # 移動方向は軸は決まっているが正負は決まっていないので自由に決める。
    # また、足し算なので順番は関係ない。
    sx, sy = 0, 0
    for dx in sorted(ds[0], key=lambda i: -i):
        if 0 < sx:
            sx -= dx
        else:
            sx += dx

    if sx != 0:
        return False

    for dy in sorted(ds[1], key=lambda i: - i):
        if 0 < sy:
            sy -= dy
        else:
            sy += dy

    return sy == 0


if __name__ == "__main__":
    s = input()
    x, y = map(int, input().split())
    yes = ft_robot(s, x, y)
    print('Yes' if yes else 'No')

Submission status: Wrong Answer

Solution code:
def ft_robot(s: str, x: int, y: int) -> int:
    # 各方向への一回に移動可能な距離のリストをもつ。
    # ds[0] が x 軸方向用。ds[1] が y軸方向用。
    ds = [[], []]
    axis = 0
    cur_dis = 0
    for c in s:
        if c == 'T':
            if cur_dis > 0:
                ds[axis].append(cur_dis)
            axis = 1 - axis
            cur_dis = 0
        else:
            cur_dis += 1

    if cur_dis > 0:
        ds[axis].append(cur_dis)

    if len(ds[0]) > 0:
        # 最初だけは方向が決まっているのでスタート位置に補正を入れることで対応する。
        sx, sy = ds[0][0], 0
    else:
        sx, sy = 0, 0

    # 移動方向は軸は決まっているが正負は決まっていないので自由に決める。
    # また、足し算なので順番は関係ない。
    for dx in sorted(ds[0][1:], key=lambda i: -i):
        if sx < x:
            sx += dx
        else:
            sx -= dx

    if sx != x:
        return False

    for dy in sorted(ds[1], key=lambda i: - i):
        if sy < y:
            sy += dy
        else:
            sy -= dy

    return sy == y


if __name__ == "__main__":
    s = input()
    x, y = map(int, input().split())
    yes = ft_robot(s, x, y)
    print('Yes' if yes else 'No')

Submission status: Wrong Answer

Solution code:
s = input()
gx, gy = [int(s) for s in input().split(' ')]

q = set([((0, 0), 0, 0)])

def conv_d(d):
    if d == 0:
        return (1, 0)
    elif d == 1:
        return (0, 1)
    elif d == 2:
        return (-1, 0)
    else:
        return (0, -1)

while len(q) > 0:
    (x, y), d, c = q.pop()
    dx, dy = conv_d(d)
    if c >= len(s):
        continue
    elif s[c] == 'F':
        if c == len(s) - 1 and x+dx == gx and y+dy == gy:
            print('Yes')
            exit()
        q.add(((x + dx, y + dy), d, c + 1))
    else:
        q.add(((x, y), (d + 1) % 4, c + 1))
        q.add(((x, y), (d - 1) % 4, c + 1))

Submission status: Wrong Answer

Solution code:
s = input()
gx, gy = [int(s) for s in input().split(' ')]

q = [((0, 0), 0, 0)]

def conv_d(d):
    if d == 0:
        return (1, 0)
    elif d == 1:
        return (0, 1)
    elif d == 2:
        return (-1, 0)
    else:
        return (0, -1)

while len(q) > 0:
    (x, y), d, c = q.pop()
    dx, dy = conv_d(d)
    if c >= len(s):
        print('No')
        exit()
    elif s[c] == 'F':
        if x+dx == gx and y+dy == gy:
            print('Yes')
            exit()
        q.insert(0, ((x + dx, y + dy), d, c + 1))
    else:
        q.insert(0, ((x, y), (d + 1) % 4, c + 1))
        q.insert(0, ((x, y), (d - 1) % 4, c + 1))

Submission status: Wrong Answer

Solution code:
s = input()
gx, gy = [int(s) for s in input().split(' ')]

q = [((0, 0), 0, 0)]

def conv_d(d):
    if d == 0:
        return (1, 0)
    elif d == 1:
        return (0, 1)
    elif d == 2:
        return (-1, 0)
    else:
        return (0, -1)

while len(q) > 0:
    (x, y), d, c = q.pop()
    dx, dy = conv_d(d)
    if x+dx == gx and y+dy == gy:
        print('Yes')
        exit()
    elif c >= len(s):
        print('No')
        exit()
    elif s[c] == 'F':
        q.insert(0, ((x + dx, y + dy), d, c + 1))
    else:
        q.insert(0, ((x, y), (d + 1) % 4, c + 1))
        q.insert(0, ((x, y), (d - 1) % 4, c + 1))

Submission status: Wrong Answer

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
for x in sorted(X, reverse = True):
    if gx > 0:
        gx -= x
    else:
        gx += x
for y in sorted(Y, reverse = True):
    if gy > 0:
        gy -= y
    else:
        gy += y
if gx == gy == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
gx, gy = map(int, input().split())
n = len(s)
X, Y = [], []
x, y, flag = 0, 0, 0
for i in range(n):
    if s[i] == 'F' and flag == 0:
        x += 1
    elif s[i] == 'F' and flag == 1:
        y += 1
    else:
        if flag and y > 0:
            Y.append(y)
            y = 0
        elif not flag and x > 0:
            X.append(x)
            x = 0
        flag = (flag + 1) % 2
if flag and y > 0:
    Y.append(y)
elif not flag and x > 0:
    X.append(x)
MAX_X, MAX_Y, l_X, l_Y = sum(X), sum(Y), len(X), len(Y)
if MAX_X < abs(gx) or MAX_Y < abs(gy):
    print("No")
else:
    dp_x = [[False for _ in range(MAX_X * 2 + 1)] for _ in range(l_X + 1)]
    dp_y = [[False for _ in range(MAX_Y * 2 + 1)] for _ in range(l_Y + 1)]
    dp_x[0][MAX_X], dp_y[0][MAX_Y] = True, True
    for i in range(l_X):
        for x in range(MAX_X * 2 + 1):
            if x + X[i] < MAX_X * 2 + 1:
                dp_x[i + 1][x] |= dp_x[i][x + X[i]]
            if x - X[i] >= 0:
                dp_x[i + 1][x] |= dp_x[i][x - X[i]]
    for i in range(l_Y):
        for y in range(MAX_Y * 2 + 1):
            if y + Y[i] < MAX_Y * 2 + 1:
                dp_y[i + 1][y] |= dp_y[i][y + Y[i]]
            if y - Y[i] >= 0:
                dp_y[i + 1][y] |= dp_y[i][y - Y[i]]
    #print(X, l_X, MAX_X, dp_x, Y, l_Y, MAX_Y, dp_y)
    if dp_x[l_X][gx + MAX_X] and dp_y[l_Y][gy + MAX_Y]:
        print("Yes")
    else:
        print("No")