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:
sl = list(input())
x,y = map(int,input().split())
lrl = [[],[]]
mode = 0
stack = 0
flag = True
first_t = 0
for s in sl:
    if s == "F":
        stack += 1
    else:
        if flag:
            first_t = stack
            flag = False
        elif stack > 0:
            lrl[mode%2].append(stack)
        mode += 1
        stack = 0
else:
    if stack > 0:
        lrl[mode%2].append(stack)

x = abs(x - first_t)
y = abs(y)
from collections import defaultdict
l = defaultdict(int)
r = defaultdict(int)
l[0] = 1
r[0] = 1
ol = x + sum(lrl[0])
for a in lrl[0]:
    kouho = []
    for ll in l:
        if ll + 2 * a <= ol:
            kouho.append(ll+2*a)
    for i in kouho:
        l[i] = 1

orr = y + sum(lrl[1])
for a in lrl[1]:
    kouho = []
    for rr in r:
        if rr + 2 * a <= orr:
            kouho.append(rr+2*a)
    for i in kouho:
        r[i] = 1


if l[ol] == 1 and r[orr] == 1:
    print("Yes")
    import sys
    sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
sl = list(input())
x,y = map(int,input().split())
x = abs(x)
y = abs(y)
lrl = [[],[]]
mode = 0
stack = 0
for s in sl:
    if s == "F":
        stack += 1
    else:
        if stack > 0:
            lrl[mode%2].append(stack)
        mode += 1
        stack = 0
else:
    if stack > 0:
        lrl[mode%2].append(stack)

from collections import defaultdict
l = defaultdict(int)
r = defaultdict(int)
l[0] = 1
r[0] = 1
ol = x + sum(lrl[0])
for a in lrl[0]:
    kouho = []
    for ll in l:
        if ll + 2 * a <= ol:
            kouho.append(ll+2*a)
    for i in kouho:
        l[i] = 1

orr = y + sum(lrl[1])
for a in lrl[1]:
    kouho = []
    for rr in r:
        if rr + 2 * a <= orr:
            kouho.append(rr+2*a)
    for i in kouho:
        r[i] = 1


if l[ol] == 1 and r[orr] == 1:
    print("Yes")
    import sys
    sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(s: str, x: int, y: int):
    s = "FFFFFFFFFFFF"
    x = 12
    y = 0 
    LENS = len(s)
    s_list = list(map(len,s.split("T")))
    x_s_list = s_list[0::2]
    y_s_list = s_list[1::2]

    x_dp = [[False]*(2*LENS+1) for _ in range(len(x_s_list))]
    ## answer = x_dp[-1][x+LENS]
    for index,count in enumerate(x_s_list):
        ## 最初は
        if index == 0:
            x_dp[index][count+LENS] = True
            continue
        
        for j in range(2*LENS+1):
            if j-count >= 0 and j+count< 2*LENS+1:
                x_dp[index][j] = x_dp[index-1][j-count] or x_dp[index-1][j+count] 
            elif j-count >= 0:
                x_dp[index][j] = x_dp[index-1][j-count]
            elif j+count< 2*LENS+1:
                x_dp[index][j] = x_dp[index-1][j+count]


    y_dp = [[False]*(2*LENS+1) for _ in range(len(y_s_list))]
    for index,count in enumerate(y_s_list):
        ## 最初は
        if index == 0:
            y_dp[index][count+LENS] = True
            y_dp[index][-count+LENS] = True            
            continue
        
        for j in range(2*LENS+1):
            if j-count >= 0 and j+count< 2*LENS+1:
                y_dp[index][j] = y_dp[index-1][j-count] or y_dp[index-1][j+count] 
            elif j-count >= 0:
                y_dp[index][j] = y_dp[index-1][j-count]
            elif j+count< 2*LENS+1:
                y_dp[index][j] = y_dp[index-1][j+count]
    
    if not y_dp:
        if y != 0:
            print(NO)
        else:
            if x_dp[-1][x+LENS]:
                print(YES)
            else:
                print(NO)
        return

    if not x_dp:
        if x != 0:
            print(NO)
        else:
            if y_dp[-1][y+LENS]:
                print(YES)
            else:
                print(NO)
        return

    if x_dp[-1][x+LENS] and y_dp[-1][y+LENS]:
        print(YES)
    else:
        print(NO)

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
x -= F[0]
Fx = F[2::2]
Fy = F[1::2]

xt2 = sum(Fx)-x
yt2 = sum(Fy)-y
if xt2%2==1 or yt2%2==1 or xt2<0 or yt2<0:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2
print(xt, yt)

dpx = [False]*(xt+1)
dpx[0] = True
for f in Fx:
    for i in range(xt, f-1, -1): dpx[i] |= dpx[i-f]

dpy = [False]*(yt+1)
dpy[0] = True
for f in Fy:
    for i in range(yt, f-1, -1): dpy[i] |= dpy[i-f]

print('Yes' if dpx[xt] and dpy[yt] else 'No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from itertools import groupby
def resolve():
    S=input()
    X=[]; Y=[]
    dir=0
    for key,iter in groupby(S):
        h=len(list(iter))
        if(key=='T'): dir^=(h&1)
        else:
            if(dir&1==0): X.append(h)
            else: Y.append(h)

    # 最初が移動のときだけは自由度が無いため例外処理
    tx,ty=map(int,input().split())
    if(S[0]=='F'):
        tx-=X[0]
        del X[0]

    # あとはx,y独立に移動できるので、tx、tyが到達可能かを判定
    M=8100*2
    dpx=[0]*M; dpx[0]=1
    dpy=[0]*M; dpy[0]=1

    for x in X:
        ndpx=dpx[:]
        for i in range(M):
            if(dpx[i]==0): continue
            ndpx[(i+x)%M]=1
            ndpx[(i-x)%M]=1
        dpx=ndpx

    for y in Y:
        ndpy=dpy[:]
        for i in range(M):
            if(dpy[i]==0): continue
            ndpy[(i+y)%M]=1
            ndpy[(i-y)%M]=1
        dpy=ndpy

    print("Yes" if(dpx[tx%M] and dpy[ty%M]) else "No")
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from itertools import groupby
def resolve():
    S=input()
    X=[]; Y=[]
    dir=0
    for key,iter in groupby(S):
        h=len(list(iter))
        if(key=='T'): dir^=(h&1)
        else:
            if(dir&1==0): X.append(h)
            else: Y.append(h)

    # 最初が移動のときだけは自由度が無いため例外処理
    tx,ty=map(int,input().split())
    if(S[0]=='F'):
        tx-=X[0]
        del X[0]

    # あとはx,y独立に移動できるので、tx、tyが到達可能かを判定
    M=8100*2
    dpx=[0]*M; dpx[0]=1
    dpy=[0]*M; dpy[0]=1

    for x in X:
        ndpx=dpx[:]
        for i in range(M):
            if(dpx[i]==0): continue
            ndpx[(i+x)%M]=1
            ndpx[(i-x)%M]=1
        dpx=ndpx

    for y in Y:
        ndpy=dpy[:]
        for i in range(M):
            if(dpy[i]==0): continue
            ndpy[(i+y)%M]=1
            ndpy[(i-y)%M]=1
        dpy=ndpy

    print("Yes" if(dpx[tx] and dpy[ty]) else "No")
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from itertools import groupby
def resolve():
    X,Y=[],[]
    dir=0 # 0 が x、1 が y
    for key,iter in groupby(input()):
        if(key=='T'):
            dir+=1
        else:
            if(dir&1==0): X.append(len(list(iter)))
            else: Y.append(len(list(iter)))

    # x,y独立で、到達できる値を全列挙できればよい
    M=8000*2
    dpx=[0]*(M+1)
    dpx[0]=1
    dpy=[0]*(M+1)
    dpy[0]=1

    for x in X:
        ndpx=dpx[:]
        for i in range(-M,M+1):
            if(dpx[i]==0): continue
            if(i+x<=M): ndpx[i+x]=1
            if(i-x>=-M): ndpx[i-x]=1
        dpx=ndpx

    for y in Y:
        ndpy=dpy[:]
        for i in range(-M//2,M//2+1):
            if(dpy[i]==0): continue
            if(i+y<=M): ndpy[i+y]=1
            if(i-y>=-M): ndpy[i-y]=1
        dpy=ndpy

    x,y=map(int,input().split())
    print("Yes" if(dpx[x] and dpy[y]) else "No")
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from itertools import groupby
def resolve():
    X,Y=[],[]
    dir=0 # 0 が x、1 が y
    for key,iter in groupby(input()):
        if(key=='T'):
            dir+=1
        else:
            if(dir&1==0): X.append(len(list(iter)))
            else: Y.append(len(list(iter)))

    # x,y独立で、到達できる値を全列挙できればよい
    M=8000*2
    dpx=[0]*(M+1)
    dpx[0]=1
    dpy=[0]*(M+1)
    dpy[0]=1

    for x in X:
        ndpx=dpx[:]
        for i in range(M+1):
            if(dpx[i]==0): continue
            if(i+x<=M): ndpx[i+x]=1
            if(i-x>=-M): ndpx[i-x]=1
        dpx=ndpx

    for y in Y:
        ndpy=dpy[:]
        for i in range(M+1):
            if(dpy[i]==0): continue
            if(i+y<=M): ndpy[i+y]=1
            if(i-y>=-M): ndpy[i-y]=1
        dpy=ndpy

    x,y=map(int,input().split())
    print("Yes" if(dpx[x] and dpy[y]) else "No")
resolve()

Submission status: Wrong Answer

Solution code:
#82d高速解
s = str(input())+"E"
goal_x,goal_y = map(int, input().split())

#inputの同じ文字はまとめる
summary_s = []
now_order = s[0]
now_order_count = 0 #最初は二重カウントされるので0

for order in s:
    if order == now_order:
        now_order_count += 1
    else:
        summary_s.append([now_order,now_order_count])
        now_order = order
        now_order_count = 1
        
#print(summary_s)

#さらにx,yの動きにまとめる
summary_x = []
summary_y = []
now_state = 1 #1:x ,-1:y

for order in summary_s:
    #print(order[0],order[1])
    
    #進む
    if order[0]=="F":
        if now_state == 1:
            summary_x.append(order[1])
        elif now_state == -1:
            summary_y.append(order[1])

    #回る
    elif order[0]=="T":      
        if order[1]%2 == 1:
            now_state *= -1
            
        #%2==0の時は、進行方向の変化は正負の変化のみ。


#summary_xの中身を足したり引いたりして、input_xに出来るか? という問題になった。yも同様。
#愚直策で考えると2**(len(summary_x)-1)通りあるので間に合わなさそう
#∴どんどん点に近づく方向に大きい値から移動してみる
summary_x.sort(reverse=True)
summary_y.sort(reverse=True)

#print(summary_x)
x = 0
for distance in summary_x:
    if abs(goal_x - (x-distance)) >= abs(goal_x - (x+distance)):
        x += distance
        #print(" +",distance,end="")
    else:
        x -= distance
        #print(" -",distance,end="")
#print(" =",x)

    
#print(summary_y)
y = 0
for distance in summary_y:
    if abs(goal_y - (y-distance)) >= abs(goal_y - (y+distance)):
        y += distance
        #print(" +",distance,end="")
    else:
        y -= distance
        #print(" -",distance,end="")
#print(" =",y)
        
if x == goal_x and y == goal_y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def examD():
    St = S(); X, Y = LI()
    N = len(St)
    ans = "No"
    Fx = deque(); Fy = deque()
    ve = int(1); cur = int(0)
    for i in range(N):
        if St[i] == "F":
            cur += 1
        else:
            if ve == 1:
                Fx.append(cur)
                cur = int(0)
                ve *= -1
            else:
                Fy.append(cur)
                cur = int(0)
                ve *= -1
    if ve == 1:
        Fx.append(cur)
        cur = int(0)
    else:
        Fy.append(cur)
        cur = int(0)
    xfirst = Fx.popleft()
    X = X - xfirst

#    print(Fx)
#    print(Fy)
    xlen = len(Fx); ylen = len(Fy)
    xneed = -1; yneed = -1
    if (sum(Fx) - X) % 2 == 0:
        xneed = (sum(Fx) - X) // 2
    if (sum(Fy) - Y) % 2 == 0:
        yneed = (sum(Fy) - Y) // 2
#    print(xneed)
    dp = [[0] * (xneed + 1) for _ in range(xlen + 1)]
    if xneed > 0:
        dp[0][0] = 1
        for i in range(xlen):
            for j in range(max(xneed + 1, 0)):
                if dp[i][j] != 0:
                    if xneed + 1 - Fx[i] > j:
                        dp[i + 1][j + Fx[i]] = dp[i][j]
                    dp[i + 1][j] = dp[i][j]

    #    print(dp)
    #    print(dp[xlen][xneed])
    if (xneed > 0 and dp[xlen][xneed] == 1) or xneed == 0:
        dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
        for i in range(yneed + 1):
            dp[0][i] = 1
        for i in range(ylen):
            for j in range(max(yneed + 1, 0)):
                if dp[i][j] != 0:
                    if yneed + 1 - Fy[i] > j:
                        dp[i + 1][j + Fy[i]] = dp[i][j]
                    dp[i + 1][j] = dp[i][j]
        if (yneed > 0 and dp[ylen][yneed] == 1) or yneed == 0:
            ans = "Yes"

    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Wrong Answer

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

x = abs(x)
y = abs(y)

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if tmp == 0:
            pass
        elif flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if tmp != 0:
    if flag:
        X.append(tmp)
    else:
        Y.append(tmp)

# print (X)
# print (Y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = [0] * (total_X + 1)
lst_X[0] = 1
for i in X:
    for j in range(total_X - i, -1, -1):
        if lst_X[j] == 1:
            lst_X[j + i] = 1

# print (lst_X)

lst_Y = [0] * (total_Y + 1)
lst_Y[0] = 1
for i in Y:
    for j in range(total_Y - i, -1, -1):
        if lst_Y[j] == 1:
            lst_Y[j + i] = 1

# print (lst_Y)
if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and lst_X[(total_X - x) // 2] == 1 and lst_Y[(total_Y - y) // 2]:
    print ('Yes')
else:
    print ('No')

Submission status: Wrong Answer

Solution code:
from math import cos, sin, radians

S = input()
x,y = map(int,input().split())
pos = [0,0,0] #[dir,x,y]
for s in S:
  if s == 'F':
    pos[1] += int(cos(radians(pos[0])))
    pos[2] += int(sin(radians(pos[0])))
  else:
    if pos[0] == 0:
      if pos[2] < y: pos[0] = 90
      else: pos[0] = 270
        
    elif pos[0] == 180:
      if pos[2] <= y: pos[0] = 90
      else: pos[0] = 270
        
    elif pos[0] == 90:
      if pos[1] <= x: pos[0] = 0
      else: pos[0] = 180
        
    else: # 270
      if pos[1] <= x: pos[0] = 0
      else: pos[0] = 180  
  #print(s, pos)
if pos[1] == x and pos[2] == y:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
from math import cos, sin, radians

S = input()
x,y = map(int,input().split())
pos = [0,0,0] #[dir,x,y]
for s in S:
  if s == 'F':
    pos[1] += int(cos(radians(pos[0])))
    pos[2] += int(sin(radians(pos[0])))
  else:
    if pos[0] == 0:
      if pos[2] <= y: pos[0] += 90
      else:
        pos[0] = 270
    elif pos[0] == 180:
      if pos[2] <= y: pos[0] -= 90
      else:
        pos[0] += 90
    elif pos[0] == 90:
      if pos[1] <= x:
        pos[0] -= 90
      else:
        pos[0] += 90
    else: # 270
      if pos[1] <= x:
        pos[0] = 0
      else:
        pos[0] -= 90  
  #print(s, pos)
if pos[1] == x and pos[2] == y:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import math
s = input()
tgt_x, tgt_y = map(int, input().split())

r_pos = [0, 0]
r_dir = [1, 0]
for order in s:
  if order == "F":
    r_pos[0] += r_dir[0]
    r_pos[1] += r_dir[1]
  elif order == "T":
    tgt_dis_x = tgt_x - r_pos[0]
    if tgt_dis_x != 0:
      tgt_dis_x = tgt_dis_x / abs(tgt_dis_x)
    tgt_dis_y = tgt_y - r_pos[1]
    if tgt_dis_y != 0:
      tgt_dis_y = tgt_dis_y / abs(tgt_dis_y)
    check = r_dir[0] * tgt_dis_y - r_dir[1] * tgt_dis_x
    if check > 0:
      r_dir = [-1 * r_dir[1], r_dir[0]]
    else:
      r_dir = [r_dir[1], -1 * r_dir[0]]

if r_pos[0] == tgt_x and r_pos[1] == tgt_y:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import math
s = input()
tgt_x, tgt_y = map(int, input().split())

r_pos = [0, 0]
r_dir = [1, 0]
for order in s:
  if order == "F":
    r_pos[0] += r_dir[0]
    r_pos[1] += r_dir[1]
    print("{} {}".format(order, r_pos))
  elif order == "T":
    tgt_dis_x = tgt_x - r_pos[0]
    if tgt_dis_x != 0:
      tgt_dis_x = tgt_dis_x / abs(tgt_dis_x)
    tgt_dis_y = tgt_y - r_pos[1]
    if tgt_dis_y != 0:
      tgt_dis_y = tgt_dis_y / abs(tgt_dis_y)
    check = r_dir[0] * tgt_dis_y - r_dir[1] * tgt_dis_x
    if check > 0:
      r_dir = [-1 * r_dir[1], r_dir[0]]
    else:
      r_dir = [r_dir[1], -1 * r_dir[0]]

if r_pos[0] == tgt_x and r_pos[1] == tgt_y:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
X, Y = LI()
N = len(S)
ans = "No"
Fx = deque()
Fy = deque()
ve = int(1)
cur = int(0)

for i in range(N):
    if S[i]=="F":
        cur +=1
    else:
        if ve==1:
            Fx.append(cur)
            cur = int(0)
            ve *= -1
        else:
            Fy.append(cur)
            cur = int(0)
            ve *= -1
if ve==1:
    Fx.append(cur)
    cur = int(0)
else:
    Fy.append(cur)
    cur = int(0)
xfirst = Fx.popleft()
X = X-xfirst

#print(Fx)
#print(Fy)
xlen = len(Fx)
ylen = len(Fy)
xneed = -1; yneed = -1
if (sum(Fx)-X)%2==0:
    xneed = (sum(Fx)-X)//2
if (sum(Fy)-Y)%2==0:
    yneed = (sum(Fy)-Y)//2
#print(xneed)
dp = [[0] * (xneed + 1) for _ in range(xlen + 1)]
if xneed>0:
    dp[0][0]=1
    for i in range(xlen):
        for j in range(max(xneed + 1, 0)):
            if dp[i][j] != 0:
                if xneed + 1 - Fx[i]>j:
                    dp[i + 1][j + Fx[i]] = dp[i][j]
                dp[i + 1][j] = dp[i][j]

#    print(dp)
#    print(dp[xlen][xneed])
if (xneed>0 and dp[xlen][xneed]==1) or xneed==0:
    dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
    if xneed > 0:
        dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
        for i in range(yneed + 1):
            dp[0][i] = 1
        for i in range(ylen):
            for j in range(max(yneed + 1, 0)):
                if dp[i][j] != 0:
                    if yneed + 1 - Fy[i] > j:
                        dp[i + 1][j + Fy[i]] = dp[i][j]
                    dp[i + 1][j] = dp[i][j]

    if (yneed >0 and dp[ylen][yneed]==1) or yneed==0:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
X, Y = LI()
N = len(S)
ans = "No"
Fx = deque()
Fy = deque()
ve = int(1)
cur = int(0)

for i in range(N):
    if S[i]=="F":
        cur +=1
    else:
        if ve==1:
            Fx.append(cur)
            cur = int(0)
            ve *= -1
        else:
            Fy.append(cur)
            cur = int(0)
            ve *= -1
if ve==1:
    Fx.append(cur)
    cur = int(0)
else:
    Fy.append(cur)
    cur = int(0)
xfirst = Fx.popleft()
X = X-xfirst

#print(Fx)
#print(Fy)
xlen = len(Fx)
ylen = len(Fy)
xneed = -1; yneed = -1
if (sum(Fx)-X)%2==0:
    xneed = (sum(Fx)-X)//2
if (sum(Fy)-Y)%2==0:
    yneed = (sum(Fy)-Y)//2
#print(xneed)
dp = [[0] * (xneed + 1) for _ in range(xlen + 1)]
if xneed>0:
    dp[0][0] = 1
    for i in range(xlen):
        for j in range(max(xneed + 1 - Fx[i], 0)):
            if dp[i][j] != 0:
                dp[i + 1][j + Fx[i]] = dp[i][j]

#    print(dp)
#    print(dp[xlen][xneed])
if (xneed>0 and dp[xlen][xneed]==1) or xneed==0:
    dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
    if xneed > 0:
        dp = [[0] * (yneed + 1) for _ in range(ylen + 1)]
        dp[0][0] = 1
        for i in range(ylen):
            for j in range(max(yneed + 1 - Fy[i], 0)):
                if dp[i][j] != 0:
                    dp[i + 1][j + Fy[i]] = dp[i][j]

    if (yneed >0 and dp[ylen][yneed]==1) or yneed==0:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

s = str(input())
x,y = II()

N = len(s)
yoko = []
tate = []
ziku = True
count = 0

for i in range(N):
    if s[i]=='F':
        count += 1
    else:
        if ziku:
            yoko.append(count)
            ziku = False
        else:
            tate.append(count)
            ziku = True
        count = 0

if count!=0:
    if ziku:
        yoko.append(count)
    else:
        tate.append(count)

yoko.append(0)
tate.append(0)

sum1 = sum(yoko)
sum2 = sum(tate)

if abs(x)>sum1 or abs(y)>sum2:
    print('No')
    exit()

yoko_yes = [False]*(2*sum1+1)
yoko_yes[sum1] = True

for yk in yoko:
    ok = []
    for i in range(2*sum1+1):
        if yoko_yes[i]:
            if 0<=i+yk<=2*sum1:
                ok.append(i+yk)
            if 0<=i-yk<=2*sum1:
                ok.append(i-yk)
    yoko_yes = [False]*(2*sum1+1)
    for o in ok:
        yoko_yes[o] = True

tate_yes = [False]*(2*sum2+1)
tate_yes[sum2] = True

for t in tate:
    ok = []
    for i in range(2*sum2+1):
        if tate_yes[i]:
            if 0<=i+t<=2*sum2:
                ok.append(i+t)
            if 0<=i-t<=2*sum2:
                ok.append(i-t)
    tate_yes = [False]*(2*sum2+1)
    for o in ok:
        tate_yes[o] = True

if yoko_yes[x+sum1] and tate_yes[y+sum2]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

s = str(input())
x,y = II()

N = len(s)
yoko = []
tate = []
ziku = True
count = 0

for i in range(N):
    if s[i]=='F':
        count += 1
    else:
        if ziku:
            yoko.append(count)
            ziku = False
        else:
            tate.append(count)
            ziku = True
        count = 0

if count!=0:
    if ziku:
        yoko.append(count)
    else:
        tate.append(count)

if (not yoko) or (not tate):
    print('No')
    exit() 
sum1 = sum(yoko)
sum2 = sum(tate)
if abs(x)>sum1 or abs(y)>sum2:
    print('No')
    exit()

yoko_yes = [False]*(2*sum1+1)
yoko_yes[sum1] = True

for yk in yoko:
    ok = []
    for i in range(2*sum1+1):
        if yoko_yes[i]:
            if 0<=i+yk<=2*sum1:
                ok.append(i+yk)
            if 0<=i-yk<=2*sum1:
                ok.append(i-yk)
    yoko_yes = [False]*(2*sum1+1)
    for o in ok:
        yoko_yes[o] = True

tate_yes = [False]*(2*sum2+1)
tate_yes[sum2] = True

for t in tate:
    ok = []
    for i in range(2*sum2+1):
        if tate_yes[i]:
            if 0<=i+t<=2*sum2:
                ok.append(i+t)
            if 0<=i-t<=2*sum2:
                ok.append(i-t)
    tate_yes = [False]*(2*sum2+1)
    for o in ok:
        tate_yes[o] = True

if yoko_yes[x+sum1] and tate_yes[y+sum2]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int, input().split( ))
cnt_fx = 0
cnt_fy = 0
cnt_tx = 0
cnt_ty = 0
direct_x = 1
for i in range(len(s)):
    if s[i]=="F":
        if direct_x:
            cnt_fx += 1
        else:
            cnt_fy += 1
    else:
        direct_x ^= 1
        if direct_x:
            cnt_tx += 1
        else:
            cnt_ty += 1
    
if cnt_fx < abs(x) or cnt_fy < abs(y) or (cnt_fx + x) % 2 or (cnt_fy + y) % 2 :
    print("No")
elif (x<0 and (cnt_fx-2<abs(x) or cnt_tx<1)):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
xx,yy=[],[]
w=[0,0]
ans=chk=f=0
for i in s:
    if f==1 and i=='F':
        chk+=1
    elif f==1 and i=='T':
        yy.append(chk)
        f=0
    elif f==0 and i=='F':
        chk+=1
    elif f==0 and i=='T':
        xx.append(chk)
        f=1
    if i=='T': chk=0
if chk and f==1:
    yy.append(chk)
elif chk and f==0:
    xx.append(chk)
xx.sort()
yy.sort()
for i in xx[::-1]:
    if w[0]<x:
        w[0]+=i
    else:
        w[0]-=i
for i in yy[::-1]:
    if w[1]<y:
        w[1]+=i
    else:
        w[1]-=i
print("Yes" if w[0]==x and w[1]==y else "No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
xx,yy=[],[]
w=[0,0]
ans=chk=0
f=0
for i in s:
    if f==0 and i=='F':
        w[0]+=1
    elif f==0 and i=='T':
        f=1
    elif f==1 and i=='F':
        chk+=1
    elif f==1 and i=='T':
        yy.append(chk)
        chk=0
        f=2
    elif f==2 and i=='F':
        chk+=1
    elif f==2 and i=='T':
        xx.append(chk)
        chk=0
        f=1
if chk and f==1:
    yy.append(chk)
elif chk and f==2:
    xx.append(chk)
xx.sort(reverse=True)
yy.sort()
for i in xx[::-1]:
    if w[0]<x:
        w[0]+=i
    else:
        w[0]-=i
for i in yy[::-1]:
    if w[1]<y:
        w[1]+=i
    else:
        w[1]-=i
print("Yes" if w[0]==x and w[1]==y else "No")

Submission status: Wrong Answer

Solution code:
s = input().split("T")
x,y = map(int,input().split())
x -= len(s[0])
XY = [[],[]]
for i in range(1,len(s)):
  XY[i%2].append(len(s[i]))
DP = [[0]*(abs(x)+1) for i in range(len(XY[0])+1)]
DP[0][0] = 1
for i in range(len(XY[0])):
  for j in range(abs(x)+1):
    if j >= XY[0][i]:
      DP[i+1][j] = DP[i][j] + DP[i][j-XY[0][i]]
    else:
      DP[i+1][j] = DP[i][j]
if DP[-1][-1] != 0:
  x = 0

DP = [[0]*(abs(y)+1) for i in range(len(XY[1])+1)]
DP[0][0] = 1
for i in range(len(XY[1])):
  for j in range(abs(y)+1):
    if j >= XY[1][i]:
      DP[i+1][j] = DP[i][j] + DP[i][j-XY[1][i]]
    else:
      DP[i+1][j] = DP[i][j]
if DP[-1][-1] != 0:
  y = 0

if (x,y) == (0,0):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
# D submit
import sys
sys.setrecursionlimit(9000)
s = input()
x, y = map(int, input().split())

Fl = s.split('T')
cnt = [len(tmp) for tmp in Fl]
xcnt = [tmp for ind, tmp in enumerate(cnt) if ind%2==0]
ycnt = [tmp for ind, tmp in enumerate(cnt) if ind%2==1]

xfinished = []
yfinished = []

def xdfs(index, total):
    if index == len(xcnt)-1:
        total1 = total + xcnt[index]
        total2 = total - xcnt[index]
        xfinished.append(total1)
        xfinished.append(total2)
        return

    else:
        total1 = total + xcnt[index]
        xdfs(index+1, total1)
        total2 = total - xcnt[index]
        xdfs(index+1, total2)
def ydfs(index, total):
    if index == len(ycnt)-1:
        total1 = total + ycnt[index]
        total2 = total - ycnt[index]
        yfinished.append(total1)
        yfinished.append(total2)
        return

    else:
        total1 = total + ycnt[index]
        ydfs(index+1, total1)
        total2 = total - ycnt[index]
        ydfs(index+1, total2)

xdfs(0, 0)
if ycnt:
	ydfs(0, 0)
else:
	yfinished.append(0)

if (x in xfinished) and (y in yfinished):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def check(z, zz, z_list):
  if len(z_list) == 0:
    if z != zz:
      return 0
    else:
      return 1
  else:
    z_n = len(z_list)
    z_hash = {}
    z_hash[0] = {}
    z_hash[0][zz] = 1
    z_hash[z_n] = {}
    z_hash[z_n][z] = 1
    for i in range(0,z_n):
      if i+1 not in z_hash:
        z_hash[i+1] = {}
        for b_z in z_hash[i]:
          a_z = b_z + z_list[i]
          z_hash[i+1][a_z] = 1
          a_z = b_z - z_list[i]
          z_hash[i+1][a_z] = 1
      else:
        for b_z in z_hash[i]:
          a_z = b_z + z_list[i]
          if a_z in z_hash[i+1]:
            return 1
          a_z = b_z - z_list[i]
          if a_z in z_hash[i+1]:
            return 1
        return 0
      if z_n-i-1 not in z_hash:
        z_hash[z_n-i-1] = {}
        for a_z in z_hash[z_n-i]:
          b_z = a_z + z_list[z_n-i-1]
          z_hash[z_n-i-1][b_z] = 1
          b_z = a_z - z_list[z_n-i-1]
          z_hash[z_n-i-1][b_z] = 1
      else:
        for a_z in z_hash[z_n-i]:
          b_z = a_z + z_list[z_n-i-1]
          if b_z in z_hash[z_n-i-1]:
            return 1
          b_z = a_z + z_list[z_n-i-1]
          if b_z in z_hash[z_n-i-1]:
            return 1
        return 0



s = input()
x, y = map(int, input().split())
data = s.split("T")
xx, yy = 0, 0
i = 0
x_list = []
y_list = []
for Fs in data:
  if len(Fs) == 0:
    i += 1
  else:
    if i == 0:
      xx = len(Fs)
    elif i % 2 == 0:
      x_list.append(len(Fs))
    else:
      y_list.append(len(Fs))
    i += 1
if check(x, xx, x_list) == 1 and check(y, yy, y_list) == 1:
  print("Yes")
else:
  print("No")