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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    a,b = LI()
    print(math.ceil((a+b)/2))

#B
def B():
    s = S()
    t = S()
    s.sort()
    t.sort()
    t = t[::-1]
    l = [s,t]
    l.sort()
    if s == t:
        print("No")
    elif l[0] == s:
        print("Yes")
    else:
        print("No")
#C
def C():
    n = I()
    d = defaultdict(int)
    a = LI()
    for i in a:
        d[i] += 1
    ans = 0
    for i in d.keys():
        if i <= d[i]:
            ans += d[i]-i
        else:
            ans += d[i]
    print(ans)
#D
def D():
    s = input().split("T")
    x,y = LI()
    a,b = [0,0]
    l = len(s)
    dp_x = [-1 for i in range(17000)]
    dp_y = [-1 for i in range(17000)]
    dp_x[len(s[0])+8000] = 1
    dp_y[8000] = 0
    c,d = [1,0]
    q = deque()
    for i in range(1,l):
        if i%2 == 0:
            k = len(s[i])
            if k > 0:
                for j in range(17000):
                    if dp_x[j] == c:
                        q.append(j)
                c += 1
                while q:
                    j = q.pop()
                    if j+k < 17000:
                        dp_x[j+k] = min(c,dp_x[j]+1)
                    if j-k >= 0:
                        dp_x[j-k] = min(c,dp_x[j]+1)
                print(dp_x[7990:8010])
    for i in range(1,l):
        if i%2 == 1:
            k = len(s[i])
            if k > 0:
                for j in range(17000):
                    if dp_y[j] == d:
                        q.append(j)
                d += 1
                while q:
                    j = q.pop()
                    if j+k < 17000:
                        dp_y[j+k] = min(d,dp_y[j]+1)
                    if j-k >= 0:
                        dp_y[j-k] = min(d,dp_y[j]+1)
    if dp_x[x+8000] == c and dp_y[y+8000] == d:
        print("Yes")
    else:
        print("No")
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    a,b = LI()
    print(math.ceil((a+b)/2))

#B
def B():
    s = S()
    t = S()
    s.sort()
    t.sort()
    t = t[::-1]
    l = [s,t]
    l.sort()
    if s == t:
        print("No")
    elif l[0] == s:
        print("Yes")
    else:
        print("No")
#C
def C():
    n = I()
    d = defaultdict(int)
    a = LI()
    for i in a:
        d[i] += 1
    ans = 0
    for i in d.keys():
        if i <= d[i]:
            ans += d[i]-i
        else:
            ans += d[i]
    print(ans)
#D
def D():
    s = input().split("T")
    x,y = LI()
    a,b = [0,0]
    l = len(s)
    dp_x = [-1 for i in range(17000)]
    dp_y = [-1 for i in range(17000)]
    dp_x[len(s[0])+8000] = 0
    dp_y[8000] = 0
    c,d = [0,0]
    q = deque()
    for i in range(1,l):
        if i%2 == 0:
            k = len(s[i])
            if k > 0:
                c += 1
                for j in range(17000):
                    if dp_x[j] >= 0:
                        q.append(j)
                while q:
                    j = q.pop()
                    if j+k < 17000:
                        dp_x[j+k] = min(c,dp_x[j]+1)
                    if j-k >= 0:
                        dp_x[j-k] = min(c,dp_x[j]+1)
    for i in range(1,l):
        if i%2 == 1:
            k = len(s[i])
            if k > 0:
                d += 1
                for j in range(17000):
                    if dp_y[j] >= 0:
                        q.append(j)
                while q:
                    j = q.pop()
                    if j+k < 17000:
                        dp_y[j+k] = min(d,dp_y[j]+1)
                    if j-k >= 0:
                        dp_y[j-k] = min(d,dp_y[j]+1)
    if dp_x[x+8000] == c and dp_y[y+8000] == d:
        print("Yes")
    else:
        print("No")
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    a,b = LI()
    print(math.ceil((a+b)/2))

#B
def B():
    s = S()
    t = S()
    s.sort()
    t.sort()
    t = t[::-1]
    l = [s,t]
    l.sort()
    if s == t:
        print("No")
    elif l[0] == s:
        print("Yes")
    else:
        print("No")
#C
def C():
    n = I()
    d = defaultdict(int)
    a = LI()
    for i in a:
        d[i] += 1
    ans = 0
    for i in d.keys():
        if i <= d[i]:
            ans += d[i]-i
        else:
            ans += d[i]
    print(ans)
#D
def D():
    s = input().split("T")
    x,y = LI()
    a,b = [0,0]
    l = len(s)
    dp_x = [-1 for i in range(17000)]
    dp_y = [-1 for i in range(17000)]
    dp_x[len(s[0])+8000] = 0
    dp_y[8000] = 0
    c,d = [0,0]

    for i in range(1,l):
        if i%2 == 0:
            k = len(s[i])
            if k > 0:
                c += 1
                for j in range(17000):
                    if dp_x[j] >= 0:
                        if j+k < 17000:
                            dp_x[j+k] = min(c,dp_x[j]+1)
                        if j-k >= 0:
                            dp_x[j-k] = min(c,dp_x[j]+1)
    for i in range(1,l):
        if i%2 == 1:
            k = len(s[i])
            if k > 0:
                d += 1
                for j in range(17000):
                    if dp_y[j] >= 0:
                        if j+k < 17000:
                            dp_y[j+k] = min(d,dp_y[j]+1)
                        if j-k >= 0:
                            dp_y[j-k] = min(d,dp_y[j]+1)
    if dp_x[x+8000] == c and dp_y[y+8000] == d:
        print("Yes")
    else:
        print("No")
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = [str(c) for c in input().strip()]
    X, Y = map(int, input().split())
    F = []
    while len(S) > 0:
        f = 0
        while len(S) > 0 and S[0] == 'F':
            f += 1
            S.pop(0)
        F.append(f)
        if len(S) > 0:
            S.pop(0)

    Fx = []
    Fy = []
    for i in range(len(F)):
        if i % 2 == 0:
            Fx.append(F[i])
        else:
            Fy.append(F[i])

    dpx = [[0]] + [0] * len(Fx)
    for i in range(len(Fx)):
        nx = set()
        for a in dpx[i]:
            nx.add(a + Fx[i])
            nx.add(a - Fx[i])
        dpx[i+1] = nx

    dpy = [[0]] + [0] * len(Fy)
    for i in range(len(Fy)):
        ny = set()
        for a in dpy[i]:
            ny.add(a + Fy[i] )
            ny.add(a - Fy[i])
        dpy[i+1] = ny


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = [str(c) for c in input().strip()]
    X, Y = map(int, input().split())
    F = []
    while len(S) > 0:
        f = 0
        while len(S) > 0 and S[0] == 'F':
            f += 1
            S.pop(0)
        F.append(f)
        if len(S) > 0:
            S.pop(0)

    Fx = []
    Fy = []
    for i in range(len(F)):
        if i % 2 == 0:
            Fx.append(F[i])
        else:
            Fy.append(F[i])

    dpx = [[0]] + [0] * len(Fx)
    for i in range(len(Fx)):
        nx = set()
        for a in dpx[i]:
            nx.add(Fx[i] + a)
            nx.add(Fx[i] - a)
        dpx[i+1] = nx

    dpy = [[0]] + [0] * len(Fy)
    for i in range(len(Fy)):
        ny = set()
        for a in dpy[i]:
            ny.add(Fy[i] + a)
            ny.add(Fy[i] - a)
        dpy[i+1] = ny


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0 or xtar > sum(edge[0]) or ytar > sum(edge[1]):
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    for i in range(xtar+1 - 2*e):
        pre = dx.copy()
        if pre[i] == 1:
            dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    for i in range(ytar+1 - 2*e):
        pre = dy.copy()
        if pre[i] == 1:
            dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
edge = [[], []]
# delete first edge
firstedge = 0
for c in s:
    if c == 'T': break
    else: firstedge += 1
x -= firstedge
dir = 0
cur = 0
for c in s[firstedge:]:
    if c == 'T':
        if cur > 0:
            edge[dir].append(cur)
            cur = 0
        dir = (dir + 1) % 2
    else:
        cur += 1
if cur > 0:
    edge[dir].append(cur)
xtar = sum(edge[0]) + x
ytar = sum(edge[1]) + y
if xtar < 0 or ytar < 0:
    print('No')
    exit()
# partition dp
dx = [0] * (xtar + 1)
dy = [0] * (ytar + 1)
dx[0], dy[0] = 1, 1
for e in edge[0]:
    for i in range(xtar+1 - 2*e):
        pre = dx.copy()
        if pre[i] == 1:
            dx[i+2*e] = 1
    if dx[xtar]: break
for e in edge[1]:
    for i in range(ytar+1 - 2*e):
        pre = dy.copy()
        if pre[i] == 1:
            dy[i+2*e] = 1
    if dy[ytar]: break
if dx[xtar] and dy[ytar]: print('Yes')
else: print('No')

Submission status: Wrong Answer

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

XX=[]
YY=[]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            if b == 0 :
                XX.append(1)
            else :
                YY.append(1)
            renzoku = 1
        else :
            if b == 0 :
                XX[-1] += 1
            else :
                YY[-1] += 1



#print(XY)
#print("LIST OK")

g = len(s) + 2

X = [[0 for i in range(g*2)] for j in range(len(XX))]
Y = [[0 for i in range(g*2)] for j in range(len(YY))]



if len(XX) > 0 :
    X[0][g+XX[0]] = 1
    if s[0] == "T" :
        X[0][g-XX[0]] = 1

    abs1 = 2
    for i in range(1, len(XX)) :
        abs1 = min(abs1+XX[i], g)
        #print(i)
        for j in range(g-abs1, g+abs1) :
            #print(X)
            if j - XX[i] >= 0 and X[i-1][j - XX[i]] == 1 :
                X[i][j] = 1
            if j + XX[i] <= g*2-1 and X[i-1][j + XX[i]] == 1 :
                X[i][j] = 1
#print("X OK")

if len(YY) > 0 :

    Y[0][g+YY[0]] = 1
    Y[0][g-YY[0]] = 1

    abs1 = 2
    for i in range(1, len(YY)) :
        abs1 = min(abs1+YY[i], g)
        for j in range(g-abs1, g+abs1) :
            if j - YY[i] >= 0 and Y[i-1][j - YY[i]] == 1 :
                Y[i][j] = 1
            if j + YY[i] <= g*2-1 and Y[i-1][j + YY[i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XX) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(YY) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")

Submission status: Wrong Answer

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

XX=[]
YY=[]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            if b == 0 :
                XX.append(1)
            else :
                YY.append(1)
            renzoku = 1
        else :
            if b == 0 :
                XX[-1] += 1
            else :
                YY[-1] += 1



#print(XY)
print("LIST OK")

g = len(s) + 2

X = [[0 for i in range(g*2)] for j in range(len(XX))]
Y = [[0 for i in range(g*2)] for j in range(len(YY))]



if len(XX) > 0 :
    X[0][g+XX[0]] = 1
    if s[0] == "T" :
        X[0][g-XX[0]] = 1

    abs1 = 2
    for i in range(1, len(XX)) :
        abs1 = min(abs1+XX[i], g)
        #print(i)
        for j in range(g-abs1, g+abs1) :
            #print(X)
            if j - XX[i] >= 0 and X[i-1][j - XX[i]] == 1 :
                X[i][j] = 1
            if j + XX[i] <= g*2-1 and X[i-1][j + XX[i]] == 1 :
                X[i][j] = 1
print("X OK")

if len(YY) > 0 :

    Y[0][g+YY[0]] = 1
    Y[0][g-YY[0]] = 1

    abs1 = 2
    for i in range(1, len(YY)) :
        abs1 = min(abs1+YY[i], g)
        for j in range(g-abs1, g+abs1) :
            if j - YY[i] >= 0 and Y[i-1][j - YY[i]] == 1 :
                Y[i][j] = 1
            if j + YY[i] <= g*2-1 and Y[i-1][j + YY[i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XX) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(YY) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")

Submission status: Wrong Answer

Solution code:
s = input() + "T"
x, y = map(int, input().split())
X = [[], [0]]
d = 0
t = 0
for i in range(len(s)):
    if s[i] == "F":
        t += 1
    else:
        X[d].append(t)
        d = 1-d
        t = 0
def calc(l):
    if len(l) == 0: return [0] 
    post = [l[0]]
    for i in range(1, len(l)):
        if l[i]:
            pre = post
            post = []
            for j in pre:
                post.append(j+l[i])
                post.append(j-l[i])
            print(pre, post)
    return post

if x in calc(X[0]) and y in calc(X[1]):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input() + "T"
x, y = map(int, input().split())
X = [[], [0]]
d = 0
t = 0
for i in range(len(s)):
    if s[i] == "F":
        t += 1
    else:
        if t: X[d].append(t)
        d = 1-d
        t = 0
def calc(l):
    if len(l) == 0: return [0] 
    post = [l[0]]
    for i in range(1, len(l)):
        pre = post
        post = []
        for j in pre:
            post.append(j+l[i])
            post.append(j-l[i])
    return post

if x in calc(X[0]) and y in calc(X[1]):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]


if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    sax = (sum(xFs)-abs(x))/2
    say = (sum(yFs)-abs(y))/2
    if sax%2 == 0 and say%2 == 0:
        sax = int(sax)
        say = int(say)
        if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]


if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    sax = (sum(xFs)-x)/2
    say = (sum(yFs)-y)/2
    if sax%2 == 0 and say%2 == 0:
        sax = int(sax)
        say = int(say)
        if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]

flag = 0

if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    sax = int((sum(xFs)-x)/2)
    say = int((sum(yFs)-y)/2)
    if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
command = s.split("T")

command_length = len(command)

x_command = []
y_command = []
for i in range(command_length):
    c = len(command[i])
    if i % 2 == 0:
        x_command.append(c)

    else:
        y_command.append(c)

x_command.sort(reverse=True)
y_command.sort(reverse=True)

c_x = 0
c_y = 0
for c in x_command:
    if x - c_x >= 0:
        c_x += c
    else:
        c_x -= c

for c in y_command:
    if y - c_y > 0:
        c_y += c
    else:
        c_y -= c
if c_x == x and c_y == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
command = s.split("T")

command_length = len(command)

x_command = []
y_command = []
for i in range(command_length):
    c = len(command[i])
    if i % 2 == 0:
        x_command.append(c)

    else:
        y_command.append(c)

x_command.sort(reverse=True)
y_command.sort(reverse=True)

c_x = 0
c_y = 0
for c in x_command:
    if x - c_x >= 0:
        c_x += c
    else:
        c_x -= c

for c in y_command:
    if y - c_y >= 0:
        c_y += c
    else:
        c_y -= c
if c_x == x and c_y == y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
x, y = map(int, input().split())
movex = []
movey = []

direc = 0
first = None
for elem in s.split('T'):
    if direc == 0:
        if first is not None:
            movex.append(len(elem))
        else:
            first = len(elem)
        direc = 1
    else:
        movey.append(len(elem))
        direc = 0
x -= first

n = len(s)
dpx = [[False]*(2*n+1) for _ in range(len(movex)+1)]
dpy = [[False]*(2*n+1) for _ in range(len(movey)+1)]
# dpx = -len(s), -len(s)+1, ..., -1, 0, 1, ..., len(s)-1, len(s)

dpx[0][n] = True
dpy[0][n] = True

for i in range(len(movex)):
    for j in range(2*n+1):
        if j-movex[i] >= 0 and j+movex[i] <= 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]] or dpx[i][j+movex[i]]
        if j-movex[i] < 0:
            dpx[i+1][j] = dpx[i][j+movex[i]]
        if j+movex[i] > 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]]
for i in range(len(movey)):
    for j in range(2*n+1):
        if j-movey[i] >= 0 and j+movey[i] <= 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]] or dpy[i][j+movey[i]]
        if j-movey[i] < 0:
            dpy[i+1][j] = dpy[i][j+movey[i]]
        if j+movey[i] > 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]]

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
x, y = map(int, input().split())
movex = []
movey = []

direc = 0
first = None
for elem in s.split('T'):
    if direc == 0:
        if first is not None:
            movex.append(len(elem))
        else:
            first = len(elem)
            direc = 1
    else:
        movey.append(len(elem))
        direc = 0
x -= first

n = len(s)
dpx = [[False]*(2*n+1) for _ in range(len(movex)+1)]
dpy = [[False]*(2*n+1) for _ in range(len(movey)+1)]
# dpx = -len(s), -len(s)+1, ..., -1, 0, 1, ..., len(s)-1, len(s)

dpx[0][n] = True
dpy[0][n] = True

for i in range(len(movex)):
    for j in range(2*n+1):
        if j-movex[i] >= 0 and j+movex[i] <= 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]] or dpx[i][j+movex[i]]
        if j-movex[i] < 0:
            dpx[i+1][j] = dpx[i][j+movex[i]]
        if j+movex[i] > 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]]
for i in range(len(movey)):
    for j in range(2*n+1):
        if j-movey[i] >= 0 and j+movey[i] <= 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]] or dpy[i][j+movey[i]]
        if j-movey[i] < 0:
            dpy[i+1][j] = dpy[i][j+movey[i]]
        if j+movey[i] > 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]]

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

Submission status: Wrong Answer

Solution code:
S = input()
X,Y = map(int,input().split())

S = S+"T"
d,cnt = 0,0
pos = [set([0]),set([0])]
for s in S:
    # 前進
    if s=="F":
        cnt += 1
    # 方向転換
    else:
        # 移動先を全列挙
        if cnt>0:
            temp = set([])
            for p in pos[d]:
                temp.add(p+cnt)
                if pos[0]!=set([0]):
                    temp.add(p-cnt)
            pos[d] = temp
        # 方向転換
        d = (d+1)%2
        cnt = 0

print("Yes" if X in pos[0] and Y in pos[1] else "No")

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
movex = []
movey = []

direc = 0
for elem in s.split('T'):
    if direc == 0:
        movex.append(len(elem))
        direc = 1
    else:
        movey.append(len(elem))
        direc = 0
x -= movex[0]
movex = movex[1:]

n = len(s)
dpx = [[False]*(2*len(s)+1) for _ in range(len(movex)+1)]
dpy = [[False]*(2*len(s)+1) for _ in range(len(movey)+1)]
# dpx = -len(s), -len(s)+1, ..., -1, 0, 1, ..., len(s)-1, len(s)

dpx[0][n] = True
dpy[0][n] = True

for i in range(len(movex)):
    for j in range(2*n+1):
        if j-movex[i] >= 0 and j+movex[i] <= 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]] or dpx[i][j+movex[i]]
        if j-movex[i] < 0:
            dpx[i+1][j] = dpx[i][j+movex[i]]
        if j+movex[i] > 2*n:
            dpx[i+1][j] = dpx[i][j-movex[i]]
for i in range(len(movey)):
    for j in range(2*n+1):
        if j-movey[i] >= 0 and j+movey[i] <= 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]] or dpx[i][j+movey[i]]
        if j-movey[i] < 0:
            dpy[i+1][j] = dpy[i][j+movey[i]]
        if j+movey[i] > 2*n:
            dpy[i+1][j] = dpy[i][j-movey[i]]

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

Submission status: Wrong Answer

Solution code:
S = input()
X,Y = map(int,input().split())

x0 = 0
for s in S:
    if s=="F":
        x0 += 1
    else:
        break

dir = 0
cnt = [0]*2
for i in range(x0,len(S)):
    if S[i]=="F":
        cnt[dir] += 1
    else:
        dir = (dir+1)%2

Ans = "No"
if abs(X-x0)==cnt[0] and abs(Y)==cnt[1]:
    Ans = "Yes"
else:
    if abs(X-x0) <= cnt[0] and abs(Y) <= cnt[1]:
        if (cnt[0]+x0)%2==0 and cnt[1]%2==0:
            Ans = "Yes"

print(Ans)

Submission status: Wrong Answer

Solution code:
S = input()
X,Y = map(int,input().split())

x0 = 0
for s in S:
    if s=="F":
        x0 += 1
    else:
        break

dir = 0
cnt = [0]*2
for i in range(x0,len(S)):
    if S[i]=="F":
        cnt[dir] += 1
    else:
        dir = (dir+1)%2

Ans = "No"
if X==cnt[0]+x0 and Y==cnt[1]:
    Ans = "Yes"
else:
    if abs(X-x0) <= cnt[0] and abs(Y) <= cnt[1]:
        if (cnt[0]+x0)%2==0 and cnt[1]%2==0:
            Ans = "Yes"

print(Ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc082/editorial.pdf
・DPをxとyの2つに分けて行う。
　[step][x] = その時xはその状態になれるか
　[step][y] = その時yはその状態になれるか
・x方向とy方向は独立に考えることができる。
"""

from collections import defaultdict

S = input()
X, Y = map(int, input().split())

S2 = []
tmp = 0
# 連続するF毎にまとまるように文字列Sを変形させる
for i in range(len(S)):
    if S[i] == 'F':
        tmp += 1
    # T毎に区切る
    else:
        S2.append(tmp)
        tmp = 0
S2.append(tmp)

# 文字列がFのみだとこの後のDPできないので別処理
if len(S2) == 1:
    if X in [-S2[0], S2[0]] and Y == 0:
        print('Yes')
    else:
        print('No')
    exit()

# dictならマイナスの添字もそのまま使える
dpx = [defaultdict(int) for _ in range(len(S2))]
dpy = [defaultdict(int) for _ in range(len(S2))]
# xの初期化：step0は右移動、step1ではそのまま
dpx[0][S2[0]] = dpx[1][S2[0]] = 1
# yの初期化：step0は何もなし、step1で上下どちらかに移動
dpy[1][S2[1]] = dpy[1][-S2[1]] = 1
for i in range(2, len(S2)):
    for j in range(-len(S), len(S)+1):
        # 左右に移動する
        if i % 2 == 0:
            # 前回stepに今回step分を+-して到達可能か見る
            dpx[i][j] = dpx[i-1][j-S2[i]] | dpx[i-1][j+S2[i]]
            # xをやる時はyはそのまま
            dpy[i][j] = dpy[i-1][j]
        # 上下に移動する
        else:
            dpx[i][j] = dpx[i-1][j]
            dpy[i][j] = dpy[i-1][j-S2[i]] | dpy[i-1][j+S2[i]]
# 最後のstepでXとYが到達可能ならOK
if dpx[len(S2)-1][X] and dpy[len(S2)-1][Y]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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


def reachable(start, target, lst):

    current = set()
    current.add(start)

    for moves in lst:
        candidates = set()
        for x in current:
            candidates.add(x + moves)
            candidates.add(x - moves)
        current = candidates

    return target in current


def main():
    s = input()
    sa = input().split(' ')
    x = int(sa[0])
    y = int(sa[1])

    x_list = []
    y_list = []
    moves = 0
    move_x = True
    lst = x_list
    for cmd in s:
        if cmd == 'F':
            moves += 1
        else:
            # cmd == 'T'
            if moves != 0:
                lst.append(moves)
            moves = 0
            move_x = not move_x
            lst = x_list if move_x else y_list
    if moves != 0:
        lst.append(moves)

    if 0 < len(x_list):
        x -= x_list[0]
        x_list = x_list[1:]

    if reachable(0, x, x_list) and reachable(0, y, y_list):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]

ansX = [0]
for i in range(0,len(X)):
    if not X[i] == 0:
        ansX = list(set([c+X[i] for c in ansX]+[c-X[i] for c in ansX]))

ansY = [0]
for i in range(0,len(Y)):
    if not Y[i] == 0:
        ansY = list(set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY]))
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]

ansX = set([0])
for i in range(0,len(X)):
    if not X[i] == 0:
        ansX = set([c+X[i] for c in ansX]+[c-X[i] for c in ansX])

ansY = set([0])
for i in range(0,len(Y)):
    if not Y[i] == 0:
        ansY = set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY])
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]
ansX = set([0])
for i in range(0,len(X)):
    ansX = set([c+X[i] for c in ansX]+[c-X[i] for c in ansX])
ansY = set([0])
for i in range(0,len(Y)):
    ansY = set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY])
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")