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 = list(input())
x, y = map(int, input().split())

z = [0]
for i in s:
    if i=='F':
        z[-1] += 1
    else:
        z.append(0)
_y = len(z)//2
_x = len(z) - _y
len_s = len(s)
dp_x = [[0]*(2*len_s+2) for _i in range(_x)]
dp_y = [[0]*(2*len_s+2) for _i in range(max(1, _y))]
dp_x[0][z[0]] = 1
dp_y[0][0] = 1

for i in range(1, len(z)):
    if i%2==0:
        for j in range(-len_s, len_s+1):
            dp_x[i//2][j] = max(
                dp_x[i//2 - 1][j-z[i]],
                dp_x[i//2 - 1][j+z[i]]
            )
    else:
        for j in range(-len_s, len_s+1):
            dp_y[i//2][j] = max(
                dp_y[i//2 -1][j-z[i]],
                dp_y[i//2 -1][j+z[i]]
            )

if dp_x[_x-1][x] == dp_y[_y-1][y] == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

z = [0]
for i in s:
    if i=='F':
        z[-1] += 1
    else:
        z.append(0)
_y = len(z)//2
_x = len(z) - _y
len_s = len(s)
dp_x = [[0]*(2*len_s+2) for _i in range(_x+1)]
dp_y = [[0]*(2*len_s+2) for _i in range(_y+1)]
dp_x[-1][0] = 1
dp_y[-1][0] = 1

for i in range(len(z)):
    if i%2==0:
        for j in range(-len_s, len_s+1):
            dp_x[i//2][j] = max(
                dp_x[i//2 - 1][j-z[i]],
                dp_x[i//2 - 1][j+z[i]]
            )
    else:
        for j in range(-len_s, len_s+1):
            dp_y[i//2][j] = max(
                dp_y[i//2 -1][j-z[i]],
                dp_y[i//2 -1][j+z[i]]
            )

if dp_x[_x-1][x] == dp_y[_y-1][y] == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

dpx=[False]*16001
dpy=[False]*16001

dpx[8000],dpy[8000]=True,True

xxx=True
judge=True
s+='T'
cnt=0
for i in s:
  if i=='F':
      cnt+=1

  else:
    xxx=False
    if judge:
        judge=False
    
    else:
        judge=True

    if cnt==0:
        continue

    sin=[False]*16001
    if not judge:
        for j in range(16001):
            if dpx[j]==True:
                if not xxx:
                  sin[j-cnt]=True
                sin[j+cnt]=True
        dpx=sin
    
    else:
        for j in range(16001):
            if dpy[j]==True:
                sin[j-cnt]=True
                sin[j+cnt]=True
        dpy=sin

    cnt=0

    


if dpx[x+8000] and dpy[y+8000]:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

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

dpx=[False]*16001
dpy=[False]*16001

dpx[8000],dpy[8000]=True,True

xxx=True
judge=True
s+='T'
cnt=0
for i in s:
  if i=='F':
      cnt+=1

  else:
    if judge:
        judge=False
    
    else:
        judge=True

    if cnt==0:
        continue

    sin=[False]*16001
    if not judge:
        for j in range(16001):
            if dpx[j]==True:
                if not xxx:
                  sin[j-cnt]=True
                sin[j+cnt]=True
        dpx=sin
    
    else:
        for j in range(16001):
            if dpy[j]==True:
                sin[j-cnt]=True
                sin[j+cnt]=True
        dpy=sin

    cnt=0
    xxx=False
    


if dpx[x+8000] and dpy[y+8000]:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

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

dpx=[False]*16001
dpy=[False]*16001

dpx[8000],dpy[8000]=True,True

judge=True
s+='T'
cnt=0
for i in s:
  if i=='F':
      cnt+=1

  else:
    if judge:
        judge=False
    
    else:
        judge=True

    if cnt==0:
        continue

    sin=[False]*16001
    if not judge:
        for j in range(16001):
            if dpx[j]==True:
                sin[j-cnt]=True
                sin[j+cnt]=True
        dpx=sin
    
    else:
        for j in range(16001):
            if dpy[j]==True:
                sin[j-cnt]=True
                sin[j+cnt]=True
        dpy=sin

    cnt=0

    


if dpx[x+8000] and dpy[y+8000]:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
FT = []
s = input()
x,y = ma()
if s[0]=="T":
    FT.append(0)
prev = s[0]
cnt=0
for i in range(len(s)):
    if s[i]==prev:
        cnt+=1
    else:
        FT.append(cnt)
        cnt=1
    prev=s[i]
FT.append(cnt)
Fxy = [[],[]]
idx=0#0->x 1->y
for i in range(len(FT)):
    if i%2==0:
        Fxy[idx].append(FT[i])
    else:
        if FT[i]%2==0:
            pass
        else:
            idx=(idx+1)%2
def reach(xls,x):
    l = len(xls)
    s = sum(xls)
    if abs(x) >s:
        return False
    dp = [[False]*(2*s+1) for _ in range(l+1)] #dp[i][j] i 個使ったときにjにいられるか
    dp[0][0] =True
    for i in range(l):
        d = xls[i]
        for j in range(-s,s+1):
            dp[i+1][j] = dp[i][j-d] or dp[i][j+d]
    #print(dp)
    return dp[-1][x]
fx = reach(Fxy[0],x)
fy = reach(Fxy[1],y)
yn(fx and fy)
#print(FT)
#print(dpx)
#print(dpy)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
FT = []
s = input()
x,y = ma()
if s[0]=="T":
    FT.append(0)
prev = s[0]
cnt=1
for i in range(1,len(s)):
    if s[i]==prev:
        cnt+=1
    else:
        FT.append(cnt)
        cnt=1
    prev=s[i]
FT.append(cnt)
Fxy = [[],[]]
idx=0#0->x 1->y
for i in range(len(FT)):
    if i%2==0:
        Fxy[idx].append(FT[i])
    else:
        if FT[i]%2==0:
            idx=idx
        else:
            idx=(idx+1)%2
def reach(xls,x):
    l = len(xls)
    s = sum(xls)
    if abs(x) >s:
        return False
    dp = [[False]*(2*s+1) for _ in range(l+1)] #dp[i][j] i 個使ったときにjにいられるか
    dp[0][0] =True
    for i in range(l):
        d = xls[i]
        for j in range(-s,s+1):
            dp[i+1][j] = dp[i][j-d] or dp[i][j+d]
    return dp[-1][x]
fx = reach(Fxy[0],x)
fy = reach(Fxy[1],y)
yn(fx and fy)
#print(FT)
#print(dpx)
#print(dpy)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
FT = []
s = input()
x,y = ma()
if s[0]=="T":
    FT.append(0)
prev = s[0]
cnt=1
for i in range(1,len(s)):
    if s[i]==prev:
        cnt+=1
    else:
        FT.append(cnt)
        cnt=1
    prev=s[i]
FT.append(cnt)
Fxy = [[],[]]
idx=0#0->x 1->y
for i in range(len(FT)):
    if i%2==0:
        Fxy[idx].append(FT[i])
    else:
        if FT[i]%2==0:
            idx=idx
        else:
            idx=(idx+1)%2
def reach(xls):
    l = len(xls)
    s = 8000
    dp = [[False]*(2*s+1) for _ in range(l+1)] #dp[i][j] i 個使ったときにjにいられるか
    dp[0][0] =True
    for i in range(l):
        d = xls[i]
        for j in range(-s,s+1):
            dp[i+1][j] = dp[i][j-d] or dp[i][j+d]
    return dp
dpx = reach(Fxy[0])
dpy = reach(Fxy[1])
yn(dpx[-1][x] and dpy[-1][y])
#print(FT)
#print(dpx)
#print(dpy)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
x, y = MAP()

cnt_F = s.count("F")
cnt_T = s.count("T")

cnt_F_needed = abs(x) + abs(y)

if cnt_F < cnt_F_needed or (cnt_F - cnt_F_needed)%2 == 1:
	print("No")
	exit()

#cnt_T_flg: 0か1で偶奇 -1は両方可能
if x == 0:
	if y == 0:
		cnt_T_needed = 0
		cnt_T_flg = -1
	else:
		cnt_T_needed = 1
		cnt_T_flg = 1

elif 0 < x:
	if y == 0:
		cnt_T_needed = 0
		cnt_T_flg = 0
	else:
		cnt_T_needed = 1
		cnt_T_flg = -1

elif x < 0:
	if y == 0:
		cnt_T_needed = 2
		cnt_T_flg = 0
	else:
		cnt_T_needed = 2
		cnt_T_flg = -1

if cnt_T_flg != -1 and cnt_T%2 != cnt_T_flg:
	print("No")
elif cnt_T < cnt_T_needed:
	print("No")
elif 0 < cnt_F - cnt_F_needed and cnt_T < cnt_T_needed+2:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
x, y = MAP()

cnt_F = s.count("F")
cnt_T = s.count("T")

cnt_F_needed = abs(x) + abs(y)

if cnt_F < cnt_F_needed or (cnt_F - cnt_F_needed)%2 == 1:
	print("No")
	exit()

#cnt_T_flg: 0か1で偶奇 -1は両方可能
if x == 0:
	if y == 0:
		cnt_T_needed = 0
		cnt_T_flg = -1
	else:
		cnt_T_needed = 1
		cnt_T_flg = 1

elif 0 < x:
	if y == 0:
		cnt_T_needed = 0
		cnt_T_flg = 0
	else:
		cnt_T_needed = 1
		cnt_T_flg = -1

elif x < 0:
	if y == 0:
		cnt_T_needed = 2
		cnt_T_flg = 0
	else:
		cnt_T_needed = 2
		cnt_T_flg = -1

if cnt_T_flg != -1 and cnt_T%2 != cnt_T_flg:
	print("No")
elif cnt_T < cnt_T_needed:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
x, y = MAP()

cnt_F = s.count("F")
cnt_T = s.count("T")

cnt_F_needed = abs(x) + abs(y)

if cnt_F < cnt_F_needed or (cnt_F - cnt_F_needed)%2 == 1:
	print("No")
	exit()

#cnt_T_flg: 0か1で偶奇 -1は両方可能
if x == 0:
	if y == 0:
		cnt_T_needed = 0
		cnt_T_flg = -1
	else:
		cnt_T_needed = 1
		cnt_T_flg = 1

elif 0 < x:
	if y == 0:
		cnt_T_needed = 1
		cnt_T_flg = 0
	else:
		cnt_T_needed = 1
		cnt_T_flg = -1

elif x < 0:
	if y == 0:
		cnt_T_needed = 2
		cnt_T_flg = 0
	else:
		cnt_T_needed = 2
		cnt_T_flg = -1

if cnt_T_flg != -1 and cnt_T%2 != cnt_T_flg:
	print("No")
elif cnt_T < cnt_T_needed:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
x, y = MAP()

cnt_F = s.count("F")
cnt_T = s.count("T")

cnt_F_needed = abs(x) + abs(y)

if cnt_F < cnt_F_needed or (cnt_F - cnt_F_needed)%2 == 1:
	print("No")
	exit()

#cnt_T_needed == 1ならTが奇数個, 2なら偶数個必要(0なら両方可)
if x == 0:
	if y == 0:
		cnt_T_needed = 0
	else:
		cnt_T_needed = 1

elif 0 < x:
	if y == 0:
		cnt_T_needed = 2
	else:
		cnt_T_needed = 0

elif x < 0:
	if y == 0:
		cnt_T_needed = 1
	else:
		cnt_T_needed = 2

if 0 < cnt_T_needed and cnt_T%2 != cnt_T_needed%2:
	print("No")
else:
	print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s):
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	if "T" not in s:
		dp1[0]=0
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s):
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	if "F" not in s:
		dp1[len(s)+X]=X==len(s)
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s):
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	if len(b)==0:
		dp1[len(s)+X]=X==len(s)
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s):
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	if len(b)==0:
		dp1[len(s)+X]=X==0;dp2[len(s)+Y]=Y==0
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	s=input()
	X,Y=map(int,input().split())
	p=[]
	F=T=0
	if s[0]=="T":
		p.append(0)
	for i in range(len(s)):
		if s[i]=="F":
			if T:
				p.append(T)
			T=0
			F+=1
		else:
			if F:
				p.append(F)
			F=0
			T+=1
	p.append(max(F,T))
	a=[]
	b=[]
	now=0
	for i in range(len(p)//2):
		if now==0:
			a.append(p[i*2])
		else:
			b.append(p[i*2])
		if p[i*2+1]%2==1:
			if now==0:
				now=1
			else:
				now=0
	if len(p)%2==1:
		if now==0:
			a.append(p[-1])
		else:
			b.append(p[-1])
	dp1=[0]*(2*len(s)+1)
	dp2=[0]*(2*len(s)+1)
	dp1[len(s)]=1
	dp2[len(s)]=1
	for x in a:
		dp1_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
			if i+x<=2*len(s):
				dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
		dp1=dp1_copy.copy()
	for x in b:
		dp2_copy=[0]*(2*len(s)+1)
		for i in range(2*len(s)+1):
			if i-x>=0:
				dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
			if i+x<=2*len(s):
				dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
		dp2=dp2_copy.copy()
	print("Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
s=input()
X,Y=map(int,input().split())
p=[]
F=T=0
if s[0]=="T":
	p.append(0)
for i in range(len(s)):
	if s[i]=="F":
		if T:
			p.append(T)
		T=0
		F+=1
	else:
		if F:
			p.append(F)
		F=0
		T+=1
p.append(max(F,T))
a=[]
b=[]
now=0
for i in range(len(p)//2):
	if now==0:
		a.append(p[i*2])
	else:
		b.append(p[i*2])
	if p[i*2+1]%2==1:
		if now==0:
			now=1
		else:
			now=0
if len(p)%2==1:
	if now==0:
		a.append(p[-1])
	else:
		b.append(p[-1])
dp1=[0]*(2*len(s)+1)
dp2=[0]*(2*len(s)+1)
dp1[len(s)]=1
dp2[len(s)]=1
for x in a:
	dp1_copy=[0]*(2*len(s)+1)
	for i in range(2*len(s)+1):
		if i-x>=0:
			dp1_copy[i]=max(dp1[i-x],dp1_copy[i])
		if i+x<=2*len(s):
			dp1_copy[i]=max(dp1[i+x],dp1_copy[i])
	dp1=dp1_copy.copy()
for x in a:
	dp2_copy=[0]*(2*len(s)+1)
	for i in range(2*len(s)+1):
		if i-x>=0:
			dp2_copy[i]=max(dp2[i-x],dp2_copy[i])
		if i+x<=2*len(s):
			dp2_copy[i]=max(dp2[i+x],dp2_copy[i])
	dp2=dp2_copy.copy()
print( "Yes" if dp1[len(s)+X] and dp2[len(s)+Y] else "No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
p=8010
a,b=[],0
for c in s:
    if c=='T':
        a.append(b)
        b=0
    else:
        b+=1
a.append(b)
x-=a.pop(0)
yl,xl=a[::2],a[1::2]
mx,my=[0]*(p*2),[0]*(p*2)
mx[p],my[p]=1,1
for dx in xl:
    nx=[0]*(p*2)
    for i in range((p*2)):
        nx[i]=max(nx[i],mx[i])
        if i-dx>=0:
            nx[i-dx]=max(nx[i-dx],mx[i])
        if i+dx<2*p:
            nx[i+dx]=max(nx[i+dx],mx[i])
    mx=nx
for dy in yl:
    ny=[0]*(p*2)
    for i in range((p*2)):
        ny[i]=max(ny[i],my[i])
        if i-dy>=0:
            ny[i-dy]=max(ny[i-dy],my[i])
        if i+dy<2*p:
            ny[i+dy]=max(ny[i+dy],my[i])
    my=ny
print('Yes' if mx[x+p] and my[y+p] else 'No')

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
x,y = list(map(int,input().split()))

now = 1
YOKO = []
TATE = []
cnt=0
for i in range(N):
    if now==1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            YOKO.append(cnt)
            cnt=0
            now=-1*now
    elif now==-1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            TATE.append(cnt)
            cnt=0
            now=-1*now
if cnt>0:
    if now==1:
        YOKO.append(cnt)
    if now==-1:
        TATE.append(cnt)

NYOKO = len(YOKO)
NTATE = len(TATE)

dpYOKO = [0]*16001
dpTATE = [0]*16001
dpYOKO[0+8000]=1
dpTATE[0+8000]=1

for i in range(1,NYOKO+1):
    YOKOd = YOKO[i-1]
    newdp1 = [0]*16001
    for j in range(0,16001):
        if (0<=j-YOKOd)and(j+YOKOd<=16000):
            newdp1[j] = max(dpYOKO[j-YOKOd],dpYOKO[j+YOKOd])
        elif (0<=j-YOKOd):
            newdp1[j] = dpYOKO[j-YOKOd]
        elif (j+YOKOd<=16000):
            newdp1[j] = dpYOKO[j+YOKOd]
    dpYOKO = newdp1

for i in range(1,NTATE+1):
    TATEd = TATE[i-1]
    newdp2 = [0]*16001
    for j in range(0,16001):
        if (0<=j-TATEd)and(j+TATEd<=16000):
            newdp2[j] = max(dpTATE[j-TATEd],dpTATE[j+TATEd])
        elif (0<=j-TATEd):
            newdp2[j] = dpTATE[j-TATEd]
        elif (j+TATEd<=16000):
            newdp2[j] = dpTATE[j+TATEd]
    dpTATE = newdp2

if dpYOKO[x+8000]==1 and dpTATE[y+8000]==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
x,y = list(map(int,input().split()))

now = 1
YOKO = []
TATE = []
cnt=0
for i in range(N):
    if now==1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            if cnt!=0:
                YOKO.append(cnt)
            cnt=0
            now=-1*now
    elif now==-1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            if cnt!=0:
                TATE.append(cnt)
            cnt=0
            now=-1*now
if cnt>0:
    if now==1:
        YOKO.append(cnt)
    if now==-1:
        TATE.append(cnt)

NYOKO = len(YOKO)
NTATE = len(TATE)

dpYOKO = [0]*16001
dpTATE = [0]*16001
dpYOKO[0+8000]=1
dpTATE[0+8000]=1

for i in range(1,NYOKO+1):
    YOKOd = YOKO[i-1]
    newdp1 = [0]*16001
    for j in range(0,16001):
        if (0<=j-YOKOd)and(j+YOKOd<=16000):
            newdp1[j] = max(dpYOKO[j-YOKOd],dpYOKO[j+YOKOd])
        elif (0<=j-YOKOd):
            newdp1[j] = dpYOKO[j-YOKOd]
        elif (j+YOKOd<=16000):
            newdp1[j] = dpYOKO[j+YOKOd]
    dpYOKO = newdp1

for i in range(1,NTATE+1):
    TATEd = TATE[i-1]
    newdp2 = [0]*16001
    for j in range(0,16001):
        if (0<=j-TATEd)and(j+TATEd<=16000):
            newdp2[j] = max(dpTATE[j-TATEd],dpTATE[j+TATEd])
        elif (0<=j-TATEd):
            newdp2[j] = dpTATE[j-TATEd]
        elif (j+TATEd<=16000):
            newdp2[j] = dpTATE[j+TATEd]
    dpTATE = newdp2

if dpYOKO[x+8000]==1 and dpTATE[y+8000]==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
x,y = list(map(int,input().split()))

now = 1
YOKO = []
TATE = []
cnt=0
for i in range(N):
    if now==1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            if cnt!=0:
                YOKO.append(cnt)
            cnt=0
            now=-1*now
    elif now==-1:
        if S[i]=="F":
            cnt+=1
        elif S[i]=="T":
            if cnt!=0:
                TATE.append(cnt)
            cnt=0
            now=-1*now
if cnt>0:
    if now==1:
        YOKO.append(cnt)
    if now==-1:
        TATE.append(cnt)

NYOKO = len(YOKO)
NTATE = len(TATE)

dpYOKO = [[0]*16001 for i in range(NYOKO+1)]
dpTATE = [[0]*16001 for i in range(NTATE+1)]
dpYOKO[0][0+8000]=1
dpTATE[0][0+8000]=1

for i in range(1,NYOKO+1):
    YOKOd = YOKO[i-1]
    for j in range(0,16001):
        if (0<=j-YOKOd)and(j+YOKOd<=16000):
            dpYOKO[i][j] = max(dpYOKO[i-1][j-YOKOd],dpYOKO[i-1][j+YOKOd])
        elif (0<=j-YOKOd):
            dpYOKO[i][j] = dpYOKO[i-1][j-YOKOd]
        elif (j+YOKOd<=16000):
            dpYOKO[i][j] = dpYOKO[i-1][j+YOKOd]

for i in range(1,NTATE+1):
    TATEd = TATE[i-1]
    for j in range(0,16001):
        if (0<=j-TATEd)and(j+TATEd<=16000):
            dpTATE[i][j] = max(dpTATE[i-1][j-TATEd],dpTATE[i-1][j+TATEd])
        elif (0<=j-TATEd):
            dpTATE[i][j] = dpTATE[i-1][j-TATEd]
        elif (j+TATEd<=16000):
            dpTATE[i][j] = dpTATE[i-1][j+TATEd]

if dpTATE[-1][y+8000]==1 and dpYOKO[-1][x+8000]==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
num=[0,0]#x,y
now=0
f=len(s)
for i in range(len(s)):
	if s[i]=="F":
		num[now]+=1
	else:
		now=~now
		if f==len(s):
			f=i

r=f-(num[0]-f)
if abs(x)<=num[0] and (x-num[0])%2==0 and abs(y)<=num[1] and (y-num[1])%2==0 and r<=x:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
num=[0,0]#x,y
now=0
f=len(s)
for i in range(len(s)):
	if s[i]=="F":
		num[now]+=1
	else:
		now=~now
		if f==0:
			f=i

r=f-(num[0]-f)
if abs(x)<=num[0] and (x-num[0])%2==0 and abs(y)<=num[1] and (y-num[1])%2==0 and r<=x:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
num=[0,0]#x,y
now=0
f=0
for i in range(len(s)):
	if s[i]=="F":
		num[now]+=1
	else:
		now=~now
		f=1
if abs(x)<=num[0] and (x-num[0])%2==0 and abs(y)<=num[1] and (y-num[1])%2==0 and (f or x>0):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
num=[0,0]#x,y
now=0
for i in range(len(s)):
	if s[i]=="F":
		num[now]+=1
	else:
		now=~now
if abs(x)<=num[0] and (x-num[0])%2==0 and abs(y)<=num[1] and (y-num[1])%2==0:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
S=input()
x,y=map(int,input().split())
ans=[]
S+="T"
cnt=0
fl=0
ans.append([[0,0]])
for s in S:
    if s=="F":
        cnt+=1
    elif s=="T" :
        fl+=1
        tmp=[]
        for j in range(len(ans[fl-1])):
            nx = ans[fl - 1][j][0]
            ny = ans[fl - 1][j][1]
            if fl%2==1:
                tmp.append([nx+cnt,ny])
                tmp.append([nx-cnt,ny])
            else:
                tmp.append([nx, ny+cnt])
                tmp.append([nx, ny-cnt])
        cnt=0
        ans.append(tmp)

if [x,y] in ans[-1]:
     print("Yes")
     exit()
print("No")

Submission status: Wrong Answer

Solution code:
S=input()
x,y=map(int,input().split())
ans=[]
S+="T"
cnt=0
fl=0
ans.append([[0,0]])
for s in S:
    if s=="F":
        cnt+=1
    elif s=="T" :
        fl+=1
        tmp=[]
        for j in range(len(ans[fl-1])):
            nx = ans[fl - 1][j][0]
            ny = ans[fl - 1][j][1]
            if fl%2==1:
                tmp.append([nx+cnt,ny])
                tmp.append([nx-cnt,ny])
            else:
                tmp.append([nx, ny+cnt])
                tmp.append([nx, ny-cnt])
        cnt=0
        ans.append(tmp)
for i in range(len(ans)):
    if [x,y] in ans[i]:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
S=input()
x,y=map(int,input().split())
ans=[]
S+="T"
cnt=0
fl=0
ans.append([[0,0]])

for s in S:
    if s=="F":
        cnt+=1
    elif s=="T" :
        fl+=1
        tmp=[]
        for j in range(len(ans[fl-1])):
            nx = ans[fl - 1][j][0]
            ny = ans[fl - 1][j][1]
            if fl%2==1:
                tmp.append([nx+cnt,ny])
                tmp.append([nx-cnt,ny])
            else:
                tmp.append([nx, ny+cnt])
                tmp.append([nx, ny-cnt])
        cnt=0
        ans.append(tmp)

for i in range(len(ans)):
    if [x,y] in ans[i]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
#!python3

# input
S = input()
X, Y = list(map(int, input().split()))


def main():
    dx, dy = 0, 0
    side = True
    for s in S:
        if s == "F":
            if side:
                dx += 1
            else:
                dy += 1
        else:
            side = not side
    
    b1 = X <= dx and (dx - X) % 2 == 0
    b2 = Y <= dy and (dy - Y) % 2 == 0
    ans = "Yes" if b1 and b2 else "No"
    print(ans)


if __name__ == "__main__":
    main()