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 numpy as np

s = input() + "T"
x, y = map(int, input().split())
A = []
B = []
now = 0
di = 1
for i in s:
  if i=="T":
    if di:
      A.append(now)
    else:
      B.append(now)
    now = 0
    di ^= 1
  else:
    now += 1

def test(L, dist):
  dist = abs(dist)
  su = sum(L)
  l = len(L)
  if su < dist or (su-dist)%2:
    return False
  can = (su-dist)//2
  dp = np.zeros(can+1, dtype=bool)
  dp[0] = True
  for i in L:
    if i <= can:
      dp[i:] |= dp[:can+1-i]
  return dp[-1]

if test(A, x) and test(B, y):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

def main():
    s = input().split("T")
    x,y = map(int,input().split())
    l = len(s)
    dx,dy = [0],[0]
    nx,ny = [],[]
    for i in range(l):
        d = len(s[i])
        if i%2 == 0:
            nx = []
            for num in dx:
                nx.append(num+d)
                nx.append(num-d)
            dx = list(set(nx))
        else:
            ny = []
            for num in dy:
                ny.append(num+d)
                ny.append(num-d)
            dy = list(set(ny))

    if (x in dx and y in dy):
        print("Yes")
    else:
        print("No")
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

s = input().split('T')
dx = list(map(len, s[0::2]))
dy = list(map(len, s[1::2]))
lx = sum(dx) + 1
ly = sum(dy) + 1
x, y = map(int, input().split())

dp = [defaultdict(bool) for _ in range(len(dx))]
dp[0][dx[0]] = True
for i in range(1, len(dx)):
    for j in range(-lx, lx):
        dp[i][j] = dp[i - 1][j - dx[i]] or dp[i - 1][j + dx[i]]

x_ok = dp[len(dx) - 1][x]

if len(dy) > 0:
    dp = [defaultdict(bool) for _ in range(len(dy))]
    dp[0][dy[0]] = True
    dp[0][-dy[0]] = True
    for i in range(1, len(dy)):
        for j in range(-ly, ly):
            dp[i][j] = dp[i - 1][j - dy[i]] or dp[i - 1][j + dy[i]]
    y_ok = dp[len(dy) - 1][y]
else:
    y_ok = y == 0

print(x_ok, y_ok)
print('Yes' if x_ok and y_ok else 'No')

Submission status: Wrong Answer

Solution code:
def check(s,x_tag,y_tag):
    x = s.split('T')[::2]
    y = s.split('T')[1::2]
 
    dp_x = [[False]*16001 for _ in range(len(x)+1)]
    dp_y = [[False]*16001 for _ in range(len(y)+1)]
    dp_x[0][8000], dp_y[0][8000] = True, True
 
    for i,x_s in enumerate(x):
        for j,boolean in enumerate(dp_x[i]):
            if boolean:
                dp_x[i+1][j+len(x_s)] = True
                dp_x[i+1][j-len(x_s)] = True
    
    for i,y_s in enumerate(y):
        for j,boolean in enumerate(dp_y[i]):
            if boolean:
                dp_y[i+1][j+len(y_s)] = True
                dp_y[i+1][j-len(y_s)] = True
    
    print('Yes' if dp_x[len(x)][x_tag+8000] and dp_y[len(y)][y_tag+8000] else 'No')
    
s = input()
x, y = map(int, input().split())
check(s,x,y)

Submission status: Wrong Answer

Solution code:
def check(s,x_tag,y_tag):
    x = s.split('T')[::2]
    y = s.split('T')[1::2]
    while '' in x :
        x.remove('')
    while '' in y :
        y.remove('')
        
    dp_x = [[False]*16001 for _ in range(len(x)+1)]
    dp_y = [[False]*16001 for _ in range(len(y)+1)]
    dp_x[0][8000], dp_y[0][8000] = True, True
 
    for i,x_s in enumerate(x):
        for j,boolean in enumerate(dp_x[i]):
            if boolean:
                dp_x[i+1][j+len(x_s)] = True
                dp_x[i+1][j-len(x_s)] = True
    
    for i,y_s in enumerate(y):
        for j,boolean in enumerate(dp_y[i]):
            if boolean:
                dp_y[i+1][j+len(y_s)] = True
                dp_y[i+1][j-len(y_s)] = True
    
    print('Yes' if dp_x[len(x)][x_tag+8000] and dp_y[len(y)][y_tag+8000] else 'No')
    
s = input()
x, y = map(int, input().split())
check(s,x,y)

Submission status: Wrong Answer

Solution code:
def check(s,x_tag,y_tag):
    x = s.split('T')[::2]
    y = s.split('T')[1::2]
    while '' in x :
        x.remove('')
    while '' in y :
        y.remove('')
        
    dp_x = [[False]*16001 for _ in range(len(x)+1)]
    dp_y = [[False]*16001 for _ in range(len(y)+1)]
    dp_x[0][8000], dp_y[0][8000] = True, True

    for i,x_s in enumerate(x):
        for j,boolean in enumerate(dp_x[i]):
            if boolean:
                dp_x[i+1][j+len(x_s)] = True
    
    for i,y_s in enumerate(y):
        for j,boolean in enumerate(dp_y[i]):
            if boolean:
                dp_y[i+1][j+len(y_s)] = True
    
    print('Yes' if dp_x[len(x)][x_tag+8000] and dp_y[len(y)][y_tag+8000] else 'No')
    
s = input()
x, y = map(int, input().split())
check(s,x,y)

Submission status: Wrong Answer

Solution code:
s = input()
a = input()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
if cnt==0:
    x-=tmp

sumx=sum(lst[0])
sumy=sum(lst[1])
# print(x,sumx)
if sumx<x or x<-sumx:
    print("No")
    exit()
if sumy<y or y<-sumy:
    print("No")
    exit()
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1

for i in range(len(lst[0])):
    for j in range(sumx*2+1):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(sumy*2+1):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

# print(dpx)
# print(dpy)
if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
if cnt==0:
    x-=tmp
# print(x)
sumx=sum(lst[0])
sumy=sum(lst[1])
if sumx<x or x<-sumx:
    print("No")
    exit()
if sumy<y or y<-sumy:
    print("No")
    exit()
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1

for i in range(len(lst[0])):
    for j in range(sumx*2+1):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(sumy*2+1):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

# print(dpx)
# print(dpy)
if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)

sumx=sum(lst[0])
sumy=sum(lst[1])
if sumx<x or x<-sumx:
    print("No")
    exit()
if sumy<y or y<-sumy:
    print("No")
    exit()
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1

for i in range(len(lst[0])):
    for j in range(sumx*2+1):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(sumy*2+1):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

# print(dpx)
# print(dpy)
if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
# print(lst)
sumx=sum(lst[0])
sumy=sum(lst[1])
if (sumx<x and -sumx<x) or (x<-sumx and x<sumx):
    print("No")
    exit()
if (sumy<y and -sumy<y) or (y<-sumy and y<sumy):
    print("No")
    exit()
dpx=[[0]*(sumx*2+1) for i in range(len(lst[0])+1)]
dpy=[[0]*(sumy*2+1) for i in range(len(lst[1])+1)]
dpx[0][sumx]=1
dpy[0][sumy]=1
# print(len(lst[1]),len(dpy))
# print(dpy)

for i in range(len(lst[0])):
    for j in range(sumx*2+1):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(sumy*2+1):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][sumx+x]!=0 and dpy[len(lst[1])][sumy+y]!=0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

s=input()
x,y=map(int,input().split())
lst=[[],[]]
cnt=0
tmp=0
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    else:
        if cnt==0:
            x-=tmp
        else:
            if tmp!=0:
                lst[cnt%2].append(tmp)
        tmp=0
        cnt+=1
if tmp!=0:
    lst[cnt%2].append(tmp)
# print(lst)
dpx=[[0]*16001 for i in range(len(lst[0])+1)]
dpy=[[0]*16001 for i in range(len(lst[1])+1)]
dpx[0][8000]=1
dpy[0][8000]=1
# print(len(lst[1]),len(dpy))
# print(dpy)

for i in range(len(lst[0])):
    for j in range(16001):
        if dpx[i][j]!=0:
            dpx[i+1][j+lst[0][i]]+=1
            dpx[i+1][j-lst[0][i]]+=1

for i in range(len(lst[1])):
    for j in range(16001):
        if dpy[i][j]!=0:
            dpy[i+1][j+lst[1][i]]+=1
            dpy[i+1][j-lst[1][i]]+=1

if dpx[len(lst[0])][8000+x]!=0 and dpy[len(lst[1])][8000+y]!=0:
    print("Yes")
else:
    print("No")
# print(x,lst)

Submission status: Wrong Answer

Solution code:
def main():
    s = str(input())
    s = s+"T"
    ax,ay = map(int,input().split())
    now = 1
    count = 0
    border = []
    stripe = []
    for moji in s:
        if moji == "F":
            count += 1
        else:
            if now == 1:
                border.append(count)
            if now == -1:
                stripe.append(count)
            now *= -1
            count = 0

    ux = [0]
    nx = []
    uy = [0]
    ny = []
    for x in border:
        for num in ux:
            nx.append(num+x)
            nx.append(num-x)
        ux = list(set(nx))
        nx = []

    for y in stripe:
        for num in uy:
            ny.append(num+y)
            ny.append(num-y)
        uy = list(set(ny))
        ny = []

    if (ax in ux and ay in uy):
        print("Yes")
    else:
        print("No")
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    X,Y = map(int, input().split())
    
    S_F = S.split('T')
    move_x = list(map(len, S_F[::2]))
    move_y = list(map(len,S_F[1::2]))
    
    if sum(move_x) < abs(X) or sum(move_y) < abs(Y):
        print('No')
        return
    
    move_x_process = [mx for mx in move_x if mx > 0]
    move_y_process = [my for my in move_y if my > 0]
    X = abs(X); Y = abs(Y)
    len_move_x = len(move_x_process)
    sum_x = sum(move_x_process)
    len_move_y = len(move_y_process)
    sum_y = sum(move_y_process)
    dp_table = [[False for _ in range(sum_x+1)] for _ in range(len_move_x+1)]
    dp_table[0][0] = True
    
    for i in range(0,len_move_x):
        for j in range(0, sum_x+1):
            dp_table[i+1][j] = ret = dp_table[i][abs(j-move_x_process[i])]
    
    # print(dp_table)
    ret = dp_table[len_move_x][X]
    dp_table = [[False for _ in range(sum_y+1)] for _ in range(len_move_y+1)]
    dp_table[0][0] = True
    for i in range(0,len_move_y):
        for j in range(0, sum_y+1):
            # if j-move_x_process[i] >= 0:
            dp_table[i+1][j] = dp_table[i][abs(j-move_y_process[i])]
            
    
    ret = ret and dp_table[len_move_y][Y]
    print('Yes' if ret else 'No')
    
solve()

Submission status: Wrong Answer

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

k = 8000
def foo(fe,x):
    n = len(fe)
    d = [ [False]*(2*k+1) for i in range(n+1) ]
    d[0][k] = True
    for i in range(n):
        for j in range(-k,k+1):
            if d[i][j+k]:
                d[i+1][j+fe[i]+k] = True
                d[i+1][j-fe[i]+k] = True
    return d[n][x+k]

s = ins()
x,y = inm()
f = [ [], [] ]
strk = 0
turn = 0
n = len(s)
for i in range(n):
    if s[i]=='T':
        f[turn].append(strk)
        turn = 1 - turn
        strk = 0
    else:
        strk += 1
f[turn].append(strk)
if foo(f[0],x) and foo(f[1],y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]

if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    for p in longi:
      if x > 0:
        x -= p
      else:
        x += p
    if x == 0:
      lati.sort(reverse=True)
      for q in lati:
        if y > 0:
          y -= q
        else:
          y += q
      if y == 0:
        ans = "Yes"
print(ans)

Submission status: Wrong Answer

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


def check(arr, x):
    dp = [False] * (2*8000+1)
    dp[8000+0] = True
    for a in arr:
        s = abs(a)
        t = 2*8000-abs(a)
        if s > t:
            s, t = t, s
        for i in range(s, t+1):
            dp[i] = dp[i-a] | dp[i+a]
    return dp[8000+x]


s = input().rstrip() + 'T'
x, y = map(int, input().split())
X = []
Y = []
xy = 0
f_count = 0
for c in s:
    if c == 'T':
        if xy == 0:
            X.append(f_count)
        else:
            Y.append(f_count)
        f_count = 0
        xy = 1 - xy
    else:
        f_count += 1
x -= X[0]
X.pop(0)
if check(X, x) and check(Y, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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


def check(arr, x):
    if x < 0:
        x *= -1
    s = sum(arr)
    if (s+x) % 2 == 1:
        return False
    target = (s+x) // 2
    dp = [False] * (target+1)
    dp[0] = True
    for a in arr:
        for i in range(a, target+1):
            dp[i] |= dp[i-a]
    return dp[-1]


s = input().rstrip() + 'T'
x, y = map(int, input().split())
X = []
Y = []
xy = 0
f_count = 0
for c in s:
    if c == 'T':
        if xy == 0:
            X.append(f_count)
        else:
            Y.append(f_count)
        f_count = 0
        xy = 1 - xy
    else:
        f_count += 1
x -= X[0]
X.pop(0)
if check(X, x) and check(Y, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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


def check(arr, x):
    if x < 0:
        x *= -1
    s = sum(arr)
    if (s+x) % 2 == 1:
        return False
    target = (s+x) // 2
    dp = [False] * (target+1)
    dp[0] = True
    for a in arr:
        for i in range(a, target+1):
            dp[i] = dp[i-a]
    return dp[-1]


s = input().rstrip() + 'T'
x, y = map(int, input().split())
X = []
Y = []
xy = 0
f_count = 0
for c in s:
    if c == 'T':
        if xy == 0:
            X.append(f_count)
        else:
            Y.append(f_count)
        f_count = 0
        xy = 1 - xy
    else:
        f_count += 1
x -= X[0]
X.pop(0)
if check(X, x) and check(Y, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    vert_DP = [False] * 8001
    side_DP = [False] * 8001
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = [0] * len(order_F)
    side_sum = [0] * len(order_F)
    distance = [len(order_F[i]) for i, value in enumerate(order_F)]
    x -= distance[0]
    for i, value in enumerate(distance):
        if i == 0:
            continue
        if i % 2 == 0:
            side_sum[(i-1)//2] += value
            side_sum[(i-1)//2 + 1] = side_sum[(i-1)//2]
            for j in reversed(range(8001)):
                if side_DP[j]:
                    side_DP[j + value] = True
        else:
            vert_sum[(i-1)//2] += value
            vert_sum[(i-1)//2 + 1] = vert_sum[(i-1)//2]
            for j in reversed(range(8001)):
                if vert_DP[j]:
                    vert_DP[j + value] = True
    if side_sum[len(order_F)//2] < x or vert_sum[len(order_F)//2] < y:
        print("No")
    elif (side_sum[len(order_F)//2] - x) % 2 == 1 or (vert_sum[len(order_F)//2] - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum[len(order_F)//2] - x)//2] and vert_DP[(vert_sum[len(order_F)//2] - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    vert_DP = [False] * 8001
    side_DP = [False] * 8001
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    distance = [len(order_F[i]) for i in range(len(order_F))]
    d_len = max(distance)
    x -= len(order_F[0])
    for i in range(1, len(order_F)):
        if i % 2 == 0:
            side_sum += distance[i]
            for j in reversed(range(d_len + 1 - distance[i])):
                if side_DP[j]:
                    side_DP[j + distance[i]] = True
        else:
            vert_sum += distance[i]
            for j in reversed(range(d_len + 1 - distance[i])):
                if vert_DP[j]:
                    vert_DP[j + distance[i]] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    distance = [len(order_F[i]) for i in range(len(order_F))]
    dp_len = max(distance)
    vert_DP = [False] * (dp_len + 1)
    side_DP = [False] * (dp_len + 1)
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    x -= distance[0]
    for i in range(1, len(order_F)):
        if i % 2 == 0:
            side_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if side_DP[j]:
                    side_DP[j + distance[i]] = True
        else:
            vert_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if vert_DP[j]:
                    vert_DP[j + distance[i]] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if (side_sum - x)//2 <= dp_len and (vert_sum - y)//2 <= dp_len and side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    distance = [len(order_F[i]) for i in range(len(order_F))]
    dp_len = max(distance)
    vert_DP = [False] * (dp_len + 1)
    side_DP = [False] * (dp_len + 1)
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    x -= distance[0]
    for i in range(1, len(order_F)):
        if i % 2 == 0:
            side_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if side_DP[j]:
                    side_DP[j + distance[i]] = True
        else:
            vert_sum += distance[i]
            for j in reversed(range(dp_len + 1 - distance[i])):
                if vert_DP[j]:
                    vert_DP[j + distance[i]] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if dp_len * 2 >= side_sum - x and dp_len * 2 >= vert_sum - y and side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    vert_DP = [False] * 8001
    side_DP = [False] * 8001
    vert_DP[0] = True
    side_DP[0] = True
    vert_sum = 0
    side_sum = 0
    for i in range(len(order_F)):
        distance = len(order_F[i])
        if i % 2 == 0:
            side_sum += distance
            for j in reversed(range(8001 - distance)):
                if side_DP[j]:
                    side_DP[j + distance] = True
        else:
            vert_sum += distance
            for j in reversed(range(8001 - distance)):
                if vert_DP[j]:
                    vert_DP[j + distance] = True
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum - x)//2] and vert_DP[(vert_sum - y)//2]:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    order_F = []
    order_F = input().rstrip().split('T')
    x, y = map(int, input().split())
    vert_DP =[0] * 8001
    side_DP =[0] * 8001
    vert_DP[0] = 1
    side_DP[0] = 1
    vert_sum = 0
    side_sum = 0
    for i in range(len(order_F)):
        distance = len(order_F[i])
        if i % 2 == 0:
            side_sum += distance
            for j in reversed(range(8001 - distance)):
                if side_DP[j] == 1:
                    side_DP[j + distance] = 1
        else:
            vert_sum += distance
            for j in reversed(range(8001 - distance)):
                if vert_DP[j] == 1:
                    vert_DP[j + distance] = 1
    if side_sum < x or vert_sum < y:
        print("No")
    elif (side_sum - x) % 2 == 1 or (vert_sum - y) % 2 == 1:
        print("No")
    else:
        if side_DP[(side_sum - x)//2] == 1 and vert_DP[(vert_sum - y)//2] == 1:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
x=abs(x)
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0

v=sum(x1)
w=sum(y1)
if v<x or w<y:
    print('No')
    exit()

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]
dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)
dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1

if dpy[-1][y]==1 and dpx[-1][x]==1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
xy = list(map(int, input().split()))

right = 0
updown = []
rightleft = []

direction = 0
for i in range(n):
    if s[i]=='F':
        if direction == 0:
            right+=1
        elif direction == 1:
            updown[-1]+=1
        else:
            rightleft[-1]+=1
    else:
        if direction == 0 or direction == 2:
            direction = 1
            updown.append(0)
        else:
            direction = 2
            rightleft.append(0)

updown = [x for x in updown if x!=0]
rightleft = [x for x in rightleft if x!=0]
print(updown)
print(rightleft)

# 最初はx方向にしか進めないので補正
xy[0]-=right

# updownでyに行けるか？rightleftでxに行けるかを考えれば良い
dpy = [set() for i in range(len(updown)+1)]
dpy[0].add(0)
for i in range(len(updown)):
    for y in dpy[i]:
        dpy[i+1].add(y+updown[i])
        dpy[i+1].add(y-updown[i])

dpx = [set() for i in range(len(rightleft)+1)]
dpx[0].add(0)
for i in range(len(rightleft)):
    for x in dpx[i]:
        dpx[i+1].add(x+rightleft[i])
        dpx[i+1].add(x-rightleft[i])

if xy[1] in dpy[-1] and xy[0] in dpx[-1]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
xy = list(map(int, input().split()))


right = 0
updown = []
rightleft = []

direction = 0
for i in range(n):
    if s[i]=='F':
        if direction == 0:
            right+=1
        elif direction == 1:
            updown[-1]+=1
        else:
            rightleft[-1]+=1
    else:
        if direction == 0 or direction == 2:
            direction = 1
            updown.append(0)
        else:
            direction = 2
            rightleft.append(0)

updown = [x for x in updown if x!=0]
rightleft = [x for x in rightleft if x!=0]

# 最初はx方向にしか進めないので補正
xy[0]-=right

# updownでyに行けるか？rightleftでxに行けるかを考えれば良い
dpy = [set() for i in range(len(updown)+1)]
dpy[0].add(0)
for i in range(len(updown)):
    for y in dpy[i]:
        dpy[i+1].add(y+updown[i])
        dpy[i-1].add(y-updown[i])

dpx = [set() for i in range(len(rightleft)+1)]
dpx[0].add(0)
for i in range(len(rightleft)):
    for x in dpx[i]:
        dpx[i+1].add(x+rightleft[i])
        dpx[i-1].add(x-rightleft[i])

if xy[1] in dpy[-1] and xy[0] in dpx[-1]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(2*cntx+1):
            if j-AX[i-1]<=cntx:
                dpx[i][j] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j] = max(dpx[i][j],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(2*cnty+1):
            if j-AY[i-1]<=cnty:
                dpy[i][j] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j] = max(dpy[i][j],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
cntx = 0
for a in C:
    if a>0 and a%2==0:
        cntx += C[a]
cnty = 0
for a in C:
    if a%2==1:
        cnty += C[a]
AX = []
for i in range(-cntx,cntx+1,2):
    AX.append(C[0]+i)
AY = []
for i in range(-cnty,cnty+1,2):
    AY.append(i)
if x in AX and y in AY:
    print("Yes")
else:
    print("No")