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
input = sys.stdin.readline

s = input().rstrip()
x, y = [int(x) for x in input().split()]

horizontal = []
vertical = []

switch = 1
distance = 0

for i in range(len(s)):
    if s[i] == "F":
        distance += 1
    elif switch:
        horizontal.append(distance)
        distance = 0
        switch ^= 1
    else:
        vertical.append(distance)
        distance = 0
        switch ^= 1

if switch:
    horizontal.append(distance)
else:
    vertical.append(distance)

x_error = sum(horizontal) - abs(x)
y_error = sum(vertical) - abs(y)

if x_error < 0 or y_error < 0:
    print("No")
    exit()
elif x_error == 0 and y_error == 0:
    print("Yes")
    exit()

dp_x = [[[0, 0] for _ in range(2*(x_error + 1) - 1)] for _ in range(len(horizontal) + 1)]
dp_y = [[[0, 0] for _ in range(2*(y_error + 1) - 1)] for _ in range(len(vertical) + 1)]

dp_x[0][0 + x_error] = [1, 1]
dp_y[0][0 + y_error] = [1, 1]

for i in range(1, len(horizontal) + 1):
    x_ = horizontal[i - 1]
    for j in range(-x_error, x_error + 1):
        for k in range(2):
            if k:
                x_ *= -1
            if 0 <= j - x_ + x_error < 2*x_error + 1:
                dp_x[i][j + x_error][k] = max(dp_x[i - 1][j - x_ + x_error])

for i in range(1, len(vertical) + 1):
    x_ = vertical[i - 1]
    for j in range(-y_error, y_error + 1):
        for k in range(2):
            if k:
                x_ *= -1
            if 0 <= j - x_ + y_error < 2*y_error + 1:
                dp_y[i][j + y_error][k] = max(dp_y[i - 1][j - x_ + y_error])

if max(dp_x[-1][-1]) and max(dp_y[-1][-1]):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

s = input().rstrip()
x, y = [int(x) for x in input().split()]

horizontal = []
vertical = []

switch = 1
distance = 0

for i in range(len(s)):
    if s[i] == "F":
        distance += 1
    elif switch:
        horizontal.append(distance)
        distance = 0
        switch ^= 1
    else:
        vertical.append(distance)
        distance = 0
        switch ^= 1

if switch:
    horizontal.append(distance)
else:
    vertical.append(distance)

x_error = sum(horizontal) - abs(x)
y_error = sum(vertical) - abs(y)

if x_error < 0 or y_error < 0:
    print("No")
    exit()
elif x_error == 0 and y_error == 0:
    print("Yes")
    exit()

dp_x = [[[0, 0] for _ in range(2*(x_error + 1) - 1)] for _ in range(len(horizontal) + 1)]
dp_y = [[[0, 0] for _ in range(2*(y_error + 1) - 1)] for _ in range(len(vertical) + 1)]

dp_x[0][0 + x_error] = [1, 1]
dp_y[0][0 + y_error] = [1, 1]

for i in range(1, len(horizontal) + 1):
    x_ = horizontal[i - 1]
    for j in range(-x_error, x_error + 1):
        for k in range(2):
            if not k:
                x_ *= -1
            if -x_error <= j - x_ <= x_error:
                dp_x[i][j][k] = max(max(dp_x[i - 1][j + x_error]), max(dp_x[i - 1][j - x_ + x_error]))
            else:
                dp_x[i][j][k] = max(dp_x[i - 1][j + x_error])

for i in range(1, len(vertical) + 1):
    x_ = vertical[i - 1]
    for j in range(-y_error, y_error + 1):
        for k in range(2):
            if not k:
                x_ *= -1
            if -y_error <= j - x_ <= y_error:
                dp_y[i][j][k] = max(max(dp_y[i - 1][j + y_error]), max(dp_y[i - 1][j - x_ + y_error]))
            else:
                dp_y[i][j][k] = max(dp_y[i - 1][j + y_error])

if max(dp_x[-1][-1]) and max(dp_y[-1][-1]):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import itertools

s = input()
x,y = map(int,input().split())
d = [len(fs) for fs in s.split('T')]
x -= d[0]
dx = d[2::2]
dy = d[1::2]

def check(d,x):
    set_ = set([0])
    for dx in d:
        set_ = {a+b for a,b in itertools.product(set_,[dx,-dx])}
        return x in set_
if check(dx,x) and check(dy,y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
x_count = 0
y_count = 0
first_x = 0
frag = 0
for _ in s:
  if _ == "F":
    if frag %2 == 0:
      x_count += 1
    if frag %2 ==1 :
      y_count += 1
  if _ == "T":
    frag += 1
for _ in s:
  if _ == "F":
    first_x += 1
  else:
    break
  
      
if abs(x_count - first_x)  >= abs(x - first_x) and abs(y_count) >= abs(y) and x_count % 2 == x % 2 and y_count % 2 == y %2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split())
x_count = 0
y_count = 0
frag = 0
for _ in s:
  if _ == "F":
    if frag %2 == 0:
      x_count += 1
    if frag %2 ==1 :
      y_count += 1
  if _ == "T":
    frag += 1
  
      
if abs(x_count) >= abs(x) and abs(y_count) >= abs(y) and x_count % 2 == x % 2 and y_count % 2 == y %2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
t = [len(i) for i in input().split('T')]
x,y = map(int, input().split())

a = sorted(t[2::2])
b = sorted(t[1::2])
acc = [0] + list(accumulate(a))
bcc = [0] + list(accumulate(b))

xx = False
for i in acc:
    # print(2 * i - acc[-1])
    tmp = 2 * i - acc[-1]
    # print(tmp, x-t[0], x)
    if abs(x - t[0]) == abs(tmp):
        xx = True
        break
yy = False
y = abs(y)
for i in bcc:
    tmp = 2 * i - bcc[-1]
    if y == abs(tmp):
        yy = True
        break

print('Yes' if xx and yy else 'No')
# print(a,b)
# print(acc, bcc)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
t = [len(i) for i in input().split('T')]
x,y = map(int, input().split())

a = t[2::2]
b = t[1::2]
acc = [0] + list(accumulate(a))
bcc = [0] + list(accumulate(b))

xx = False
for i in acc:
    # print(2 * i - acc[-1])
    tmp = 2 * i - acc[-1]
    # print(tmp, x-t[0], x)
    if abs(x - t[0]) == abs(tmp):
        xx = True
        break
yy = False
y = abs(y)
for i in bcc:
    tmp = 2 * i - bcc[-1]
    if y == abs(tmp):
        yy = True
        break

print('Yes' if xx and yy else 'No')
# print(a,b)
# print(acc, bcc)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
t = [len(i) for i in input().split('T')]
x,y = map(int, input().split())

a = t[0::2]
b = t[1::2]
acc = list(accumulate(a))
bcc = list(accumulate(b))

xx = False
for i in acc:
    # print(2 * i - acc[-1])
    if x == 2 * i - acc[-1]:
        xx = True
        break
yy = False
for i in bcc:
    if y == 2 * i - bcc[-1]:
        yy = True
        break

print('Yes' if xx and yy else 'No')

# print(a,b)
# print(acc, bcc)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
t = [len(i) for i in input().split('T')]
x,y = map(int, input().split())

a = t[0::2]
b = t[1::2]
acc = list(accumulate(a))
bcc = [0] + list(accumulate(b))

xx = False
for i in acc:
    if x == 2 * i - acc[-1]:
        xx = True
        break
yy = False
for i in bcc:
    if y == 2 * i - bcc[-1]:
        yy = True
        break

print('Yes' if xx and yy else 'No')

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
s = input()
x,y = map(int, input().split())
t = [len(i) for i in s.split('T')]
a = sorted(t[0::2])
b = sorted(t[1::2])

acc = [0] + list(accumulate(a))
bcc = [0] + list(accumulate(b))

last = acc[-1]
xx = False
for i in acc:
    if x == 2 * i - last:
        xx = True
        break
last = bcc[-1]
yy = False
for i in bcc:
    if y == 2 * i - last:
        yy = True
        break

print('Yes' if xx and yy else 'No')

Submission status: Wrong Answer

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

    dx = []
    dy = []
    dir = 0
    cnt = 0
    for i in range(n):
        if s[i] == 'F':
            cnt += 1
        else:
            if dir%2 == 0:
                dx.append(cnt)
                cnt = 0
                dir += 1
            else:
                dy.append(cnt)
                cnt = 0
                dir += 1
    else:
        if dir%2 == 0:
            dx.append(cnt)
        else:
            dy.append(cnt)

    dpx = [0]*(len(dx)+1)
    dpy = [0]*(len(dy)+1)

    import numpy as np
    D = 2*n+1
    dpx[0] = np.zeros(D, np.bool)
    dpy[0] = np.zeros(D, np.bool)
    dpx[0][n] = 1
    dpy[0][n] = 1

    for i in range(len(dx)):
        d = dx[i]
        b = np.zeros(D, np.bool)
        b[d:] |= dpx[i][:D-d]
        b[:D-d] |= dpx[i][d:]
        dpx[i+1] = b

    for i in range(len(dy)):
        d = dy[i]
        b = np.zeros(D, np.bool)
        b[d:] |= dpy[i][:D-d]
        b[:D-d] |= dpy[i][d:]
        dpy[i+1] = b

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
cnt=0
flag=0
for i in range(len(s)):
  if s[i]=='T':
    cnt+=1
    flag=0
  else: 
    if cnt==0:
      x-=1
    elif flag==0:
      if cnt%2==0:
        if x>=0:
          x-=1
          flag=3
        else:
          x+=1
          flag=1
      else:
        if y>=0:
          y-=1
          flag=4
        else:
          y+=1
          flag=2
    else:
      if flag==1:
        x+=1
      elif flag==2:
        y+=1
      elif flag==3:
        x-=1
      elif flag==4:
        y-=1
print('Yes' if x==0 and y==0 else 'No')

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
cnt=0
for i in range(len(s)):
  if s[i]=='T':
    cnt+=1
  else: 
    if cnt==0:
      x-=1
    elif cnt%2==0:
      if x>=0:
        x-=1
      else:
        x+=1
    else:
      if y>=0:
        y-=1
      else:
        y+=1
print('Yes' if x==0 and y==0 else 'No')

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


def main():

    ss = list(input())[:-1]

    ss = s(ss)

    n = len(ss)

    x,y = m()

    x += 8000

    y += 8000

    dpx = [[False for i in range(8000*2 + 1)] for j in range(n+1)]

    dpy = [[False for i in range(8000*2 + 1)] for j in range(n+1)]

    dpx[0][8000] = True

    dpy[0][8000] = True

    ro = 0
    exit()

    for i in range(1,n+1):
        pop = ss[i-1]
        if pop[0] == "T":
            if pop[1] % 2 == 1:
                ro ^= 1
            for j in range(16000+1):
                dpx[i][j] = dpx[i-1][j]
                dpy[i][j] = dpy[i-1][j]
        else:
            if i == 1:
                dpx[i][pop[1]+ 8000] = True
                dpy[i][8000] = True
                
            else:
                if ro == 0:
                    for j in range(16000+1):
                        if j + pop[1] <= 16000:
                            if dpx[i-1][j]:
                                dpx[i][j + pop[1]] = dpx[i-1][j]
                        if j - pop[1] >= 0:
                            if dpx[i-1][j]:
                                dpx[i][j - pop[1]] = dpx[i-1][j]
                        dpy[i][j] = dpy[i-1][j]
                else:
                    for j in range(16000+1):
                        if j + pop[1] <= 16000:
                            if dpy[i-1][j]:
                                dpy[i][j + pop[1]] = dpy[i-1][j]
                        if j - pop[1] >= 0:
                            if dpy[i-1][j]:
                                dpy[i][j - pop[1]] = dpy[i-1][j]
                        dpx[i][j] = dpx[i-1][j]

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

            


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
X,Y=map(int,input().split())

if s==["F"]:
    if X==1 and Y==0:
        print("Yes")
    else:
        print("No")
    exit()

way=[[],[]]

switch=0
judge=True

lx=[]
ly=[0]
temp=0
for item in s:
    if item == "T":
        if judge:
            judge=False
            lx.append(temp)
        else:
            way[switch].append(temp)
        temp=0
        switch^=1
    else:
        temp+=1
way[switch].append(temp)

#print(lx)

for x in way[0]:
    temp_x=[]
    for item in lx:
        temp_x.append(item+x)
        temp_x.append(item-x)
    lx=temp_x[:]
    lx=list(set(lx))
#print(lx)

for y in way[1]:
    temp_y=[]
    for item in ly:
        temp_y.append(item+y)
        temp_y.append(item-y)
    ly=temp_y[:]
    ly=list(set(ly))
#print(ly)

if (X in lx) and (Y in ly):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
X,Y=map(int,input().split())

way=[[],[]]

switch=0
judge=True

lx=[]
ly=[0]
temp=0
for item in s:
    if item == "T":
        if judge:
            judge=False
            lx.append(temp)
        else:
            way[switch].append(temp)
        temp=0
        switch^=1
    else:
        temp+=1
way[switch].append(temp)

#print(lx)

for x in way[0]:
    temp_x=[]
    for item in lx:
        temp_x.append(item+x)
        temp_x.append(item-x)
    lx=temp_x[:]
    lx=list(set(lx))
#print(lx)

for y in way[1]:
    temp_y=[]
    for item in ly:
        temp_y.append(item+y)
        temp_y.append(item-y)
    ly=temp_y[:]
    ly=list(set(ly))
#print(ly)

if (X in lx) and (Y in ly):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
X,Y=map(int,input().split())

way=[[],[]]

switch=0
judge=True

lx=[]
ly=[0]
temp=0
for item in s:
    if item == "T":
        if judge:
            judge=False
            lx.append(temp)
        else:
            way[switch].append(temp)
        temp=0
        switch^=1
    else:
        temp+=1
way[switch].append(temp)

#print(lx)

for x in way[0]:
    temp_x=[]
    for item in lx:
        temp_x.append(item+x)
        temp_x.append(item-x)
    lx=temp_x[:]

#print(lx)

for y in way[1]:
    temp_y=[]
    for item in ly:
        temp_y.append(item+y)
        temp_y.append(item-y)
    ly=temp_y[:]
    
#print(ly)

if (X in lx) and (Y in ly):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#082_D
s = input()
x, y = map(int, input().split())
xgo, ygo = [], []

cnt = 0
flg = True
check = True if s[0] == 'F' else False
for i in range(len(s)):
    if s[i] == 'T':
        if flg and cnt > 0:
            xgo.append(cnt)
        elif cnt > 0:
            ygo.append(cnt)
        cnt = 0
        flg = (flg + 1) % 2
    else:
        cnt += 1

if flg and cnt > 0:
    xgo.append(cnt)
elif cnt > 0:
    ygo.append(cnt)

flg1, flg2 = len(xgo)==0, len(ygo)==0

sum_x, sum_y = sum(xgo), sum(ygo)
dp1 = [[False for _ in range(2*sum_x+1)] for _ in range(len(xgo)+1)]
dp2 = [[False for _ in range(2*sum_y+1)] for _ in range(len(ygo)+1)]

if check:
    dp1[1][sum_x+xgo[0]] = True
    for i in range(2, len(xgo)+1):
        for j in range(-sum_x, sum_x+1):
            if 0 <= j+sum_x-xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x-xgo[i-1]]:
                    dp1[i][j+sum_x] = True
            if 0 <= j+sum_x+xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x+xgo[i-1]]:
                    dp1[i][j+sum_x] = True
else:
    dp1[0][0] = True
    for i in range(1, len(xgo)+1):
        for j in range(-sum_x, sum_x+1):
            if 0 <= j+sum_x-xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x-xgo[i-1]]:
                    dp1[i][j+sum_x] = True
            if 0 <= j+sum_x+xgo[i-1] <= 2*sum_x:
                if dp1[i-1][j+sum_x+xgo[i-1]]:
                    dp1[i][j+sum_x] = True

dp2[0][sum_y+0] = True
for i in range(1, len(ygo)+1):
    for j in range(-sum_y, sum_y+1):
        if 0 <= j+sum_y-ygo[i-1] <= 2*sum_y:
            if dp2[i-1][j+sum_y-ygo[i-1]]:
                dp2[i][j+sum_y] = True
        if 0 <= j+sum_y+ygo[i-1] <= 2*sum_y:
            if dp2[i-1][j+sum_y+ygo[i-1]]:
                dp2[i][j+sum_y] = True
                
if flg1:
    flgx = (x == 0)
elif abs(x) > sum_x:
    flgx = False
else:
    flgx = dp1[len(xgo)][sum_x+x]
    
if flg2:
    flgy = (y == 0)
elif abs(y) >sum_y:
    flgy = False
else:
    flgy = dp2[len(ygo)][sum_y+y]
    
print('Yes' if flgx and flgy else 'No')

Submission status: Wrong Answer

Solution code:
s = list(input())
x, y = map(int, input().split())
l = [0, 0]
c = 0
for i in s:
    if i == "F":
        if c == 0:
            x -= 1
        else:
            l[c % 2] += 1
    else:
        c += 1
ans = 0
if l[0] - abs(x) >= 0 and l[1] - abs(y) >= 0:
    if (l[0] - abs(x)) % 2 == 0 and abs(l[1] - abs(y)) % 2 == 0:
        ans = 1
print("Yes" if ans == 1 else "No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


def solve(L, pos, axis):
    N = sum(L)
    if N == 0:
        return pos == 0
    dp = [[0] * (2 * N + 10) for _ in range(len(L))]
    dp[0][L[0]] = 1
    if axis == 'Y':
        dp[0][-L[0]] = 1
    for i in range(1, len(L)):
        d = L[i]
        for j in range(-N, N + 1):
            dp[i][j] = dp[i - 1][max(- N - 1, j - d)] + dp[i - 1][min(N + 1, j + d)]
    return dp[len(L) - 1][pos]


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

X = []
Y = []

L = X
cnt = 0
for s in S:
    if s == 'F':
        cnt += 1
    else:
        L.append(cnt)
        L = X if L == Y else Y
        cnt = 0
else:
    if s == 'F':
        L.append(cnt)

ans = True
ans &= solve(X, x, 'X')
ans &= solve(Y, y, 'Y')

if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


def solve(L, pos, axis):
    N = sum(L)
    if N == 0:
        return pos == x
    dp = [[0] * (2 * N + 10) for _ in range(len(L))]
    dp[0][L[0]] = 1
    if axis == 'Y':
        dp[0][-L[0]] = 1
    for i in range(1, len(L)):
        d = L[i]
        for j in range(-N, N + 1):
            dp[i][j] = dp[i - 1][j - d] + dp[i - 1][j + d]
    return dp[len(L) - 1][pos]


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

X = []
Y = []

L = X
cnt = 0
for s in S:
    if s == 'F':
        cnt += 1
    else:
        L.append(cnt)
        L = X if L == Y else Y
        cnt = 0
else:
    if s == 'F':
        L.append(cnt)

ans = True
ans &= solve(X, x, 'X')
ans &= solve(Y, y, 'Y')

if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
a,b=[],[]
turn=True
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    else:
        if i[1]%2==1:
            turn=not turn
a.sort(reverse=True)
b.sort(reverse=True)
for i in a:
    if x>0:
        x-=i
    else:
        x+=i
for i in b:
    if y>0:
        y-=i
    else:
        y+=i
if x!=0 or y!=0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main(): 
    s = input() + 'a'
    x,y = map(int,input().split())
    
    cnt_t = 0
    cnt_f = 0
    p = []
    q = []
    before = True
    for i in range(len(s)-1):
        if s[i] == 'T' :
            cnt_t += 1
        elif s[i] == 'F' and s[i+1] == 'F':
            cnt_f += 1
        else:
            cnt_f += 1
            if cnt_t == 0:
                x -= cnt_f
            elif cnt_t%2 == 0:
                if before:
                    p.append(cnt_f)
                else:
                    q.append(cnt_f)
            else:
                if before:
                    q.append(cnt_f)
                else:
                    p.append(cnt_f)
                before = False
            cnt_t = 0
            cnt_f = 0
    
    
    p.sort(reverse=True)
    q.sort(reverse=True)

    s = 0
    for i in range(len(p)):
        if s <= x:
            s += p[i]
        else:
            s -= p[i]
    
    t = 0
    for i in range(len(q)):
        if t <= y:
            t += q[i]
        else:
            t -= q[i]
    
    if s == x and t == y:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
S=input()
x,y=map(int,input().split())

Xlst=[]
Ylst=[]
count=0
flag=0
for s in S:
    if s=="F":
        count+=1
    else:
        if flag:
            if count:
                Ylst.append(count)
            flag=0
        else:
            if count:
                Xlst.append(count)
            flag=1
        count=0
if flag:
    if count:
        Ylst.append(count)
else:
    if count:
        Xlst.append(count)

numx=set([0])
nlst=set()
c=0
for X in Xlst:
    if c%2==0:
        while numx:
            a=numx.pop()
            nlst.add(a+X)
            nlst.add(a-X)
    else:
        while nlst:
            a=nlst.pop()
            numx.add(a+X)
            numx.add(a-X)
    c+=1
if x in numx|nlst:
    numx=set([0])
    nlst=set()
    c=0
    for X in Ylst:
        if c%2==0:
            while numx:
                a=numx.pop()
                nlst.add(a+X)
                nlst.add(a-X)
        else:
            while nlst:
                a=nlst.pop()
                numx.add(a+X)
                numx.add(a-X)
        c+=1
    if y in numx|nlst:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
S=input()
x,y=map(int,input().split())

Xlst=[]
Ylst=[]
count=0
flag=0
for s in S:
    if s=="F":
        count+=1
    else:
        if flag:
            if count:
                Ylst.append(count)
            flag=0
        else:
            if count:
                Xlst.append(count)
            flag=1
        count=0
if flag:
    if count:
        Ylst.append(count)
else:
    if count:
        Xlst.append(count)

numx=set([0])
nlst=set()
c=0
for X in Xlst:
    if c%2==0:
        while numx:
            a=numx.pop()
            nlst.add(a+X)
            nlst.add(a-X)
    else:
        while nlst:
            a=nlst.pop()
            numx.add(a+X)
            numx.add(a-X)
    c+=1
if c%2:
    numx=nlst
if x in numx:
    numx=set([0])
    nlst=set()
    c=0
    for X in Ylst:
        if c%2==0:
            while numx:
                a=numx.pop()
                nlst.add(a+X)
                nlst.add(a-X)
        else:
            while nlst:
                a=nlst.pop()
                numx.add(a+X)
                numx.add(a-X)
        c+=1
    if c%2:
        numx=nlst
    if y in numx:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input()
x,y=map(int,input().split())
xy=[0,0]
xx=0
f=0
flag=True
for i in s:
  if i=="F":
    if flag and f==0:
      xx+=1
      continue 
    xy[f]+=1
  else:
    f^=1
    flag=False
ans="Yes"
if not(xx-xy[0]<=x<=xx+xy[0]):ans="No"
xy[0]+=xx
if (xy[0]+x)%2==0 and (xy[1]+y)%2==0:print(ans)
else:print('No')

Submission status: Wrong Answer

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
x += lon[0]
lon = lon[1:]
def f(x, A):
  A.append(abs(x))
  A.sort(reverse=True)
  k = A[0]
  for p in A[1:]:
      if k > 0:
        k -= p
      else:
        k += p
  if k == 0:
    return True
  else:
    return False
  
#print(lon, lat)
if f(x, lon) == f(y, lat) == True:
  ans = "Yes"
  
print(ans)

Submission status: Wrong Answer

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, A):
  A.append(abs(x))
  A.sort(reverse=True)
  k = A[0]
  for p in A[1:]:
      if k > 0:
        k -= p
      else:
        k += p
  if k == 0:
    return True
  else:
    return False
  
#print(lon, lat)
if f(x, lon) == f(y, lat) == True:
  ans = "Yes"
  
print(ans)

Submission status: Wrong Answer

Solution code:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(lon, lat)
if sum(lon) >= abs(x):
  if sum(lat) >= abs(y):
    lon.sort(reverse=True)
    lat.sort(reverse=True)
    ans = f(x, y, lon, lat, ans)
    if ans == "No":
      if x != 0:
        x += x // abs(x) * abs(lon[-1])
        lon = lon[:-1]
      if y != 0:
        y += y // abs(y) * abs(lat[-1])
        lat = lat[:-1]
      ans = f(x, y, lon, lat, ans)
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split('T')
X, Y = map(int, input().split())

x = [len(i) for i in s[0::2]]
y = [len(i) for i in s[1::2]]

x, y = sorted(x), sorted(y)


while x:
    mx = x.pop()
    if X < 0:
        X += mx
    else:
        X -= mx

while y:
    my = y.pop()
    if Y < 0:
        Y += my
    else:
        Y -= my

print('Yes' if X == 0 and Y == 0 else 'No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
n = len(s)
S = [[], []]
d = 0
f = 0
for i in range(n):
  if s[i] == 'T':
    if f != 0:
      S[d].append(f)
    d += 1
    d %= 2
    f = 0
  elif s[i] == 'F':
    f += 1
if s[n-1] == 'F':
  S[d].append(f)
if S[0] == []:
  S[0].append(0)
if S[1] == []:
  S[1].append(0)
Dx, Dy = {}, {}
if s[0] == 'F':
  Dx[S[0][0]] = 1
  S[0] = S[0][1:]
Dy[S[1][0]] = 1
Dy[-S[1][0]] = 1
S[1] = S[1][1:]
for i in S[0]:
  tmp = [j for j in Dx]
  for j in tmp:
    Dx[j+i] = 1
    Dx[j-i] = 1
for i in S[1]:
  tmp = [j for j in Dy]
  for j in tmp:
    Dy[j+i] = 1
    Dy[j-i] = 1
if x in Dx and y in Dy:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

axis = 1
count = 0
X, Y = [], []
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    elif s[i] == 'T':
        if axis == 1:
            X.append(count)
            count = 0
        else:
            Y.append(count)
            count = 0
        axis *= -1
if axis == 1:
    X.append(count)
else:
    Y.append(count)


# x軸を先に見る, 値は +- 8*(10**3) が最大最小

max_idou = 8*(10**3)
DP = [[False for _ in range(2*max_idou+1)] for _ in range(len(X))]

for i in range(len(X)):
    DP[i][max_idou + X[i]] = True
    DP[i][max_idou - X[i]] = True
    for j in range(2*max_idou+1):
        if i == 0:
            break
        if j+X[i] > 2*max_idou:
            pass
        elif DP[i-1][j+X[i]] == True:
            DP[i][j] = True
        if j-X[i] < 0:
            pass
        elif DP[i-1][j-X[i]] == True:
            DP[i][j] = True
        
x_check = DP[len(X)-1][max_idou+x]

DP = [[False for _ in range(2*max_idou+1)] for _ in range(len(X))]

for i in range(len(Y)):
    DP[i][max_idou + Y[i]] = True
    DP[i][max_idou - Y[i]] = True
    for j in range(2*max_idou+1):
        if i == 0:
            break
        if j+Y[i] > 2*max_idou:
            pass
        elif DP[i-1][j+Y[i]] == True:
            DP[i][j] = True
        if j-Y[i] < 0:
            pass
        elif DP[i-1][j-Y[i]] == True:
            DP[i][j] = True
        
y_check = DP[len(Y)-1][max_idou+y]

if x_check and y_check:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()[: -1]
t = s.split("T")
x, y = map(int, input().split())

xm = t[: : 2]
ym = t[1: : 2]
xl = 0
yl = 0
for i in range(len(xm)): xl += len(xm[i])
for i in range(len(ym)): yl += len(ym[i])
if xl < abs(x) or (yl < abs(y)):
  print("No")
  exit(0)
#print(xm, ym)
dp = [[0] * (xl * 2 + 1) for _ in range(len(xm) + 1)]
dp[0][xl] = 1
for i in range(len(xm)):
  for j in range(xl * 2 + 1):
    z = len(xm[i])
    if (j + z) in range(xl * 2 + 1):
      dp[i + 1][j + z] |= dp[i][j]
    if (j - z) in range(xl * 2 + 1):
      dp[i + 1][j - z] |= dp[i][j]
if dp[-1][xl + x] == 0:
  print("No")
  exit(0)
dp = [[0] * (yl * 2 + 1) for _ in range(len(ym) + 1)]
dp[0][yl] = 1
for i in range(len(ym)):
  for j in range(yl * 2 + 1):
    z = len(ym[i])
    if (j + z) in range(yl * 2 + 1):
      dp[i + 1][j + z] |= dp[i][j]
    if (j - z) in range(yl * 2 + 1):
      dp[i + 1][j - z] |= dp[i][j]
if dp[-1][yl + y] == 0:
  print("No")
  exit(0)
print("Yes")