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

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input().split('T')
    x, y = map(int, input().split())

    X = []
    Y = []
    flag = 0
    for s in S:
        if flag == 0:
            X.append(len(s))
        else:
            Y.append(len(s))
        flag ^= 1
    A = set()
    A.add(0)

    for i in X:
        tmp = set()
        for a in A:
            tmp.add(a + i)
            tmp.add(a - i)
        A = tmp

    if x in A:
        B = set()
        B.add(0)

        for i in Y:
            tmp = set()
            for b in B:
                tmp.add(b + i)
                tmp.add(b - i)
            B = tmp
        if y in B:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input().split('T')
    x, y = map(int, input().split())

    X = []
    Y = []
    flag = 0
    for s in S:
        if flag == 0:
            X.append(len(s))
        else:
            Y.append(len(s))
        flag ^= 1

    A = set()
    A.add(0)

    for i in X:
        tmp = set()
        for a in A:
            tmp.add(a+i)
            tmp.add(a-i)
        A = tmp

    if x in A:
        B = set()
        B.add(0)

        for i in Y:
            tmp = set()
            for b in B:
                tmp.add(b + i)
                tmp.add(b - i)
            B = tmp
        if y in B:
            print('Yes')
        else:
            print('No')
    else:
        print('No')




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    n = 8000
    ml = n*2+1
    odp = [False]*ml
    ndp = [False]*ml
    for i in range(len(ini)):
        odp[ini[i]+n] = True

    for i in range(len(l)):
        for j in range(ml):
            if (j+l[i]) < ml and odp[j]:
                ndp[j+l[i]] = True
            if (j-l[i]) >= 0 and odp[j]:
                ndp[j-l[i]] = True
        odp, ndp = ndp, odp

    return odp[v+n]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [0], [0]
    for i in range(len(f)):
        if len(f[i]) == 0:
            continue
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:

def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    n = 8000
    ml = n*2+1
    odp = [False]*ml
    ndp = [False]*ml
    for i in range(len(ini)):
        ndp[ini[i]+n] = True

    for i in range(len(l)):
        odp, ndp = ndp, odp
        for j in range(ml):
            if (j+l[i]) < ml and odp[j]:
                ndp[j+l[i]] = True
            if (j-l[i]) >= 0 and odp[j]:
                ndp[j-l[i]] = True

    return ndp[v+n]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [0], [0]
    for i in range(len(f)):
        if len(f[i]) == 0:
            continue
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    n = 8000
    ml = n*2+1
    odp = [False]*ml
    ndp = [False]*ml
    for i in range(len(ini)):
        ndp[ini[i]+n] = True

    for i in range(len(l)):
        odp, ndp = ndp, odp
        for j in range(ml):
            if (j+l[i]) < ml and odp[j]:
                ndp[j+l[i]] = True
            if (j-l[i]) >= 0 and odp[j]:
                ndp[j-l[i]] = True

    return ndp[v+n]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    if len(yl) == 0:
        yl.append(0)
    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    n = 8000
    ml = n*2+1
    odp = [False]*ml
    ndp = [False]*ml
    for i in range(len(ini)):
        ndp[ini[i]+n] = True

    for i in range(len(l)):
        odp, ndp = ndp, odp
        for j in range(ml):
            if (j+l[i]) < ml and odp[j]:
                ndp[j+l[i]] = True
            if (j-l[i]) >= 0 and odp[j]:
                ndp[j-l[i]] = True

    return ndp[v+n]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    n = 8000
    ml = n*2+1
    dp = [[False]*ml for i in range(2)]
    for i in range(len(ini)):
        dp[0][ini[i]+n] = True
    oi = 0
    ni = 1-oi
    for i in range(len(l)):
        for j in range(ml):
            if (j+l[i]) < ml and dp[oi][j]:
                dp[ni][j+l[i]] = True
            if (j-l[i]) >= 0 and dp[oi][j]:
                dp[ni][j-l[i]] = True
        oi = 1-oi
        ni = 1-oi
    return dp[oi][v+n]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    ml = 8000*2+1
    dp = [False]*ml
    for i in range(len(ini)):
        dp[ini[i]+8000] = True
    for i in range(len(l)):
        for j in range(ml):
            if (j+l[i]) < ml:
                dp[j+l[i]] = dp[j+l[i]] or dp[j]
            if (j-l[i]) >= 0:
                dp[j-l[i]] = dp[j-l[i]] or dp[j]
    return dp[v+8000]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1

s = s[si:]
if len(s) == 0:
    YesNo(x == si and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    if len(yl) == 0:
        yl.append(0)
    YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    ml = 8000*2+1
    dp = [False]*ml
    for i in range(len(ini)):
        dp[ini[i]+8000] = True
    for i in range(8001):
        for j in [8000-i, 8000+i]:
            if not dp[j]:
                continue
            for k in range(len(l)):
                if (j+l[k]) < ml:
                    dp[j+l[k]] = True
                if (j-l[k]) >= 0:
                    dp[j-l[k]] = True
    return dp[v+8000]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1
    x -= 1

s = s[si:]
if len(s) == 0:
    YesNo(x == 0 and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    if len(yl) == 0:
        yl.append(0)
    YesNo(solve(x, xl, [0]) and solve(y, yl[1:], [-yl[0], yl[0]]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l, ini):
    ml = 8000*2+1
    dp = [False]*ml
    for i in range(len(ini)):
        dp[ini[i]+8000] = True
    for i in range(8001):
        for j in [8000-i, 8000+i]:
            if not dp[j]:
                continue
            for k in range(len(l)):
                if (j+l[k]) < ml:
                    dp[j+l[k]] = True
                if (j-l[k]) >= 0:
                    dp[j-l[k]] = True
    return dp[v+8000]


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

f = s.split('T')
xl, yl = [], []
for i in range(len(f)):
    if i % 2 == 1:
        yl.append(len(f[i]))
    else:
        xl.append(len(f[i]))

if len(xl) == 0:
    xl.append(0)
if len(yl) == 0:
    yl.append(0)


YesNo(solve(x, xl[1:], [xl[0]]) and solve(y, yl[1:], [yl[0], -yl[0]]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def YesNo(b):
    print("Yes" if b else "No")


def solve(v, l):
    dp = [False]*16002
    dp[8000] = True
    for i in range(8001):
        for j in [i-8000, i+8000]:
            if not dp[j]:
                continue
            for k in range(len(l)):
                if (j+l[k]) < 16002:
                    dp[j+l[k]] = True
                if (j-l[k]) >= 0:
                    dp[j-l[k]] = True
    return dp[v+8000]


s = input()
x, y = map(int, input().split())
si = 0
while si < len(s) and s[si] == 'F':
    si += 1
    x -= 1

s = s[si:]
if len(s) == 0:
    YesNo(x == 0 and y == 0)
else:
    f = s.split('T')[1:]
    xl, yl = [], []
    for i in range(len(f)):
        if i % 2 == 0:
            yl.append(len(f[i]))
        else:
            xl.append(len(f[i]))

    YesNo(solve(x, xl) and solve(y, yl))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = str(input())
obj_x, obj_y = list(map(int, input().split()))


x = []
y = []
flag = 0
num = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag % 2 == 0:
            x.append(num)
        else:
            y.append(num)
        flag += 1
        num = 0
    else:
        num += 1

if num > 0:
    if flag % 2 == 0:
        x.append(num)
    else:
        y.append(num)


if x == []:
    x = [0]
if y == []:
    y = [0]


num_x = sum(x)
num_y = sum(y)

max_x = num_x*2+1
max_y = num_y*2+1

dp_x = [[0]*((len(x)+1)) for i in range(max_x)]
dp_y = [[0]*((len(y)+1)) for i in range(max_y)]

dp_x[num_x][0] = 1
dp_y[num_y][0] = 1
dp_x[num_x+x[0]][1]=1

for i in range(0, len(x)):
    num = x[i]
    for j in range(1, len(dp_x)):
        if j+num < max_x:
            dp_x[j+num][i+1] = max(dp_x[j+num][i+1], dp_x[j][i]*1)
        if j-num >= 0:
            dp_x[j-num][i+1] = max(dp_x[j-num][i+1], dp_x[j][i]*1)
        # if dp_x[j][i] == 1:
        #     print(j+num, j-num)
for i in range(0, len(y)):
    num = y[i]
    for j in range(0, len(dp_y)):
        if j+num < max_y:
            dp_y[j+num][i+1] = max(dp_y[j+num][i+1], dp_y[j][i]*1)
        if j-num >= 0:
            dp_y[j-num][i+1] = max(dp_y[j-num][i+1], dp_y[j][i]*1)
        # if dp_y[j][i] == 1:
        #     print(j+num, j-num)


if (num_x+obj_x)<len(dp_x) and (num_x+obj_x)>=0:
    ans_x = dp_x[num_x+obj_x][-1]
else:
    print("No")
    exit()
if (num_y+obj_y)<len(dp_y) and (num_y+obj_y)>=0:
    ans_y = dp_y[num_y+obj_y][-1]
else:
    print("No")
    exit()

# print(dp_x)
if ans_x*ans_y == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = str(input())
obj_x, obj_y = list(map(int, input().split()))


x = []
y = []
flag = 0
num = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag % 2 == 0:
            x.append(num)
        else:
            y.append(num)
        flag += 1
        num = 0
    else:
        num += 1

if num > 0:
    if flag % 2 == 0:
        x.append(num)
    else:
        y.append(num)


if x == []:
    x = [0]
if y == []:
    y = [0]


num_x = sum(x)
num_y = sum(y)

max_x = num_x*2+1
max_y = num_y*2+1

dp_x = [[0]*((len(x)+1)) for i in range(max_x)]
dp_y = [[0]*((len(y)+1)) for i in range(max_y)]

dp_x[num_x][0] = 1
dp_y[num_y][0] = 1
dp_x[num_x+x[0]][1]=1
dp_y[num_y+y[0]][1]=1

for i in range(0, len(x)):
    num = x[i]
    for j in range(1, len(dp_x)):
        if j+num < max_x:
            dp_x[j+num][i+1] = max(dp_x[j+num][i+1], dp_x[j][i]*1)
        if j-num >= 0:
            dp_x[j-num][i+1] = max(dp_x[j-num][i+1], dp_x[j][i]*1)
        # if dp_x[j][i] == 1:
        #     print(j+num, j-num)
for i in range(0, len(y)):
    num = y[i]
    for j in range(1, len(dp_y)):
        if j+num < max_y:
            dp_y[j+num][i+1] = max(dp_y[j+num][i+1], dp_y[j][i]*1)
        if j-num >= 0:
            dp_y[j-num][i+1] = max(dp_y[j-num][i+1], dp_y[j][i]*1)
        # if dp_y[j][i] == 1:
        #     print(j+num, j-num)


if (num_x+obj_x)<len(dp_x) and (num_x+obj_x)>=0:
    ans_x = dp_x[num_x+obj_x][-1]
else:
    print("No")
    exit()
if (num_y+obj_y)<len(dp_y) and (num_y+obj_y)>=0:
    ans_y = dp_y[num_y+obj_y][-1]
else:
    print("No")
    exit()

# print(dp_x)
if ans_x*ans_y == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = str(input())
obj_x, obj_y = list(map(int, input().split()))


x = []
y = []
flag = 0
num = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag % 2 == 0:
            x.append(num)
        else:
            y.append(num)
        flag += 1
        num = 0
    else:
        num += 1

if num > 0:
    if flag % 2 == 0:
        x.append(num)
    else:
        y.append(num)


if x == []:
    x = [0]
if y == []:
    y = [0]


num_x = sum(x)
num_y = sum(y)

max_x = num_x*2+1
max_y = num_y*2+1

dp_x = [[0]*((len(x)+1)) for i in range(max_x)]
dp_y = [[0]*((len(y)+1)) for i in range(max_y)]

dp_x[num_x][0] = 1
dp_y[num_y][0] = 1

for i in range(0, len(x)):
    num = x[i]
    for j in range(0, len(dp_x)):
        if j+num < max_x:
            dp_x[j+num][i+1] = max(dp_x[j+num][i+1], dp_x[j][i]*1)
        if j-num >= 0:
            dp_x[j-num][i+1] = max(dp_x[j-num][i+1], dp_x[j][i]*1)
        # if dp_x[j][i] == 1:
            # print(j+num, j-num)
for i in range(0, len(y)):
    num = y[i]
    for j in range(0, len(dp_y)):

        if j+num < max_y:
            dp_y[j+num][i+1] = max(dp_y[j+num][i+1], dp_y[j][i]*1)
        if j-num >= 0:
            dp_y[j-num][i+1] = max(dp_y[j-num][i+1], dp_y[j][i]*1)
        # if dp_y[j][i] == 1:
            # print(j+num, j-num)


if num_x+obj_x<len(dp_x) and num_x+obj_x>=0:
    ans_x = dp_x[num_x+obj_x][-1]
else:
    print("No")
    exit()
if (num_y+obj_y)<len(dp_y) and (num_y+obj_y)>=0:
    ans_y = dp_y[num_y+obj_y][-1]
else:
    print("No")
    exit()

# print(dp_x)
if ans_x*ans_y == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = str(input())
obj_x, obj_y = list(map(int, input().split()))


x = []
y = []
flag = 0
num = 0
for i in range(len(s)):
    if s[i] == "T":
        if flag % 2 == 0:
            x.append(num)
        else:
            y.append(num)
        flag += 1
        num = 0
    else:
        num += 1

if num > 0:
    if flag % 2 == 0:
        x.append(num)
    else:
        y.append(num)


if x == []:
    x = [0]
if y == []:
    y = [0]

# print(x)
# print(y)

# print(sum(x))
# print(sum(y))
num_x = sum(x)
num_y = sum(y)
# num_x = 8000
# num_y = 8000
max_x = num_x*2+1
max_y = num_y*2+1

dp_x = [[0]*((len(x)+1)) for i in range(max_x)]
dp_y = [[0]*((len(y)+1)) for i in range(max_y)]

dp_x[num_x][0] = 1
dp_y[num_y][0] = 1

for i in range(0, len(x)):
    num = x[i]
    for j in range(0, len(dp_x)):
        if j+num < max_x:
            dp_x[j+num][i+1] = max(dp_x[j+num][i+1], dp_x[j][i]*1)
        if j-num >= 0:
            dp_x[j-num][i+1] = max(dp_x[j-num][i+1], dp_x[j][i]*1)
        # if dp_x[j][i] == 1:
            # print(j+num, j-num)
for i in range(0, len(y)):
    num = y[i]
    for j in range(0, len(dp_y)):

        if j+num < max_y:
            dp_y[j+num][i+1] = max(dp_y[j+num][i+1], dp_y[j][i]*1)
        if j-num >= 0:
            dp_y[j-num][i+1] = max(dp_y[j-num][i+1], dp_y[j][i]*1)
        # if dp_y[j][i] == 1:
            # print(j+num, j-num)

if num_x+obj_x<len(dp_x):
    ans_x = dp_x[num_x+obj_x][-1]
else:
    print("No")
    exit()
if num_y+obj_y<len(dp_y):
    ans_y = dp_y[num_y+obj_y][-1]
else:
    print("No")
    exit()

# print(dp_x)
if ans_x*ans_y == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = str(input()); n = len(s)
gx,gy = map(int,input().split())
Yoko = []; Tate = []
Flag = 0; cnt = 0
Max_x = 0; Max_y = 0
for i in range(n):
  if s[i] == "F":
    cnt += 1
    if i == n-1: #最後なら登録
      if Flag == 0:
        Max_x += cnt
        Yoko.append(cnt)
      else:
        Max_y += cnt
        Tate.append(cnt)      
  else: #T
    if Flag == 0:
      Max_x += cnt
      Yoko.append(cnt)
    else:
      Max_y = cnt
      Tate.append(cnt)
    cnt = 0
    Flag = Flag^1
#print(Yoko,Tate)
MAX_dpx = Max_x*2+1
dp = [0 for _ in range(MAX_dpx)]
dp[Max_x] = 1

for i,x in enumerate(Yoko):
  p = [0 for _ in range(MAX_dpx)]
  p,dp = dp,p
  for j in range(MAX_dpx):
    if i == 0: #i=0の時は右向きだけ
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
    else:
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
      if 0<=j-x<MAX_dpx:
        dp[j-x] = max(dp[j-x], p[j])
  #print(dp)
#print(dp)
#print(gx+Max_x,MAX_dpx)
if gx+Max_x >= MAX_dpx or gx+Max_x < 0 or dp[gx+Max_x] == 0:
  print("No");exit()

MAX_dpy = Max_y*2+1
dp = [0 for _ in range(MAX_dpy)]
dp[Max_y] = 1

for i,y in enumerate(Tate):
  p = [0 for _ in range(MAX_dpy)]
  p,dp = dp,p
  for j in range(MAX_dpy):
    if 0<=j+y<MAX_dpy:
       dp[j+y] = max(dp[j+y], p[j])
    if 0<=j-y<MAX_dpy:
      dp[j-y] = max(dp[j-y], p[j])
  #print(dp)
#print(dp)
if gy+Max_y >= MAX_dpy or gy+Max_y < 0 or dp[gy+Max_y] == 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
S = list(input())
x, y = map(int, input().split())
c = 0
p = 0
q = 0
now = 0
R = []
L = []
for i in range(len(S)):
    if S[i] == "T":
        if p != 0:
            R.append(p)
            p = 0
        elif q != 0:
            L.append(q)
            q = 0
        c += 1
    elif c == 0:
        now += 1
    elif c % 2 == 0:
        p += 1
    else:
        q += 1
if p != 0:
    R.append(p)
if q != 0:
    L.append(q)

dp_x = [[0]*20000 for _ in range(len(R)+2)]
dp_y = [[0]*20000 for _ in range(len(L)+1)]
c = 0
dp_x[0][8000] = 1
dp_y[0][8000] = 1
for i in range(1, len(R)+2):
    for j in range(16001):
        if i == 1:
            if j - now >= 0:
                if dp_x[i-1][j-now] == 1:
                    dp_x[i][j] = 1
            if j + now <= 16001:
                if dp_x[i-1][j+now] == 1:
                    dp_x[i][j] = 1
        else:
            if j - R[i-2] >= 0:
                if dp_x[i-1][j-R[i-2]] == 1:
                    dp_x[i][j] = 1
            if j + R[i-2] <= 16001:
                if dp_x[i-1][j+R[i-2]] == 1:
                    dp_x[i][j] = 1

for i in range(1, len(L)+1):
    for j in range(16001):
        if j - L[i-1] >= 0:
            if dp_y[i-1][j-L[i-1]] == 1:
                dp_y[i][j] = 1
        if j + L[i-1] <= 16001:
            if dp_y[i-1][j+L[i-1]] == 1:
                dp_y[i][j] = 1

if dp_x[len(R)+1][x+8000] == 1 and dp_y[len(L)][y+8000] == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = list(input())
x, y = map(int, input().split())
c = 0
p = 0
q = 0
now = 0
for i in range(len(S)):
    if S[i] == "T":
        c += 1
    elif c == 0:
        now += 1
    elif c % 2 == 0:
        p += 1
    else:
        q += 1
T = {}
K = {}
for i in range(p+1):
    T[now+2*i-p] = 1
for j in range(q+1):
    K[2*j-q] = 1
if x in T and y in K:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = list(input())
x, y = map(int, input().split())
c = 0
p = 0
q = 0
for i in range(len(S)):
    if S[i] == "T":
        c += 1
    elif c % 2 == 0:
        p += 1
    else:
        q += 1
T = {}
K = {}
for i in range(p+1):
    T[2*i-p] = 1
for j in range(q+1):
    K[2*j-q] = 1
if x in T and y in K:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10**9 + 7

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

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

Rob = list(s.split("T"))

X = [len(r) for r in Rob[::2]]
Y = [len(r) for r in Rob[1::2]]

Xst = X[0]
X = X[1:]

if abs(x-Xst) <= sum(X) and abs(y) <= sum(Y):
  f = np.array([1], np.int64)
  for i in X:
    L = [0]*(2*i+1)
    L[0], L[-1] = 1, 1
    f = np.convolve(f, np.array(L, np.int64))
  FlagX = f[abs(x-Xst)+sum(X[1:])]

  g = np.array([1], np.int64)
  for j in Y:
    L = [0]*(2*j+1)
    L[0], L[-1] = 1, 1
    g = np.convolve(g, np.array(L, np.int64))
  print(len(g))
  FlagY = g[abs(y)+sum(Y)]

  if FlagX and FlagY:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10**9 + 7

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

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

Rob = list(s.split("T"))

X = [len(r) for r in Rob[::2]]
Y = [len(r) for r in Rob[1::2]]

Xst = X[0]
X = X[1:]

if abs(x-Xst) <= sum(X) and abs(y) <= sum(Y):
  f = np.array([1], np.int64)
  for i in X:
    L = [0]*(2*i+1)
    L[0], L[-1] = 1, 1
    f = np.convolve(f, np.array(L, np.int64))
  FlagX = f[abs(x-Xst)+sum(X)]

  g = np.array([1], np.int64)
  for j in Y:
    L = [0]*(2*j+1)
    L[0], L[-1] = 1, 1
    g = np.convolve(g, np.array(L, np.int64))
  print(len(g))
  FlagY = g[abs(y)+sum(Y)]

  if FlagX and FlagY:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD = 10**9 + 7

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

s = input()
x, y = map(lambda x: abs(int(x)), input().split())

Rob = list(s.split("T"))

X = sorted([len(r) for r in Rob[::2]])
Y = sorted([len(r) for r in Rob[1::2]])

if x <= sum(X) and y <= sum(Y):
  f = np.array([1], np.int64)
  for i in X:
    L = [0]*(2*i+1)
    L[0], L[-1] = 1, 1
    f = np.convolve(f, np.array(L, np.int64))
  FlagX = f[x+sum(X)]

  g = np.array([1], np.int64)
  for j in Y:
    L = [0]*(2*j+1)
    L[0], L[-1] = 1, 1
    g = np.convolve(g, np.array(L, np.int64))
  FlagY = g[y+sum(Y)]

  if FlagX and FlagY:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from itertools import combinations
def main():
    S = input() + 'T'
    x, y = map(int, input().split())
    #データ加工
    moveX, moveY = [], []
    move ={0:moveX, 1:moveY}
    direct = 0
    step = 0
    for s in S:
        if s == 'T' and step != 0:
            move[direct].append(step)
            direct ^= 1
            step = 0
        else:
            step += 1
    #判定
    if possible(x, moveX[1:], sum(moveX)) and possible(y, moveY, sum(moveY)):
        print('Yes')
    else:
        print('No')


def possible(target, move, furthest):
    for k in range(len(move)+1):
        for c in combinations(move,k):
            if furthest-2*sum(c) == target:
                return True
    return False


main()

Submission status: Wrong Answer

Solution code:
s = list(input())
s.append('T')
X,Y =map(int, input().split())
curX = True
cnt = 0
X_s = []
Y_s = []
for i,c in enumerate(s):
    if c == 'T':
        if curX:
            X_s.append(cnt)
        else:
            Y_s.append(cnt)
        curX = not curX
        cnt=0
    else:
        cnt+=1

init = 0
if s[0] == 'F':
    init = X_s.pop(0)
X -= init

SETX = set([0])
SETY = set([0])
for TX in X_s:
    SETX.add(TX)
    ADD = set()
    for SX in SETX:
        ADD.add(SX+TX)
    SETX = ADD | SETX
for TY in Y_s:
    SETY.add(TY)
    ADD = set()
    for SY in SETY:
        ADD.add(SY+TY)
    SETY = ADD | SETY

MODX = sum(X_s)-X
MODY = sum(Y_s)-Y
# print(SETX, SETY, MODX, MODY)
if MODX % 2 == 0 and MODX//2 in SETX and MODY % 2 == 0 and MODY//2 in SETY:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = list(input())
s.append('T')
X,Y =map(int, input().split())
curX = True
cnt = 0
X_s = []
Y_s = []
for i,c in enumerate(s):
    if c == 'T':
        if curX:
            X_s.append(cnt)
        else:
            Y_s.append(cnt)
        curX = not curX
        cnt=0
    else:
        cnt+=1

init = 0
if s[0] == 'F':
    init = X_s.pop(0)
X -= init

SETX = set([0])
SETY = set([0])
for TX in X_s:
    SETX.add(TX)
    ADD = set()
    for SX in SETX:
        ADD.add(SX+TX)
    SETX = ADD | SETX
for TY in Y_s:
    SETY.add(TY)
    ADD = set()
    for SY in SETY:
        ADD.add(SY+TY)
    SETY = ADD | SETY

MODX = abs(sum(X_s)-X)
MODY = abs(sum(Y_s)-Y)
# print(SETX, SETY, MODX, MODY)s
if MODX % 2 == 0 and MODX//2 in SETX and MODY % 2 == 0 and MODY//2 in SETY:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = list(input())
s.append('T')
X,Y =map(int, input().split())
curX = True
cnt = 0
X_s = []
Y_s = []
for i,c in enumerate(s):
    if c == 'T':
        if curX:
            X_s.append(cnt)
        else:
            Y_s.append(cnt)
        curX = not curX
        cnt=0
    else:
        cnt+=1

init = 0
if s[0] == 'F':
    init = X_s.pop(0)
X -= init

SETX = set([0])
SETY = set([0])
for TX in X_s:
    SETX.add(TX)
    ADD = set()
    for SX in SETX:
        ADD.add(SX+TX)
    SETX = ADD | SETX
for TY in Y_s:
    SETY.add(TY)
    ADD = set()
    for SY in SETY:
        ADD.add(SY+TY)
    SETY = ADD | SETY

MODX = abs(sum(X_s)-X)
MODY = abs(sum(Y_s)-Y)
print(SETX, SETY, MODX, MODY)
if MODX % 2 == 0 and MODX//2 in SETX and MODY % 2 == 0 and MODY//2 in SETY:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = list(input())
s.append('T')
X,Y =map(int, input().split())
curX = True
cnt = 0
X_s = []
Y_s = []
for i,c in enumerate(s):
    if c == 'T':
        if curX:
            X_s.append(cnt)
        else:
            Y_s.append(cnt)
        curX = not curX
        cnt=0
    else:
        cnt+=1

init = 0
if s[0] == 'F':
    init = X_s.pop(0)
X -= init

SETX = set([0])
SETY = set([0])
for TX in X_s:
    SETX.add(TX)
    ADD = set()
    for SX in SETX:
        ADD.add(SX+TX)
    SETX = ADD | SETX
for TY in Y_s:
    SETY.add(TY)
    ADD = set()
    for SY in SETY:
        ADD.add(SY+TY)
    SETY = ADD | SETY

MODX = sum(X_s)-X
MODY = sum(Y_s)-Y

if MODX % 2 == 0 and MODX//2 in SETX and MODY % 2 == 0 and MODY//2 in SETY:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = list(input())
s.append('T')
X,Y =map(int, input().split())
curX = True
cnt = 0
X_s = []
Y_s = []
for i,c in enumerate(s):
    if c == 'T':
        if curX:
            X_s.append(cnt)
        else:
            Y_s.append(cnt)
        curX = not curX
        cnt=0
    else:
        cnt+=1

init = 0
if s[0] == 'F':
    init = X_s.pop(0)
X -= init

SETX = set([0])
SETY = set([0])
for TX in X_s:
    SETX.add(TX)
    ADD = set()
    for SX in SETX:
        ADD.add(SX+TX)
    SETX = ADD | SETX
for TY in Y_s:
    SETY.add(TY)
    ADD = set()
    for SY in SETY:
        ADD.add(SY+TY)
    SETY = ADD | SETY
MODX = sum(X_s)-X
MODY = sum(Y_s)-Y
if MODX % 2 == 0 and MODX//2 in SETX and MODY % 2 == 0 and MODY//2 in SETY:
    print('Yes')
else:
    print('No')