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:
def isReach( goal, move ):
    msum = sum(move)
    m = len(move)

    if msum < abs(goal):
        return False

    dp = [[False]*(msum*2+2) for i in range(m+1)]
    dp[0][0] = True

    for i in range(m):
        for j in range(-msum,msum+1):
            if dp[i][j]:
                if j-move[i] >= -msum:
                    dp[i+1][j-move[i]] = True
                if j+move[i] <= msum:
                    dp[i+1][j+move[i]] = True
    
    return dp[m][goal]


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

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move) and isReach(y,y_move):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
def isReach( goal, move ):
    msum = sum(move)
    m = len(move)
    dp = [[False]*(msum*2+2) for i in range(m+1)]
    dp[0][0] = True

    if msum < abs(goal):
        return False 

    for i in range(m):
        for j in range(-msum,msum+1):
            if dp[i][j]:
                dp[i+1][j-move[i]] = True
                dp[i+1][j+move[i]] = True
    
    return dp[m][goal]

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

move_dist = [len(move) for move in s]
x_move = move_dist[0::2]
y_move = move_dist[1::2]

if isReach(x,x_move) and isReach(y,y_move):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
if 'T' in s:
  pos=s.index('T')
  x-=pos
  s=s[pos+1:]
arr=s.split('T')
xarr=[]
yarr=[]
for i in range(len(arr)):
  l=len(arr[i])
  if l==0:
    continue
  if i%2==0:
    yarr.append(l)
  else:
    xarr.append(l)
x+=sum(xarr)
y+=sum(yarr)
if x%2==1 or y%2==1:
  print('No')
else:
  #DP for xarr,yarr
  xdp=[0]*8005
  xdp[0]=1
  for val in xarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if xdp[i-val]==1:
        xdp[i]=1
  ydp=[0]*8005
  ydp[0]=1
  for val in yarr:
    for i in range(8004,-1,-1):
      if i-val<0:
        break
      if ydp[i-val]==1:
        ydp[i]=1
  if xdp[x//2]==0:
    print('No')
  else:
    if ydp[y//2]==0:
      print('No')
    else:
      print('Yes')

Submission status: Wrong Answer

Solution code:
s=input().split('T')
x,y=map(int,input().split())
dx,dy={0},{0}
for a in map(len,s[::2]):dx=set(t+a for t in dx)|set(t-a for t in dx)
for b in map(len,s[1::2]):dy=set(t+b for t in dy)|set(t-b for t in dy)
if x in dx and y in dy:print('Yes')
else:print('No')

Submission status: Wrong Answer

Solution code:
s=input().split('T')
x,y=map(int,input().split())
dx,dy=[0],[0]
for a in map(len,s[::2]):dx=[t+a for t in dx]+[t-a for t in dx]
for b in map(len,s[1::2]):dy=[t+b for t in dy]+[t-b for t in dy]
if x in dx and y in dy:print('Yes')
else:print('No')

Submission status: Wrong Answer

Solution code:
s=input()
*x,=map(abs,map(int,input().split()))
a=[0,0]
m=0
for c in s:m^=c>'F';a[m]+=c<'T'and((a[m]<x[m])or-1)
print('YNeos'[a!=x::2])

Submission status: Wrong Answer

Solution code:
s=input()
*x,=map(int,input().split())
a=[0,0]
m=0
for c in s:m^=c>'F';a[m]+=c<'T'and((a[m]<x[m])or-1)
print('YNeos'[a!=x::2])

Submission status: Wrong Answer

Solution code:
s = input() + "T"
x, y = map(int, input().split())
n = len(s)

tmp = n 
for i in range(n):
    if s[i] == "T":
        tmp = i
        break
    x -= 1
    
up_down = False
cnt = 0
ud =[]
lr = []
for i in range(tmp, n):
    if s[i] == "T":
        if up_down and cnt != 0:
            ud.append(cnt)
        if not up_down and cnt != 0:
            lr.append(cnt)
        cnt = 0
        up_down = not up_down
    else:
        cnt += 1

def is_subset_sum(array, k, x_y):
    if (k + x_y) % 2 != 0:
        return False
    MOD = 10**9 + 1
    n = len(array)

    # dp[i][j] := i番目までを選んだときにsumがjになるときの通り数
    dp = [[False] * (k + 1) for i in range(n + 1)]
    dp[0][0] = True

    for i in range(n):
        for j in range(k + 1):
            if j - array[i] < 0:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j] or dp[i][j - array[i]]
    if not 0 <= abs(k + x_y)//2 < k + 1:
        return False
    return dp[n][abs(k + x_y)//2]


if is_subset_sum(lr, sum(lr), x) and is_subset_sum(ud, sum(ud), y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t*1)
        l = (l+1)%2
        t = 0
L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        R = min(16000, 16002-d)
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, R):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(R, 16000):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2

    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t*1)
        l = (l+1)%2
        t = 0
L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2

    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t*1)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2

    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t*1)


for i in range(2):
    DP = [0]*(2*N + 1)
    if i:
        DP[N] = 1
    else:
        DP[N+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*(2*N+1)
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 2*N+1 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(2*N + 1 - d, 2*N + 1):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if int(DP[XY[i] + N]) == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = "T"*8000#input()
XY = [0, 0]#inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[0], [0]]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(1)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase as abc
from string import ascii_uppercase as ABC
from heapq import heappop, heappush
from collections import Counter

def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[0], [0]]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)


for i in range(2):
    DP = [0]*16002
    if i:
        DP[8000] = 1
    else:
        DP[8000+L[0].pop(0)] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)
XY[0] -= L[0].pop(0)

for i in range(2):
    DP = [0]*16002
    DP[8000] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(16002 - d, 16002):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))

S = input()
XY = inpl()

L = [[], []]
l = 0
t = 0
for i in range(len(S)):
    if S[i] == "F":
        t += 1
    else:
        L[l].append(t)
        l = (l+1)%2
        t = 0
if t:
    L[l].append(t)
XY[0] -= L[0].pop(0)

for i in range(2):
    DP = [0]*16002
    DP[8000] = 1
    for j in range(len(L[i])):
        DP2 = [0]*16002
        d = L[i][j]
        if d == 0:
            continue
        for k in range(d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k+d] |= DP[k]
            DP2[k-d] |= DP[k]
        for k in range(d, 16002 - d):
            DP2[k] |= DP[k]
            DP2[k-d] |= DP[k]
        DP = DP2
    if DP[XY[i] + 8000] == 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from sys import stdin
from numpy import logical_or, zeros


def solve(s, p, q):

    ss = [list(g) for k, g in groupby(s)]
    len_sss = [len(sss) for sss in ss]
    ss_and_len = list(zip(ss, len_sss))
    dir = 0
    dx, dy = [], []

    for sss, l in ss_and_len:
        if sss[0] == 'T':
            dir += l
        elif sss[0] == 'F':
            if dir % 2 == 0:
                dx.append(l)
            else:
                dy.append(l)

    len_dx = len(dx)
    len_dy = len(dy)

    _n = len(s)
    __n = _n*2+1

    if 0 < len_dx:
        dpx = zeros((len_dx, __n), dtype='uint64')
        dpx[0][_n+dx[0]] = 1

        for i in range(1, len_dx):
            s = dx[i]
            dpx[i][:s] = dpx[i-1][s:2*s]
            dpx[i][s:-s] = logical_or(dpx[i-1][:-2*s], dpx[i-1][2*s:])
            dpx[i][-s:] = dpx[i-1][-2*s:-s]
    else:
        dpx = [[0]*__n]
        dpx[0][_n] = 1

    if 0 < len_dy:
        dpy = zeros((len_dy, __n), dtype='uint64')
        dpy[0][_n+dy[0]] = 1
        dpy[0][_n-dy[0]] = 1

        for i in range(1, len_dy):
            s = dy[i]
            dpy[i][:s] = dpy[i-1][s:2*s]
            dpy[i][s:-s] = logical_or(dpy[i-1][:-2*s], dpy[i-1][2*s:])
            dpy[i][-s:] = dpy[i-1][-2*s:-s]
    else:
        dpy = [[0]*__n]
        dpy[0][_n] = 1

    return dpx[-1][_n+p] and dpy[-1][_n+q]


if __name__ == '__main__':
    s = stdin.readline()
    p, q = map(int, input().split())

    print('Yes' if solve(s, p, q) else 'No')

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from sys import stdin
from numpy import array, logical_or


def solve(s, p, q):

    ss = [list(g) for k, g in groupby(s)]
    len_sss = [len(sss) for sss in ss]
    len_ss = len(ss)
    dir = 0
    dx = []
    dy = []

    for i in range(len_ss):
        if ss[i][0] == 'T':
            dir += len_sss[i]
        elif ss[i][0] == 'F':
            if dir % 2 == 0:
                dx.append(len_sss[i])
            else:
                dy.append(len_sss[i])

    len_dx = len(dx)
    len_dy = len(dy)

    _n = len(s)
    __n = _n*2+1

    dpx = [[0]*(_n*2+1) for _ in range(len_dx)]
    dpy = [[0]*(_n*2+1) for _ in range(len_dy)]
    dpx = array(dpx)
    dpy = array(dpy)

    if 0 < len_dx:
        dpx[0][_n+dx[0]] = 1

        for i in range(1, len_dx):
            dpx[i][:dx[i]] = dpx[i-1][dx[i]:2*dx[i]]
            dpx[i][dx[i]:__n-dx[i]
                   ] = logical_or(dpx[i-1][:__n-2*dx[i]], dpx[i-1][2*dx[i]:])
            dpx[i][__n-dx[i]:] = dpx[i-1][__n-2*dx[i]:__n-dx[i]]
    else:
        dpx = [[0]*__n]
        dpx[0][_n] = 1

    if 0 < len_dy:
        dpy[0][_n+dy[0]] = 1
        dpy[0][_n-dy[0]] = 1

        for i in range(1, len_dy):
            dpy[i][:dy[i]] = dpy[i-1][dy[i]:2*dy[i]]
            dpy[i][dy[i]:__n-dy[i]
                   ] = logical_or(dpy[i-1][:__n-2*dy[i]], dpy[i-1][2*dy[i]:])
            dpy[i][__n-dy[i]:] = dpy[i-1][__n-2*dy[i]:__n-dy[i]]
    else:
        dpy = [[0]*__n]
        dpy[0][_n] = 1

    return dpx[-1][_n+p] and dpy[-1][_n+q]


if __name__ == '__main__':
    s = stdin.readline()
    p, q = map(int, input().split())

    print('Yes' if solve(s, p, q) else 'No')

Submission status: Wrong Answer

Solution code:
from itertools import groupby


def solve(s, p, q):

    ss = [list(g) for k, g in groupby(s)]
    len_sss = [len(sss) for sss in ss]
    len_ss = len(ss)
    dir = 0
    dx = []
    dy = []

    for i in range(len_ss):
        if ss[i][0] == 'T':
            dir += len_sss[i]
        else:
            if dir % 2 == 0:
                dx.append(len_sss[i])
            else:
                dy.append(len_sss[i])

    len_dx = len(dx)
    len_dy = len(dy)

    _n = len(s)

    dpx = [[0]*(_n*2+1) for _ in range(len_dx)]
    dpy = [[0]*(_n*2+1) for _ in range(len_dy)]

    if 0 < len_dx:
        dpx[0][_n+dx[0]] = 1

        for i in range(1, len_dx):
            for x in range(_n*2+1):
                if x-dx[i] < 0:
                    dpx[i][x] = dpx[i-1][x+dx[i]]
                elif _n*2+1 <= x+dx[i]:
                    dpx[i][x] = dpx[i-1][x-dx[i]]
                else:
                    dpx[i][x] = dpx[i-1][x+dx[i]] or dpx[i-1][x-dx[i]]
    else:
        dpx = [[0]*(_n*2+1)]
        dpx[0][_n] = 1

    if 0 < len_dy:
        dpy[0][_n+dy[0]] = 1
        dpy[0][_n-dy[0]] = 1

        for i in range(1, len_dy):
            for y in range(_n*2+1):
                if y-dy[i] < 0:
                    dpy[i][y] = dpy[i-1][y+dy[i]]
                elif _n*2+1 <= y+dy[i]:
                    dpy[i][y] = dpy[i-1][y-dy[i]]
                else:
                    dpy[i][y] = dpy[i-1][y+dy[i]] or dpy[i-1][y-dy[i]]
    else:
        dpy = [[0]*(_n*2+1)]
        dpy[0][_n] = 1
    # print(dpx[-1])
    # print(dpy[-1])

    return dpx[-1][_n+p] and dpy[-1][_n+q]


if __name__ == '__main__':
    s = input()
    p, q = map(int, input().split())

    print('Yes' if solve(s, p, q) else 'No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
ct=0
XY=[]
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
  else:
    XY.append(ct)
    ct=0
XY.append(ct)
x-=XY[0]
X=XY[2::2]
Y=XY[1::2]


def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1:
          DP[i+1][j]=DP[i][j+zz]
        if j-zz>=0:
          DP[i+1][j]=DP[i][j-zz]
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
ct=0
XY=[]
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
  else:
    XY.append(ct)
    ct=0
XY.append(ct)
x-=XY[0]
X=XY[2::2]
Y=XY[1::2]


def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1:
          DP[i+1][j]=DP[i][j+zz]
        if j-zz>=0:
          DP[i+1][j]=DP[i][j-zz]
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
X,Y=[],[]
ct,dir,ss=0,1,1
sp=False
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
    if i==len(s)-1:
      if ss==1:
        if x==ct and y==0:
          sp=True
      elif dir==1:
        X.append(ct)
      else:
        Y.append(ct)
  else:
    if ss==1:
      x-=ct
      ct,dir,ss=0,0,0
    elif dir==1:
      X.append(ct)
      ct,dir=0,0
    else:
      Y.append(ct)
      ct,dir=0,1

def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1:
          DP[i+1][j]=DP[i][j+zz]
        elif j-zz>=0:
          DP[i+1][j]=DP[i][j-zz]
    return DP[nz][z+tot]
if sp==True:
  print("Yes")

elif chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
s = input() + 'T'
x, y = map(int, input().split())

si = 0
while s[si] == 'F':
    x -= 1
    si += 1
si += 1

d = [[], []]
dir = 1
z = 0
for i in range(si, len(s)):
    if s[i] == 'T':
        if z > 0:
            d[dir].append(z)
        dir = (dir + 1) % 2
        z = 0
    else:
        z += 1

d[0].sort()
d[1].sort()
# print(x, y)
# print(d)

def check(a, b):
    c1 = defaultdict(int)
    c2 = defaultdict(int)
    c1[0] += 1
    for i in range(len(a)):
        for c in c1:
            c2[c+a[i]] += 1
            c2[c-a[i]] += 1
        c1 = c2.copy()

    if b in c1:
        return True
    else:
        return False

if check(d[0], x) and check(d[1], y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
S=list(map(len,input().split("T")))
x,y=map(int,input().split())
x=abs(x-S[0])
y=abs(y)
L=S[2::2]
R=S[1::2]
La=list(accumulate(L))
Ra=list(accumulate(R))
sumL=sum(L)
sumR=sum(R)
flag=0
if sumL>=x and sumR>=y and (sumL-x)%2==0 and (sumR-y)%2==0 and flag==0:
    setL1={0}
    setR1={0}
    gL=(sumL-x)//2
    gR=(sumR-y)//2
    if gL==0:
        flag=1
    else:
        for cnt,i in enumerate(L):
            setL=setL1
            setL1=set()
            s=setL1.add
            h=sumL-La[cnt]
            for j in setL:
                k=i+j
                if k<gL and h+k>=gL:
                    s(k)
                if j<gL and h+j>=gL:
                    s(j)
                elif k==gL:
                    flag=1
                    break
            if flag==1:
                break
    if flag==1:
        if gR==0:
            flag=2
        else:
            for cnt,i in enumerate(R):
                setR=setR1
                setR1=set()
                s=setR1.add
                h=sumR-Ra[cnt]
                for j in setR:
                    k=i+j
                    if k<gR and h+k>=gR:
                        s(k)
                    if j<gR and h+j>=gR:
                        s(j)
                    elif k==gR:
                        flag=2
                        break
                if flag==2:
                    break
if flag==2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
S=list(map(len,input().split("T")))
x,y=map(lambda x:abs(int(x)),input().split())
L=S[::2]
R=S[1::2]
sumL=sum(L)
sumR=sum(R)
flag=0    
if sumL>=x and sumR>=y and (sumL-x)%2==0 and (sumR-y)%2==0 and flag==0:
    setL={0}
    setR={0}
    setL1={0}
    setR1={0}
    gL=(sumL-x)//2
    gR=(sumR-y)//2
    if gL==0:
        flag=1
    else:
        for i in L:
            setL=dc(setL1)
            for j in setL:
                k=i+j
                if k<gL:
                    setL1.add(k)
                elif k==gL:
                    flag=1
                    break
            if flag==1:
                break
    if flag==1:
        if gR==0:
            flag=2
        else:
            for i in R:
                for j in setR:
                    setR=dc(setR1)
                    k=i+j
                    if k<gR:
                        setR1.add(k)
                    elif k==gR:
                        flag=2
                        break
                if flag==2:
                    break
if flag==2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

cnt_T = 0
ex = 0
pt = 0
ans = "No"
prob_x_u = 0
prob_x_d = 0
prob_y_u = 0
prob_y_d = 0
while True:
  #print(ex,cnt_T)
  if cnt_T == 0:
    pt = s.find("T")
    if pt == -1:
      #そこから最後までTが見つからない場合
      if x == len(s) and y == 0:
        ans = "Yes"
      break
    else:
      prob_x_u += pt
      ex += pt+1
      cnt_T += 1
  else:
    pt = s[ex:].find("T")
    if pt == -1:
      if cnt_T % 2 == 0: #x軸方向のどっちかに移動してる
        prob_x_u += len(s[ex:])
        prob_x_d -= len(s[ex:])
      else:
        prob_y_u += len(s[ex:])
        prob_y_d -= len(s[ex:])
        
      if prob_x_d <= x <= prob_x_u and prob_y_d <= y <= prob_y_u:
        ans = "Yes"
      break
    else:
      if cnt_T % 2 == 0: #x軸方向のどっちかに移動してる
        prob_x_u += pt
        prob_x_d -= pt
      else:
        prob_y_u += pt
        prob_y_d -= pt
        
    ex += pt+1
    cnt_T += 1
    
print(ans)

Submission status: Wrong Answer

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

X,Y = [],[]
for i, s in enumerate(S.split('T')):
    if i % 2 == 0:
        X.append(len(s))
    else:
        Y.append(len(s))

sum_x, sum_y = sum(X), sum(Y)
abs_x, abs_y = abs(x), abs(y)
if x < 0:
    abs_x += X[0]
    sum_x -= X[0]
    X.remove(X[0])
#print(sum_x, abs_x ,sum_y, abs_y, x, y)
if sum_x < abs_x or sum_y < abs_y or (sum_x - abs_x) % 2 or (sum_y - abs_y) % 2:
    print('No')
    exit()

X.sort()
dif = (sum_x - abs_x) // 2
tmp = 0
#print('-', X, dif, sum_x, x)
for i in range(len(X)):
    if tmp == dif:
        break
    tmp += X[i]
else:
    if tmp != dif:
        print('No')
        exit()
Y.sort()
dif = (sum_y - abs_y) // 2
tmp = 0
for i in range(len(Y)):
    if tmp == dif:
        break
    tmp += Y[i]
else:
    if tmp != dif:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
from itertools import accumulate as acc

input=sys.stdin.readline

def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: return False

S=input()
s=list(S.split("T"))
X,Y=map(int,input().split())
x,y=[len(i) for i in s[::2]],[len(i) for i in s[1::2]]
if S[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)


print("Yes" if cul(x,X) and cul(y,Y) else "No")

Submission status: Wrong Answer

Solution code:
def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: return False

s=list(input().split("T"))
X,Y=map(int,input().split())
x,y=[len(i) for i in s[::2]],[len(i) for i in s[1::2]]
if s[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)
x.sort(reverse=True)
y.sort(reverse=True)

print("Yes" if cul(x,X) and cul(y,Y) else "No")

Submission status: Wrong Answer

Solution code:
def f(s):
    return abs(int(s))

def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: return False

s=input()
x,y=[],[]
d,tmp=0,0
for i in range(len(s)):
    if s[i]=="T":
        if tmp!=0:
            if d==0: x.append(tmp)
            else: y.append(tmp)
        d^=1
        tmp=0
        
    else: tmp+=1
if tmp!=0:
    if d==0: x.append(tmp)
    else: y.append(tmp)

X,Y=map(f,input().split())
print("Yes" if cul(x,X) and cul(y,Y) else "No")

Submission status: Wrong Answer

Solution code:
def f(s):
    return abs(int(s))

def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: False

s=input()
x,y=[],[]
d,tmp=0,0
for i in range(len(s)):
    if s[i]=="T":
        if tmp!=0:
            if d==0: x.append(tmp)
            else: y.append(tmp)
        d^=1
        tmp=0
        
    else: tmp+=1
if tmp!=0:
    if d==0: x.append(tmp)
    else: y.append(tmp)

X,Y=map(f,input().split())
print("Yes" if cul(x,X) and cul(y,Y) else "No")