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=map(int,input().split())
M=2
H=0
W=0
X=0

for i in range(len(S)):
    if M==2:
        if S[i]=='F':
            W+=1
            X+=1
        elif S[i]=='T':
            M=1
    elif M==0:
        if S[i]=='F':
            W+=1
        elif S[i]=='T':
            M=1
    elif M==1:
        if S[i]=='F':
            H+=1
        elif S[i]=='T':
            M=0

if 2*X-W<=x and x<=W and -H<=y and y<=H and abs(W)%2==x%2 and abs(H)%2==y%2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input()
W,H=map(int,input().split())

X=0
Y=0

B=1
for i in range(len(s)):
    if B==1:
        if s[i]=='F':
            X+=1
        elif s[i]=='T':
            B=0
    elif B==0:
        if s[i]=='F':
            Y+=1
        elif s[i]=='T':
            B=1
#print(X,Y)
#print(abs(W),abs(H))
if abs(W)<=X and abs(W)%2==X%2 and abs(H)<=Y and abs(H)%2==Y%2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

x_list = []
y_list = []

f = 0
t = 0
for i in s:
    if i == "F":
        f += 1
    else:
        t += 1
        if t % 2 == 1:
            x_list.append(f)
            f = 0
        else:
            y_list.append(f)
            f = 0
if f > 0:
    if t % 2 == 0:
        x_list.append(f)
    else:
        y_list.append(f)

dpx = [[0 for i in range(16001)] for j in range(len(x_list)+1)]
dpy = [[0 for i in range(16001)] for j in range(len(y_list)+1)]

dpx[0][8000] = 1
dpy[0][8000] = 1

for i in range(len(x_list)):
    for num in range(16001):
        if num + x_list[i] <= 16000 and dpx[i][num] == 1:
            dpx[i+1][num+x_list[i]] = 1
        if num - x_list[i] >= 0 and dpx[i][num] == 1:
            dpx[i+1][num-x_list[i]] = 1

for i in range(len(y_list)):
    for num in range(16001):
        if num + y_list[i] <= 16000 and dpy[i][num] == 1:
            dpy[i+1][num+y_list[i]] = 1
        if num - y_list[i] >= 0 and dpy[i][num] == 1:
            dpy[i+1][num-y_list[i]] = 1

if dpx[len(x_list)][x+8000] == 1 and dpy[len(y_list)][y+8000] == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def search(keys,dic,now,goal):
    if now==len(keys):
        if goal==0:
            return True
        else:
            return False
    k=keys[now]
    for i in range(dic[k]+1):
        if search(keys,dic,now+1,goal-k*i+k*(dic[k]-i)):
            return True
    return False

s=input()+'T'
x,y=list(map(int,input().split()))
xlist=[0 for _ in range(8000)]
ylist=[0 for _ in range(8000)]
flag='x+'
ini=0
tmp=0
for c in s:
    if c =='F':
        tmp+=1
    else:
        if flag=='x':
            xlist[tmp]+=1
        elif flag=='y':
            ylist[tmp]+=1
        else:
            ini=tmp
        tmp=0
        if flag=='y':
            flag='x'
        else:
            flag='y'
xlist[0]=0
ylist[0]=0
xkey=[]
ykey=[]
for i in range(8000):
    if xlist[i]>0:
        xkey.append(i)
    if ylist[i]>0:
        ykey.append(i)
xkey.reverse()
ykey.reverse()
if search(xkey,xlist,0,x-ini) and search(ykey,xlist,0,y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

X = [0]
Y = [0]

for k in range(len(a)):
    if k%2 == 0:
        nx = []
        for e in X:
            nx.append(e+a[k])
            nx.append(e-a[k])
        X = list(set(nx))
    else:
        ny = []
        for e in Y:
            ny.append(e+a[k])
            ny.append(e-a[k])
        Y = list(set(ny))

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

Submission status: Wrong Answer

Solution code:
def search(keys,dic,now,goal):
    if len(keys)==0:
        if now==goal:
            return True
        else:
            return False
    k=keys.pop()
    for i in range(dic[k]+1):
        if search(keys,dic,now+k*i-k*(dic[k]-i),goal):
            return True
    return False

s=input()+'T'
x,y=list(map(int,input().split()))
xdic={}
ydic={}

flag='x+'
ini=0
tmp=0
for c in s:
    if c =='F':
        tmp+=1
    else:
        if flag=='x':
            if xdic.get(tmp,0)==0:
                xdic[tmp]=1
            else:
                xdic[tmp]+=1
        elif flag=='y':
            if ydic.get(tmp,0)==0:
                ydic[tmp]=1
            else:
                ydic[tmp]+=1
        else:
            ini=tmp
        tmp=0
        if flag=='y':
            flag='x'
        else:
            flag='y'

if search(list(xdic.keys()),xdic,ini,x) and search(list(ydic.keys()),ydic,0,y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:

def search(keys,dic,now,goal):
    if len(keys)==0:
        if now==goal:
            return True
        else:
            return False
    k=keys.pop()
    for i in range(dic[k]+1):
        if search(keys,dic,now+k*i-k*(dic[k]-i),goal):
            return True

s=input()+'T'
x,y=list(map(int,input().split()))
xdic={}
ydic={}

flag='x+'
ini=0
tmp=0
for c in s:
    if c =='F':
        tmp+=1
    else:
        if flag=='x':
            if xdic.get(tmp,0)==0:
                xdic[tmp]=1
            else:
                xdic[tmp]+=1
        elif flag=='y':
            if ydic.get(tmp,0)==0:
                ydic[tmp]=1
            else:
                ydic[tmp]+=1
        else:
            ini=tmp
        tmp=0
        if flag=='y':
            flag='x'
        else:
            flag='y'

if search(list(xdic.keys()),xdic,ini,x) and search(list(ydic.keys()),ydic,0,y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

x_cur, y_cur = 0, 0
direction = 'r'
for i, ss in enumerate(s):
    if ss == 'F':
        if direction == 'r':
            x_cur += 1
        elif direction == 't':
            y_cur += 1
        elif direction == 'l':
            x_cur -= 1
        else:
            y_cur -= 1
    else:
        if x_cur >= x and y_cur >= y:
            if direction in ['t', 'b']:
                direction = 'l'
            else:
                direction = 'b'
        elif x_cur >= x and y_cur < y:
            if direction in ['t', 'b']:
                direction = 'l'
            else:
                direction = 't'
        elif x_cur < x and y_cur >= y:
            if direction in ['t', 'b']:
                direction = 'r'
            else:
                direction = 'b'
        else:
            if direction in ['t', 'b']:
                direction = 'r'
            else:
                direction = 't'
    
if x_cur == x and y_cur == y:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i != -1:
        x -= i
    i += 1
    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s + 'T', i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 != 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if nturns % 2 == 0:
            xsteps.append(cnt)
        else:
            ysteps.append(cnt)
        cnt = 0
        nturns += 1
    else:
        if nturns % 2 == 0:
            xsteps.append(cnt)
        else:
            ysteps.append(cnt)

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def can_reach(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) * 2 + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 0, m - 1)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if can_reach(xsteps, abs(x)) == True and can_reach(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def can_reach(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) * 2 + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, m - 1)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if can_reach(xsteps, abs(x)) == True and can_reach(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def can_reach(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 0, m - 1)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if can_reach(xsteps, abs(x)) == True and can_reach(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def can_reach(steps, x):
    m = len(steps)
    if m == 0 and x == 0:
        return True
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 0, m - 1)):
        for j in range(n):
            if dp[i][j] == True:
                if j + step < n:
                    dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i > 0:
        x -= i
    else:
        i = 0

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s, i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1
    else:
        if cnt > 0:
            if nturns % 2 == 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)

    if can_reach(xsteps, abs(x)) == True and can_reach(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input().split("T")
x,y=map(int,input().split())
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
if abs(x)+abs(y)>sum(A)+sum(B):
    print("No")
    exit()
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
    for i in range(2*T+1):
        if i+A[l]>2*T:
            dpx[l+1][i]=dpx[l][i-A[l]]
        elif i-A[l]<0:
            dpx[l+1][i]=dpx[l][i+A[l]]
        else:
            dpx[l+1][i]=dpx[l][i-A[l]] or dpx[l][i+A[l]]
for l in range(Y):
    for i in range(2*T+1):
        if i+B[l]>2*T:
            dpy[l+1][i]=dpy[l][i-B[l]]
        elif i-B[l]<0:
            dpy[l+1][i]=dpy[l][i+B[l]]
        else:
            dpy[l+1][i]=dpy[l][i-B[l]] or dpy[l][i+B[l]]
if dpx[X][x+T] and dpy[Y][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input().split("T")
x,y=map(int,input().split())
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
if abs(x)+abs(y)>sum(A)+sum(B):
    print("No")
    exit()
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
    for i in range(2*T+1):
        if i+A[l]>2*T:
            dpx[l+1][i]=dpx[l][i-A[l]]
        elif i-A[l]<0:
            dpx[l+1][i]=dpx[l][i+A[l]]
        else:
            dpx[l+1][i]=dpx[l][i-A[l]] or dpx[l][i+A[l]]
for l in range(Y):
    for i in range(2*T+1):
        if i+B[l]>2*T:
            dpx[l+1][i]=dpx[l][i-B[l]]
        elif i-B[l]<0:
            dpx[l+1][i]=dpx[l][i+B[l]]
        else:
            dpx[l+1][i]=dpx[l][i-B[l]] or dpx[l][i+B[l]]

if dpx[X][x+T] and dpy[Y][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input().split("T")
x,y=map(int,input().split())
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
if abs(x)+abs(y)>sum(A)+sum(B):
    print("No")
    exit()
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
    for i in range(2*T+1):
        if dpx[l][i]:
            dpx[l+1][i-A[l]]=True
            dpx[l+1][i+A[l]]=True
for r in range(Y):
    for i in range(2*T+1):
        if dpy[r][i]:
            dpy[r+1][i-B[r]]=True
            dpy[r+1][i+B[r]]=True
if dpx[X][x+T] and dpy[Y][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input().split("T")
x,y=map(int,input().split())
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
    for i in range(2*T+1):
        if dpx[l][i]:
            dpx[l+1][i-A[l]]=True
            dpx[l+1][i+A[l]]=True
for r in range(Y):
    for i in range(2*T+1):
        if dpy[r][i]:
            dpy[r+1][i-B[r]]=True
            dpy[r+1][i+B[r]]=True
if dpx[X][x+T] and dpy[Y][y+T]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input().split("T")
x,y=map(int,input().split())
x+=8000
y+=8000
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
X=len(A)
Y=len(B)
dpx=[[0 for i in range(16001)] for _ in range(X+1)]
dpy=[[0 for i in range(16001)] for _ in range(Y+1)]
#-8000->0
dpx[0][8000]=1
dpy[0][8000]=1
for l in range(X):
    for i in range(16001):
        if dpx[l][i]==1:
            dpx[l+1][i-A[l]]=1
            dpx[l+1][i+A[l]]=1
for r in range(Y):
    for i in range(16001):
        if dpy[r][i]==1:
            dpy[r+1][i-B[r]]=1
            dpy[r+1][i+B[r]]=1
if dpx[X][x]==1 and dpy[Y][y]==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
a = []
b = []

p = 0 #進む長さ
q = 1 #aとbのどちらに加えるか

a0 = s.find('T')

for i in range(len(s)):
    if s[i] == 'T':
        if q == 1:
            a.append(p)
        else:
            b.append(p)
        q *= -1
        p = 0
    if s[i] == 'F':
        p += 1
        if i == len(s) - 1:
            if q == 1:
                a.append(p)
            else:
                b.append(p)
if a:
    x -= a.pop(0)

def knapsack(L, n):
    #リストLの要素のいくつかの足し合わせでnを作れるか？
    if n < 0 or n > sum(L):
        return False
    else:
        dp = [True] + [False] * (n)
        for l in L:
            for i in range(n, -1, -1):
                if i >= l:
                    dp[i] = dp[i - l]
        return dp[n]

def reachable(L, n):
    #リストLの要素の+-1倍の足し合わせでnを作れるか？
    S = sum(L)
    return (S - n) % 2 == 0 and knapsack(L, (S - n) // 2)

if reachable(a, x) and reachable(b, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
a = []
b = []

p = 0 #進む長さ
q = 1 #aとbのどちらに加えるか

for i in range(len(s)):
    if s[i] == 'T':
        if p > 0 and q == 1:
            a.append(p)
        elif p > 0 and q == -1:
            b.append(p)
        q *= -1
        p = 0
    if s[i] == 'F':
        p += 1
        if i == len(s) - 1:
            if q == 1:
                a.append(p)
            else:
                b.append(p)
if a:
    x -= a.pop(0)

def knapsack(L, n):
    #リストLの要素のいくつかの足し合わせでnを作れるか？
    if n < 0 or n > sum(L):
        return False
    else:
        dp = [True] + [False] * (n)
        for l in L:
            for i in range(n, -1, -1):
                if i >= l:
                    dp[i] = dp[i - l]
        return dp[n]

def reachable(L, n):
    #リストLの要素の+-1倍の足し合わせでnを作れるか？
    S = sum(L)
    return (S - n) % 2 == 0 and knapsack(L, (S - n) // 2)

if reachable(a, x) and reachable(b, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

First = True
flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if First:
			Xans -= tmp
			First = False
		else:
			if flag:
				Xmove.append(tmp)
			else:
				Ymove.append(tmp)
		tmp = 0
		flag = not flag

Xsum = sum(Xmove)
if (Xsum+Xans)%2 == 1:
	print('No')
	sys.exit()
elif abs(Xans) > Xsum:
	print('No')
	sys.exit()
else:
	Xpos = (Xsum+Xans)//2
	dp = [0]*(Xpos+1)
	dp[0] = 1
	for x in Xmove:
		for i in range(Xpos,x-1,-1):
			dp[i] = dp[i-x]
		if dp[-1] == 1:
			break
	else:
		print('No')
		sys.exit()

Ysum = sum(Ymove)
if (Ysum+Yans)%2 == 1:
	print('No')
	sys.exit()
elif abs(Yans) > Ysum:
	print('No')
	sys.exit()
else:
	Ypos = (Ysum+Yans)//2
	dp = [0]*(Ypos+1)
	dp[0] = 1
	for y in Ymove:
		for i in range(Ypos,y-1,-1):
			dp[i] = dp[i-y]
		if dp[-1] == 1:
			break
	else:
		print('No')
		sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if flag:
			Xmove.append(tmp)
		else:
			Ymove.append(tmp)
		tmp = 0
		flag = not flag

if len(Xmove) == 0:
	if Xans != 0:
		print('No')
		sys.exit()
elif len(Xmove) == 1:
	if Xans != Xmove[0]:
		print('No')
		sys.exit()
else:
	Xsum = sum(Xmove)
	if (Xsum+Xans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Xans) > Xsum:
		print('No')
		sys.exit()
	else:
		Xpos = (Xsum+Xans)//2
		dp = [0]*(Xpos+1)
		dp[0] = 1
		for x in Xmove:
			for i in range(Xpos,x-1,-1):
				dp[i] = dp[i-x]
			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()


if len(Ymove) == 0:
	if Yans != 0:
		print('No')
		sys.exit()
else:
	Ysum = sum(Ymove)
	if (Ysum+Yans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Yans) > Ysum:
		print('No')
		sys.exit()
	else:
		Ypos = (Ysum+Yans)//2
		dp = [0]*(Ypos+1)
		dp[0] = 1
		for y in Ymove:
			for i in range(Ypos,y-1,-1):
				dp[i] = dp[i-y]

			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if flag:
			Xmove.append(tmp)
		else:
			Ymove.append(tmp)
		tmp = 0
		flag = not flag

if len(Xmove) == 0:
	if Xans != 0:
		print('No')
		sys.exit()
elif len(Xmove) == 1:
	if abs(Xans) != Xmove[0]:
		print('No')
		sys.exit()
else:
	Xsum = sum(Xmove)
	if (Xsum+Xans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Xans) > Xsum:
		print('No')
		sys.exit()
	else:
		Xpos = (Xsum+Xans)//2
		dp = [0]*(Xpos+1)
		dp[0] = 1
		for x in Xmove:
			for i in range(Xpos,x-1,-1):
				dp[i] = dp[i-x]
			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()


if len(Ymove) == 0:
	if Yans != 0:
		print('No')
		sys.exit()
else:
	Ysum = sum(Ymove)
	if (Ysum+Yans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Yans) > Ysum:
		print('No')
		sys.exit()
	else:
		Ypos = (Ysum+Yans)//2
		dp = [0]*(Ypos+1)
		dp[0] = 1
		for y in Ymove:
			for i in range(Ypos,y-1,-1):
				dp[i] = dp[i-y]

			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Xans,Yans = inpl()

Xmove = []
Ymove = []

flag = True
tmp = 0
for s in S+'T':
	if s == 'F':
		tmp += 1
	else:
		if flag:
			Xmove.append(tmp)
		else:
			Ymove.append(tmp)
		tmp = 0
		flag = not flag

if len(Xmove) == 0:
	if Xans != 0:
		print('No')
		sys.exit()
elif len(Xmove) == 1:
	if Xans != Xmove[0]:
		print('No')
		sys.exit()
else:
	Xsum = sum(Xmove)
	if (Xsum+Xans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Xans) > Xsum:
		print('No')
		sys.exit()
	else:
		Xpos = (Xsum+Xans)//2
		dp = [0]*(Xpos+1)
		print(Xpos)
		dp[0] = 1
		for x in Xmove:
			for i in range(Xpos,x-1,-1):
				dp[i] = dp[i-x]
			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()


if len(Ymove) == 0:
	if Yans != 0:
		print('No')
		sys.exit()
else:
	Ysum = sum(Ymove)
	if (Ysum+Yans)%2 == 1:
		print('No')
		sys.exit()
	elif abs(Yans) > Ysum:
		print('No')
		sys.exit()
	else:
		Ypos = (Ysum+Yans)//2
		dp = [0]*(Ypos+1)
		dp[0] = 1
		for y in Ymove:
			for i in range(Ypos,y-1,-1):
				dp[i] = dp[i-y]

			if dp[-1] == 1:
				break
		else:
			print('No')
			sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
s = [len(i) for i in input().split("T")]
x,y  = (abs(int(i)) for i in input().split())
xl,yl,flag = [],[],False
for i in range(len(s)):
	if i%2==0: xl.append(s[i])
	else: yl.append(s[i])
xs,ys = sum(xl),sum(yl)
a,b = [[0 for i in range(xs+1)] for i in range(len(xl)+1)],[[0 for i in range(ys+1)] for i in range(len(yl)+1)]
a[0][0],b[0][0] = 1,1
if xs>=x and (xs-x)%2==0 and ys>=y and (ys-y)%2==0: x2,y2,flag = (xs-x)//2,(ys-y)//2,True
else: print("No")
if flag:
	for i in range(len(xl)):
		for j in range(xs+1):
			if xl[i]<=j: a[i+1][j] = a[i][j-xl[i]] | a[i][j]
			else: a[i+1][j] = a[i][j]
	for i in range(len(yl)):
		for j in range(ys+1):
			if yl[i]<=j: b[i+1][j] = b[i][j-yl[i]] | b[i][j]
			else: b[i+1][j] = b[i][j]
	if a[-1][x2] and b[-1][y2]: print("Yes")
	else: print("No")