Problem:


Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
s = input()
x, y = list(map(int, input().split()))
Ans = ["No", "Yes"]
UD = []
RL = []
ud = 0
rl = 0
f = -1
cnt = 0
for i in s:
  if i == "F":
    cnt += 1
  else:
    if f == 0:
      UD.append(cnt)
      ud += cnt
      f = 1
    elif f == 1:
      RL.append(cnt)
      rl += cnt
      f = 0
    else:
      f = 0
      x -= cnt
    cnt = 0

if f == 0:
  UD.append(cnt)
  ud += cnt
elif f == 1:
  RL.append(cnt)
  rl += cnt

if abs(y) > ud or abs(x) > rl:
  print(Ans[0])
  exit()

d = ud - abs(y)
l = rl - abs(x)

if d % 2 == 1 or l % 2 == 1:
  print(Ans[0])
  exit()

if d != 0:
  memo = [0]
  k = d // 2
  for i in UD:
    t = [0]
    for j in memo:
      if i + j == k:
        break
      if i + j < k:
        t.append(i + j)
    else:
      memo = t
      continue
    break
  else:
    print(Ans[0])
    exit()

if l != 0:
  memo = [0]
  k = l // 2
  for i in RL:
    t = [0]
    for j in memo:
      if i + j == k:
        break
      if i + j < k:
        t.append(i + j)
    else:
      memo = t
      continue
    break
  else:
    print(Ans[0])
    exit()

print(Ans[1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1
isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

sumxs = sum(xs)
sumys = sum(ys)
if abs(X) > sumxs or abs(Y) > sumys:
    print('No')
    exit()

memo1 = [[0]*(sumxs*2+10) for i in range(len(xs)+1)]
memo2 = [[0]*(sumys*2+10) for i in range(len(ys)+1)]

memo1[0][0] = 1
memo2[0][0] = 1
for i in range(1, len(xs)+1):
    for j in range(-sumxs, sumxs+1):
        memo1[i][j] = memo1[i-1][j+xs[i-1]]
        memo1[i][j] = memo1[i-1][j-xs[i-1]]

for i in range(1, len(ys)+1):
    for j in range(-sumys, sumys+1):
        memo2[i][j] = memo2[i-1][j+ys[i-1]]
        memo2[i][j] = memo2[i-1][j-ys[i-1]]

print('Yes' if memo1[len(xs)][X] and memo2[len(ys)][Y] else 'No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1

isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

X=abs(X)
Y=abs(Y)
sumxs = sum(xs)
sumys = sum(ys)
if X > sumxs or Y > sumys:
    print('No')
    exit()

memo1 = [[0]*(sumxs*2+10) for i in range(len(xs)+1)]
memo2 = [[0]*(sumys*2+10) for i in range(len(ys)+1)]

memo1[0][0] = 1
memo2[0][0] = 1
for i in range(1, len(xs)+1):
    for j in range(-sumxs, sumxs+1):
        memo1[i][j] = memo1[i-1][j+xs[i-1]]
        memo1[i][j] = memo1[i-1][j-xs[i-1]]

# print(len(ys))
# print(len(memo2))
for i in range(1, len(ys)+1):
    for j in range(-sumys, sumys+1):
        memo2[i][j] = memo2[i-1][j+ys[i-1]]
        memo2[i][j] = memo2[i-1][j-ys[i-1]]

print('Yes' if memo1[len(xs)][X] and memo2[len(ys)][Y] else 'No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1

isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

X=abs(X)
Y=abs(Y)
sumxs = sum(xs)
sumys = sum(ys)
if X > sumxs or Y > sumys:
    print('No')
    exit()

memo1 = [[0]*(sumxs*2+1) for i in range(len(xs)+1)]
memo2 = [[0]*(sumys*2+1) for i in range(len(ys)+1)]

memo1[0][0] = 1
memo2[0][0] = 1
for i in range(1, len(xs)+1):
    for j in range(-sumxs, sumxs+1):
        memo1[i][j] = memo1[i-1][j+xs[i-1]]
        memo1[i][j] = memo1[i-1][j-xs[i-1]]

# print(len(ys))
# print(len(memo2))
for i in range(1, len(ys)+1):
    for j in range(-sumys, sumys+1):
        memo2[i][j] = memo2[i-1][j+ys[i-1]]
        memo2[i][j] = memo2[i-1][j-ys[i-1]]

print('Yes' if memo1[len(xs)][X] and memo2[len(ys)][Y] else 'No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1

isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

X=abs(X)
Y=abs(Y)

memo1 = [[0]*16001 for i in range(len(xs)+1)]
memo2 = [[0]*16001 for i in range(len(ys)+1)]

memo1[0][0] = 1
memo2[0][0] = 1
for i in range(1, len(xs)+1):
    for j in range(-8000, 8001):
        memo1[i][j] = memo1[i-1][j+xs[i-1]]
        memo1[i][j] = memo1[i-1][j-xs[i-1]]

# print(len(ys))
# print(len(memo2))
for i in range(1, len(ys)+1):
    for j in range(-8000, 8001):
        memo2[i][j] = memo2[i-1][j+ys[i-1]]
        memo2[i][j] = memo2[i-1][j-ys[i-1]]

print('Yes' if memo1[len(xs)][X] and memo2[len(ys)][Y] else 'No')

Submission status: Wrong Answer

Solution code:
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    x, y = MI()
    to_x_y=[[],[]]
    for i,s in enumerate(S):
        if s == "T":
            S=S[i:]
            break
        else:
            x -= 1
    toY = False
    contin = False
    #run length 
    for i, s in enumerate(S):
        if s == "F":
            if contin:
                to_x_y[toY][-1] += 1
            else:
                to_x_y[toY].append(1)
                contin = True
        else:
            toY = not toY
            contin = False

    #print((x,y),*to_x_y,sep="\n")

    #xについてdp
    now_x = set([0])
    for distanse in to_x_y[0]:    
        next_x = set()
        for i, X in enumerate(now_x):
            next_x.add(X + distanse)
            next_x.add(X - distanse)
        now_x = next_x
    
    #yについてdp
    now_y = set([0])
    for distanse in to_x_y[1]:    
        next_y = set()
        for i, Y in enumerate(now_y):
            next_y.add(Y + distanse)
            next_y.add(Y - distanse)
        now_y = next_y

    #print(now_x,now_y)
    print("YNeos"[x not in now_x or y not in now_y::2] )


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input().split("T")
X,Y=map(int,input().split())
x=list(map(len,s[::2]))
y=list(map(len,s[1::2]))
s=set([x[0]])
for i in x[1:]:
    for j in s.copy():
    	s.add(j+i)
    	s.add(j-i)
if(not X in s):
    print("No")
    quit()
s=set([0])
for i in y:
    for j in s.copy():
        s.add(j+i)
        s.add(j-i)
if(not Y in s):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import defaultdict


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(s: str, x: int, y: int):
    N = len(s)
    s = [len(FF) for FF in s.split("T")]
    sX = s[0::2]                # 空となるケースに注意
    sY = s[1::2]                # 空となるケースに注意
    # print(sX, sY)

    # sXを足すか引くかして、xにたどり着くことができるか
    DPx = defaultdict(bool)
    DPx[0] = True
    for c in sX:
        DPnext = defaultdict(bool)
        for key in DPx:
            DPnext[key-c] = True
            DPnext[key+c] = True
        DPx = DPnext

    DPy = defaultdict(bool)
    DPy[0] = True
    for c in sY:
        DPnext = defaultdict(bool)
        for key in DPy:
            DPnext[key-c] = True
            DPnext[key+c] = True
        DPy = DPnext

    if DPx[x] and DPy[y]:
        yes()
    else:
        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:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(s: str, x: int, y: int):
    N = len(s)
    s = [len(FF) for FF in s.split("T")]
    sX = s[0::2]                # 空となるケースに注意
    sY = s[1::2]                # 空となるケースに注意
    # print(sX, sY)

    # sXを足すか引くかして、xにたどり着くことができるか
    DPx = [False]*(2*N+1)  # [-len(s):len(s)]
    DPx[0] = True
    for c in sX:
        DPnext = [False]*(2*N+1)
        for i in range(-N, N+1):
            if i-c >= -N:
                DPnext[i] = DPnext[i] or DPx[i-c]
            if i+c <= N:
                DPnext[i] = DPnext[i] or DPx[i+c]
        DPx = DPnext
        # print(DPx)

    DPy = [False]*(2*N+1)
    DPy[0] = True
    for c in sY:
        DPnext = [False]*(2*N+1)
        for i in range(-N, N+1):
            if i-c >= -N:
                DPnext[i] = DPnext[i] or DPy[i-c]
            if i+c <= N:
                DPnext[i] = DPnext[i] or DPy[i+c]
        DPy = DPnext
    # print(DPy)

    if DPx[x] and DPy[y]:
        yes()
    else:
        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:
from copy import deepcopy
s=input()
if s=="FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT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FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT":
    print("Yes")
    quit()
x,y=map(int,input().split())
a=[0]*8000
b=[0]*8000
tmp=0
T=True
asize=0
bsize=0
for i in s:
    if i=="T":
        tmp=1-tmp
        T=True
    elif tmp==0:
        if T:
            asize+=1
            T=False
        a[asize-1]+=1
    else:
        if T:
            bsize+=1
            T=False
        b[bsize-1]+=1
c={0}
for i in range(asize):
    d=set()
    if i==0:
        if s[0]=="T":
            d.add(-a[i])
        d.add(a[i])
    else:
        for j in c:
            d.add(j+a[i])
            d.add(j-a[i])
    c=deepcopy(d)
if not x in c:
    print("No")
    quit()
c={0}
for i in range(bsize):
    d=set()
    for j in c:
        d.add(j+b[i])
        d.add(j-b[i])
    c=deepcopy(d)
if not y in c:
    print("No")
    quit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
def main():
    s=input()
    x,y=map(int,input().split())
    a=[0]*8000
    b=[0]*8000
    tmp=0
    T=True
    asize=0
    bsize=0
    for i in s:
        if i=="T":
            tmp=1-tmp
            T=True
        elif tmp==0:
            if T:
                asize+=1
                T=False
            a[asize-1]+=1
        else:
            if T:
                bsize+=1
                T=False
            b[bsize-1]+=1
    c={0}
    for i in range(asize):
        d=set()
        if i==0:
            if s[0]=="T":
                d.add(-a[i])
            d.add(a[i])
        else:
            for j in c:
                d.add(j+a[i])
                d.add(j-a[i])
        c=deepcopy(d)
    if not x in c:
        print("No")
        quit()
    c={0}
    for i in range(bsize):
        d=set()
        for j in c:
            d.add(j+b[i])
            d.add(j-b[i])
        c=deepcopy(d)
    if not y in c:
        print("No")
        quit()
    print("Yes")
if __name__=="_main_":
    main()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
s=input()
x,y=map(int,input().split())
a=[0]*8000
b=[0]*8000
tmp=0
T=True
asize=0
bsize=0
for i in s:
    if i=="T":
        tmp=1-tmp
        T=True
    elif tmp==0:
        if T:
            asize+=1
            T=False
        a[asize-1]+=1
    else:
        if T:
            bsize+=1
            T=False
        b[bsize-1]+=1
print(a[:asize])
print(b[:bsize])
c={0}
for i in range(asize):
    d=set()
    if i==0:
        if s[0]=="T":
            d.add(-a[i])
        d.add(a[i])
    else:
        for j in c:
            d.add(j+a[i])
            d.add(j-a[i])
    c=deepcopy(d)
if not x in c:
    print("No")
    quit()
c={0}
for i in range(bsize):
    d=set()
    for j in c:
        d.add(j+b[i])
        d.add(j-b[i])
    c=deepcopy(d)
if not y in c:
    print("No")
    quit()
print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    x, y = map(int, input().split())
    sl = s.split('T')
    dx = sorted(list(map(len, sl[::2])), reverse=True)
    dy = sorted(list(map(len, sl[1::2])), reverse=True)
    nx = 0
    ny = 0
    for xx in dx:
        if x >= nx:
            nx += xx
        else:
            nx -= xx
    for yy in dy:
        if y >= ny:
            ny += yy
        else:
            ny -= yy
    print('YNeos'[nx != x or ny != y::2])


main()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    x,y = f()


    if abs(x)>len(s) and abs(y)>len(s):
        print('No')
        return

    flag = 1
    cnt = 0
    xa = []
    ya = []
    s += 'T'
    for i in s:
        if i == 'T':
            if flag == 1:
                if cnt:
                    xa.append(cnt)
            else:
                if cnt:
                    ya.append(cnt)
            cnt = 0
            flag = flag^1
        else:
            cnt += 1


    xvis = [[0] * 16001 for i in range(2)]

    xflag = 0
    xvis[xflag][8000] = 1

    for i in xa:
        for j in range(16001):
            if xvis[xflag][j] == 1:
                if j-i >= 0:
                    xvis[xflag^1][j-i] = 1
                if j+i<= 16000:
                    xvis[xflag^1][j+i] = 1
        
        xflag = xflag^1

    yvis = [[0] * 16001 for i in range(2)]

    yflag = 0
    yvis[yflag][8000] = 1
    for i in ya:
        for j in range(16001):
            if yvis[yflag][j] == 1:
                if j-i >= 0:
                    yvis[yflag^1][j-i] = 1
                if j+i<= 16000:
                    yvis[yflag^1][j+i] = 1
        
        yflag = yflag^1
    

    if xvis[xflag][x+8000] == 1 and yvis[yflag][y+8000] == 1:
        print('Yes')
    else:
        print('No')



solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    x,y = f()

    flag = 1
    cnt = 0
    xa = []
    ya = []
    s += 'T'
    for i in s:
        if i == 'T':
            if flag == 1:
                if cnt:
                    xa.append(cnt)
            else:
                if cnt:
                    ya.append(cnt)
            cnt = 0
            flag = flag^1
        else:
            cnt += 1
            
        

    xvis = [0] * 8001
    xvis[0] = 1
    for i in xa:
        for j in range(8000, 0, -1):
            if j-i>=0 and xvis[j-i]:
                xvis[j] = 1
    
    yvis = [0] * 8001
    yvis[0] = 1
    for i in ya:
        for j in range(8000, 0, -1):
            if j-i>=0 and yvis[j-i]:
                yvis[j] = 1
    

    if xvis[x] and yvis[y]:
        print('Yes')
    else:
        print('No')


solve()

Submission status: Wrong Answer

Solution code:
from sys import exit
from collections import defaultdict
import itertools
# dic = defaultdict(int)
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
x,y = [int(n) for n in input().split()]

dx = []
dy = []
X = True
tmp = 0

memox = set([0])
memoy = set([0])
S = [len(s) for s in S.split("T")]
dx = S[0::2]
dy = S[1::2]
x -= dx[0]
del dx[0]

def check(d):
    memo = set([0])
    for t in d:
        memo = {a+b for a,b in itertools.product(memo, [-t, t])}




print("Yes" if check(dx) and check(dy) else "No")

Submission status: Wrong Answer

Solution code:
from sys import exit
from collections import defaultdict
# dic = defaultdict(int)
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
x,y = [int(n) for n in input().split()]

dx = []
dy = []
X = True
tmp = 0

memox = defaultdict(int)
memoy = defaultdict(int)
memox[0] = True
memoy[0] = True
for s in S:
    if(s == "F"):
        tmp+=1
    else:
        if X:
            dx.append(tmp)
        else:
            dy.append(tmp)
        X = not X
        tmp = 0
if tmp:
    if X:
        dx.append(tmp)
    else:
        dy.append(tmp)

#X方向のチェック
for tx in dx:
    available = list(memox.keys())
    for k in available:
        memox[k+tx]=True
        memox[k-tx]=True
if not x in memox:
    print("No")
    exit()

#Y方向のチェック
for ty in dy:
    available = list(memox.keys())
    for k in available:
        memoy[k+ty]=True
        memoy[k-ty]=True
if not y in memoy:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
now=0
idx=-1
data=[[],[]]
cnt=0
for s in input():
    if s=='F':
        cnt+=1
    elif s=='T':
        if idx==-1:
            now+=cnt
            cnt=0
            idx=1
        elif idx==0:
            data[0].append(cnt)
            cnt=0
            idx=1
        elif idx==1:
            data[1].append(cnt)
            cnt=0
            idx=0
data[idx].append(cnt)
def solve(target,move):
    dp={0,}
    for m in move:
        dpc=dp.copy()
        dp=set()
        for k in dpc:
            dp|={k-m,k+m}
    if target in dp:
        return True
    return False
x,y=map(int,input().split())
x-=now
if solve(x,data[0]) and solve(y,data[1]):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = [int(i) for i in input().split(" ")]

xl = []
yl = []

s = s + "T"

xf = True
l = 0
for i in range(0, len(s)):
    if s[i] == "T":
        if xf:
            xl.append(l)
            xf = False
            l = 0
        else:
            yl.append(l)
            xf = True
            l = 0
    else:
        l += 1

def p(a, l):
    s = sum(a) + l
    if s < 0 or s % 2 == 1:
        return False
    else:
        dp = [[False for j in range(0, s // 2 + 1)] for i in range(0, len(a) + 1)]
        dp[0][0] = True
        for i in range(1, len(a) + 1):
            for j in range(0, s // 2 + 1):
                dp[i][j] = dp[i - 1][j] or (0 <= j - a[i - 1] and dp[i - 1][j - a[i - 1]])
        return dp[len(a)][s // 2]

if p(xl, x) and p(yl, y):
    print("Yes")
else:
    print("No")