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:
import sys
import itertools
from itertools import accumulate
def main():
    import itertools
    def eratosthenes_sieve(n):
        table = [0] * (n + 1)
        prime_list = []
        for i in range(2, n + 1):
            if table[i] == 0:
                prime_list.append(i)
                for j in range(i + i, n + 1, i):
                    table[j] = 1
        return prime_list
        def inputs():return (int(x) for x in input().split())
    input = sys.stdin.readline
    def inputs():
        return [int(x) for x in input().split()]
    S = list(input())
    x,y=inputs()
    cnt=0
    s =[]
    if S[0]=="T":
        s.append(0)
        cnt+=1
    else:
        cnt+=1
    for i in range(len(S)-2):
        if S[i]==S[i+1]:
            cnt+=1
        else:
            s.append(cnt)
            cnt=1
    s.append(cnt)
    #print(s)
    flag=1
    x1 = []
    y1 = []
    ansx=s[0]
    ansy=0
    flagx=0
    flagy= 0
    for i in range(len(s)):
        if i%2==0:
            if flag==1:
              if i!=0:
                x1.append(s[i])
            else:
                y1.append(s[i])
        else:
            flag=(flag+s[i])%2
    dpx=[[-1]*(16001) for i in range(len(x1)+1)]
    dpx[0][8000+s[0]]=1
    dpy =[[-1]*(16001) for i in range(len(y1)+1)]
    dpy[0][8000]=1
    for i in range(len(x1)):
        for j in range(16000):
            if j+x1[i]<=16000 and dpx[i][j]!=-1:
                dpx[i+1][j+x1[i]]=1
            if j-x1[i]>=0 and dpx[i][j]!=-1:
                dpx[i+1][j-x1[i]]=1      
    for i in range(len(y1)):
        for j in range(16000):
            if j+y1[i]<=16000 and dpy[i][j]!=-1:
                dpy[i+1][j+y1[i]]=1
            elif j-y1[i]>=0 and dpy[i][j]!=-1:
                dpy[i+1][j-y1[i]]=1
    
    if dpx[len(x1)][8000+x]==1 and dpy[len(y1)][8000+y]==1:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
from itertools import accumulate
def main():
    import itertools
    def eratosthenes_sieve(n):
        table = [0] * (n + 1)
        prime_list = []
        for i in range(2, n + 1):
            if table[i] == 0:
                prime_list.append(i)
                for j in range(i + i, n + 1, i):
                    table[j] = 1
        return prime_list
        def inputs():return (int(x) for x in input().split())
    input = sys.stdin.readline
    def inputs():
        return [int(x) for x in input().split()]
    S = list(input())
    x,y=inputs()
    cnt=0
    s =[]
    if S[0]=="T":
        s.append(0)
        cnt+=1
    else:
        cnt+=1
    for i in range(len(S)-2):
        if S[i]==S[i+1]:
            cnt+=1
        else:
            s.append(cnt)
            cnt=1
    s.append(cnt)
    #print(s)
    flag=1
    x1 = []
    y1 = []
    ansx=s[0]
    ansy=0
    flagx=0
    flagy= 0
    for i in range(len(s)):
        if i%2==0:
            if flag==1:
              if i!=0:
                x1.append(s[i])
            else:
                y1.append(s[i])
        else:
            flag=(flag+s[i])%2
    dpx=[[-1]*(16001) for i in range(len(x1)+1)]
    dpx[0][8000+s[0]]=1
    dpy =[[0]*(16001) for i in range(len(y1)+1)]
    dpy[0][8000]=1
    for i in range(len(x1)):
        for j in range(16000):
            if j+x1[i]<=16000 and dpx[i][j]!=-1:
                dpx[i+1][j+x1[i]]=1
            if j-x1[i]>=0 and dpx[i][j]!=-1:
                dpx[i+1][j-x1[i]]=1      
    for i in range(len(y1)):
        for j in range(16000):
            if j+y1[i]<=16000 and dpy[i][j]!=-1:
                dpy[i+1][j+y1[i]]=1
            elif j-y1[i]>=0 and dpy[i][j]!=-1:
                dpy[i+1][j-y1[i]]=1
    
    if dpx[len(x1)][8000+x]==1 and dpy[len(y1)][8000+y]==1:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
from itertools import accumulate
def main():
    import itertools
    def eratosthenes_sieve(n):
        table = [0] * (n + 1)
        prime_list = []
        for i in range(2, n + 1):
            if table[i] == 0:
                prime_list.append(i)
                for j in range(i + i, n + 1, i):
                    table[j] = 1
        return prime_list
        def inputs():return (int(x) for x in input().split())
    input = sys.stdin.readline
    def inputs():
        return [int(x) for x in input().split()]
    S = list(input())
    x,y=inputs()
    cnt=0
    s =[]
    if S[0]=="T":
        s.append(0)
        cnt+=1
    else:
        cnt+=1
    for i in range(len(S)-2):
        if S[i]==S[i+1]:
            cnt+=1
        else:
            s.append(cnt)
            cnt=1
    s.append(cnt)
    #print(s)
    flag=1
    x1 = []
    y1 = []
    ansx=s[0]
    ansy=0
    flagx=0
    flagy= 0
    for i in range(len(s)):
        if i%2==0:
            if flag==1 and i!=0:
                x1.append(s[i])
            else:
                y1.append(s[i])
        else:
            flag=(flag+s[i])%2
    dpx=[[-1]*(16001) for i in range(len(x1)+1)]
    dpx[0][8000+s[0]]=1
    dpy =[[0]*(16001) for i in range(len(y1)+1)]
    dpy[0][8000]=1
    for i in range(len(x1)):
        for j in range(16000):
            if j+x1[i]<=16000 and dpx[i][j]!=-1:
                dpx[i+1][j+x1[i]]=1
            if j-x1[i]>=0 and dpx[i][j]!=-1:
                dpx[i+1][j-x1[i]]=1      
    for i in range(len(y1)):
        for j in range(16000):
            if j+y1[i]<=16000 and dpy[i][j]!=-1:
                dpy[i+1][j+y1[i]]=1
            elif j-y1[i]>=0 and dpy[i][j]!=-1:
                dpy[i+1][j-y1[i]]=1
    
    if dpx[len(x1)][8000+x]==1 and dpy[len(y1)][8000+y]==1:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
x, y = LI()
components = [len(i) for i in s.split('T')]
initial_x = components[0]
components = components[1:]
y_component = [j for j in components[::2] if j]
x_component = [j for j in components[1::2] if j]
x_len = len(x_component)
y_len = len(y_component)
x_D = [defaultdict(int) for k in range(x_len + 1)]
y_D = [defaultdict(int) for k in range(y_len + 1)]


x_D[0][initial_x] = 1
for i in range(x_len):
    for j in range(-sum(x_component), sum(x_component)+1):
        if x_D[i][j]:
            x_D[i + 1][j + x_component[i]] = 1
            x_D[i + 1][j - x_component[i]] = 1


y_D[0][0] = 1
for i in range(y_len):
    for j in range(-sum(y_component), sum(y_component)+1):
        if y_D[i][j]:
            y_D[i + 1][j + y_component[i]] = 1
            y_D[i + 1][j - y_component[i]] = 1



if x_D[x_len][x] and y_D[y_len][y]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import bisect
S = input()
x, y = [int(x) for x in input().split()]
#%%
def dfs(nums, goal):
    if(goal - nums[0]<0):
        return False
    elif(goal == nums[0]):
        return True
    stack = [(bisect.bisect_left(nums, goal - nums[0]), goal - nums[0])]
    while(stack):
        n, now_goal = stack.pop()
        nxt_stack = []
        for ind,i in enumerate(nums[n:]):
            if(now_goal == i):
                return True
            nxt_stack.append((bisect.bisect_left(nums, now_goal - i), now_goal - i))
        stack = nxt_stack+stack
    return False

#%%
list_distances = [[] for _ in range(2)] # 0:horizontal 1:vertical
now_direction = 0
list_distances[0].append(0)
for s in S:
    if(s=='T'):
        # change direction
        now_direction = 1-now_direction
        list_distances[now_direction].append(0)
    else:
        list_distances[now_direction][-1] += 1
list_distances[0].append(abs(x))
list_distances[1].append(abs(y))
list_distances[0].sort(reverse=True)
list_distances[1].sort(reverse=True)
sum_h = sum(list_distances[0])
sum_w = sum(list_distances[1])
if((sum_h%2 == sum_w%2 == 0) and dfs(list_distances[0], sum_h//2) and dfs(list_distances[1], sum_w//2)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
S = input()
x, y = [int(x) for x in input().split()]
#%%
def dfs(nums, goal):
    stack = [(0,0)]
    while(stack):
        n, now_sum = stack.pop()
        nxt_stack = []
        for ind,i in enumerate(nums[n:]):
            if(i>goal):
                return False
            if(now_sum+i==goal):
                return True
            if(now_sum+i>goal):
                continue
            nxt_stack.append((n+ind+1, now_sum+i))
        stack = nxt_stack+stack
    return False

#%%
list_distances = [[] for _ in range(2)] # 0:horizontal 1:vertical
now_direction = 0
list_distances[0].append(0)
for s in S:
    if(s=='T'):
        # change direction
        now_direction = 1-now_direction
        list_distances[now_direction].append(0)
    else:
        list_distances[now_direction][-1] += 1
list_distances[0].append(abs(x))
list_distances[1].append(abs(y))
list_distances[0].sort(reverse=True)
list_distances[1].sort(reverse=True)
sum_h = sum(list_distances[0])
sum_w = sum(list_distances[1])

if((sum_h%2 == sum_w%2 == 0) and dfs(list_distances[0], sum_h//2) and dfs(list_distances[1], sum_w//2)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
S = input()
x, y = [int(x) for x in input().split()]
#%%
def dfs(nums, goal):
    stack = [(0,0)]
    while(stack):
        n, now_sum = stack.pop()
        nxt_stack = []
        for ind,i in enumerate(nums[n:]):
            if(now_sum+i==goal):
                return True
            if(now_sum+i>goal):
                continue
            nxt_stack.append((n+ind+1, now_sum+i))
        stack = nxt_stack+stack
    return False

#%%
list_distances = [[] for _ in range(2)] # 0:horizontal 1:vertical
now_direction = 0
list_distances[0].append(0)
for s in S:
    if(s=='T'):
        # change direction
        now_direction = 1-now_direction
        list_distances[now_direction].append(0)
    else:
        list_distances[now_direction][-1] += 1
list_distances[0].append(abs(x))
list_distances[1].append(abs(y))
list_distances[0].sort(reverse=True)
list_distances[1].sort(reverse=True)
sum_h = sum(list_distances[0])
sum_w = sum(list_distances[1])

if((sum_h%2 == sum_w%2 == 0) and dfs(list_distances[0], sum_h//2) and dfs(list_distances[1], sum_w//2)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
S = input()
listS = list(S)
X, Y = map(int, input().split())
muki = "R"

# そもそもFが足らない
if X + Y > listS.count("F"):
    print("No")
    quit()

# そもそもTが足りない
if X > 0 and Y > 0:
    if listS.count("T") < 2:
        print("No")
        quit()

nx = 0
ny = 0

for s in listS:
    # print(muki, nx, ny)
    if s == "F":
        if muki == "U":
            ny += 1
        elif muki == "D":
            ny -= 1
        elif muki == "R":
            nx += 1
        elif muki == "L":
            nx -= 1
    else:
        if muki == "U":
            if nx < X:
                muki = "R"
            else:
                muki = "L"
        elif muki == "D":
            if nx < X:
                muki = "R"
            else:
                muki = "L"
        elif muki == "R":
            if ny < Y:
                muki = "U"
            else:
                muki = "D"
        elif muki == "L":
            if ny < Y:
                muki = "U"
            else:
                muki = "D"

if nx == X and ny == Y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC82 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
x,y = LI()
lst = []
tmp = 0
for i in range(n):
    if s[i] == 'T':
        lst.append(tmp)
        tmp = 0
    else:
        tmp += 1
if s[-1] != 'T':
    lst.append(tmp)
m = len(lst)
dpx = defaultdict(int)
dpy = defaultdict(int)
dpx[0] = True
dpy[0] = True
for i in range(m):
    if i % 2:
        tmp = defaultdict(int)
        for k in dpy.keys():
            tmp[k + lst[i]] = True
            tmp[k - lst[i]] = True
        dpy = tmp
    else:
        tmp = defaultdict(int)
        for k in dpx.keys():
            tmp[k + lst[i]] = True
            tmp[k - lst[i]] = True
        dpx = tmp
if dpx[x] and dpy[y]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
x, y = LI()
x -= s.index('T') if 'T' in s else len(s)
s = s.lstrip('F')[1:]
components = [len(i) for i in s.split('T')]
y_component = [j for j in components[::2] if j]
x_component = [j for j in components[1::2] if j]
x_D = defaultdict(int)
y_D = defaultdict(int)
x_len = len(x_component)
y_len = len(y_component)


x_D[0] = 1
for i in range(x_len):
    for j in range(-sum(x_component), sum(x_component)+1):
        x_D[j + x_component[i]] = x_D[j] | x_D[j + x_component[i]]
        x_D[j - x_component[i]] = x_D[j] | x_D[j - x_component[i]]


y_D[0] = 1
for i in range(y_len):
    for j in range(-sum(y_component), sum(y_component)+1):
        y_D[j + y_component[i]] = y_D[j] | y_D[j + y_component[i]]
        y_D[j - y_component[i]] = y_D[j] | y_D[j - y_component[i]]


if y_D[y] and x_D[x]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
x, y = LI()
x -= s.index('T') if 'T' in s else 0
s = s.lstrip('F')[1:]
components = [len(i) for i in s.split('T')]
y_component = [j for j in components[::2] if j]
x_component = [j for j in components[1::2] if j]
x_D = defaultdict(int)
y_D = defaultdict(int)
x_len = len(x_component)
y_len = len(y_component)


x_D[0] = 1
for i in range(x_len):
    for j in range(-sum(x_component), sum(x_component)+1):
        x_D[j + x_component[i]] = x_D[j] | x_D[j + x_component[i]]
        x_D[j - x_component[i]] = x_D[j] | x_D[j - x_component[i]]


y_D[0] = 1
for i in range(y_len):
    for j in range(-sum(y_component), sum(y_component)+1):
        y_D[j + y_component[i]] = y_D[j] | y_D[j + y_component[i]]
        y_D[j - y_component[i]] = y_D[j] | y_D[j - y_component[i]]


if y_D[y] and x_D[x]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    S = list(input())
    X, Y = map(int, input().split())

    Xs = []
    Ys = []
    line = True
    first = True
    x0, y0 = 0, 0
    a = 0
    for s in S:
        if s == 'F':
            a += 1
        else:
            if first:
                if a > 0:
                    x0 = a
                a = 0
                first = False
                line = False
                continue
            if a > 0:
                if line:
                    Xs.append(a)
                else:
                    Ys.append(a)
                a = 0
            if line:
                line = False
            else:
                line = True
    if a > 0:
        if line:
            Xs.append(a)
        else:
            Ys.append(a)

    Lx = sum(Xs)+x0
    dpx = [[False for _ in range(2*Lx+1)] for _ in range(len(Xs)+1)]
    dpx[0][x0+Lx] = True

    for i, x in enumerate(Xs):
        for j in range(2*Lx+1):
            if j+x <= 2*Lx:
                dpx[i+1][j+x] = dpx[i][j] or dpx[i+1][j+x]
            if j-x >= 0:
                dpx[i+1][j-x] = dpx[i][j] or dpx[i+1][j-x]

    Ly = sum(Ys)+y0
    dpy = [[False for _ in range(2*Ly+1)] for _ in range(len(Ys)+1)]
    dpy[0][y0+Ly] = True

    for i, y in enumerate(Ys):
        for j in range(2*Ly+1):
            if j+y <= 2*Ly:
                dpy[i+1][j+y] = dpy[i][j] or dpy[i+1][j+y]
            if j-y >= 0:
                dpy[i+1][j-y] = dpy[i][j] or dpy[i+1][j-y]
    print(Lx, Ly)
    if (not -Lx <= X <= Lx) or (not -Ly <= Y <= Ly): 
        print('No')
    elif dpx[-1][X+Lx] and dpy[-1][Y+Ly]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
line = True
first = True
x0, y0 = 0, 0
a = 0
for s in S:
    if s == 'F':
        a += 1
    else:
        if first:
            if a > 0:
                x0 = a
            a = 0
            first = False
            line = False
            continue
        if a > 0:
            if line:
                Xs.append(a)
            else:
                Ys.append(a)
            a = 0
        if line:
            line = False
        else:
            line = True
if a > 0:
    if line:
        Xs.append(a)
    else:
        Ys.append(a)

L = len(S)

dpx = [[False for _ in range(2*L+1)] for _ in range(len(Xs)+1)]
dpx[0][x0+L] = True

for i, x in enumerate(Xs):
    for j in range(2*L+1):
        if j+x <= 2*L:
            dpx[i+1][j+x] = dpx[i][j] or dpx[i+1][j+x]
        if j-x >= 0:
            dpx[i+1][j-x] = dpx[i][j] or dpx[i+1][j-x]

dpy = [[False for _ in range(2*L+1)] for _ in range(len(Ys)+1)]
dpy[0][y0+L] = True

for i, y in enumerate(Ys):
    for j in range(2*L+1):
        if j+y <= 2*L:
            dpy[i+1][j+y] = dpy[i][j] or dpy[i+1][j+y]
        if j-y >= 0:
            dpy[i+1][j-y] = dpy[i][j] or dpy[i+1][j-y]

if dpx[-1][X+L] and dpy[-1][Y+L]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
S = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
line = True
first = True
x0, y0 = 0, 0
a = 0
for s in S:
    if s == 'F':
        a += 1
    else:
        if first:
            if a > 0:
                x0 = a
            a = 0
            first = False
            line = False
            continue
        if a > 0:
            if line:
                Xs.append(a)
            else:
                Ys.append(a)
            a = 0
        if line:
            line = False
        else:
            line = True
if a > 0:
    if line:
        Xs.append(a)
    else:
        Ys.append(a)

L = len(S)

dpx = []
for _ in range(len(Xs)+1):
    dic = {}
    for i in range(-L, L+1):
        dic[i] = False
    dpx.append(dic)

dpx[0][x0] = True
for i, x in enumerate(Xs):
    for j in range(-L, L+1):
        if j+x <= L:
            dpx[i+1][j+x] = dpx[i][j] or dpx[i+1][j+x]
        if j-x >= -L:
            dpx[i+1][j-x] = dpx[i][j] or dpx[i+1][j-x]

dpy = []
for _ in range(len(Ys)+1):
    dic = {}
    for i in range(-L, L+1):
        dic[i] = False
    dpy.append(dic)

dpy[0][y0] = True
for i, y in enumerate(Ys):
    for j in range(-L, L+1):
        if j+y <= L:
            dpy[i+1][j+y] = dpy[i][j] or dpy[i+1][j+y]
        if j-y >= -L:
            dpy[i+1][j-y] = dpy[i][j] or dpy[i+1][j-y]

if dpx[-1][X] and dpy[-1][Y]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Submission status: Wrong Answer

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)

mid = 8005
ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Submission status: Wrong Answer

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

X = []
Y = []
flag = 0
tmp = 0
for i in s:
    if i == "T":
        if flag == 0:
            X.append(tmp)
            flag = 1
            tmp = 0
        else:
            Y.append(tmp)
            flag = 0
            tmp = 0
    else:
        tmp += 1
if tmp != 0:
    if flag == 0:
        X.append(tmp)
    else:
        Y.append(tmp)
if s[0] !="T":
    tmpX = X[0]
    del X[0]
else:
    tmpX = 0

X = sorted(X)
Y = sorted(Y)

tmpY = 0
flag = 0
for i in X:
    if tmpX <= x:
        tmpX += i
    else:
        tmpX -= i
for j in Y:
    if tmpY <= y:
        tmpY += y
    else:
        tmpY -= y
if tmpX**2==x**2 and tmpY**2==y**2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]


state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True
    
can_reachx[wayx[0]] = True
can_reachy[pad] = True

for i in range(1,len(wayx)):
    w = wayx[i]
    b = []
    for j in range(len(can_reachx)):
        if can_reachx[j]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachx[j] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachy[i] = False
    for t in b:
        can_reachy[t] = True

if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachx[i] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            can_reachy[i] = False
    for t in b:
        can_reachy[t] = True

if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
pad = 15000
can_reachx = [False for i in range(pad*2+1)]
can_reachy = [False for i in range(pad*2+1)]
can_reachx[pad] = True
can_reachy[pad] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w!=0:
                can_reachx[i] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= pad*2:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w != 0:
                can_reachy[i] = False
    for t in b:
        can_reachy[t] = True

if can_reachx[x+pad] and can_reachy[y+pad]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
wayx = []
wayy = []
can_reachx = [False for i in range(10000*2+1)]
can_reachy = [False for i in range(10000*2+1)]
can_reachx[10000] = True
can_reachy[10000] = True

state = True
seq = 0
for c in s:
    if c == "T":
        if state:
            wayx.append(seq)
            seq = 0
            state = False
        else:
            wayy.append(seq)
            seq = 0
            state = True
    else:
        seq += 1


if state:
    wayx.append(seq)
    seq = 0
    state = False
else:
    wayy.append(seq)
    seq = 0
    state = True

for w in wayx:
    b = []
    for i in range(len(can_reachx)):
        if can_reachx[i]:
            if i+w <= 20000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w!=0:
                can_reachx[i] = False
    for t in b:
        can_reachx[t] = True

for w in wayy:
    b = []
    for i in range(len(can_reachy)):
        if can_reachy[i]:
            if i+w <= 20000:
                b.append(i+w)
            if i-w >= 0:
                b.append(i-w)
            if w != 0:
                can_reachy[i] = False
    for t in b:
        can_reachy[t] = True

if can_reachx[x+10000] and can_reachy[y+10000]:
    print("Yes")
else:
    print("No")