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=map(int,input().split())
Xmove=[]
Ymove=[]
xdist=True
cnt=0
for i in range(len(S)):
  if S[i]=="T":
    if xdist:
      Xmove.append(cnt)
    else:
      Ymove.append(cnt)
    cnt=0
    xdist^=True
  else:
    cnt+=1
if S[-1]=="F":
  if xdist:
    Xmove.append(cnt)
  else:
    Ymove.append(cnt)

x=abs(x)
y=abs(y)
if (sum(Xmove)-x)%2!=0:
  print("No")
  exit(0)
tarX=(sum(Xmove)-x)//2
stack=[]
stack.append([0,0])
ok=False
while stack:
  node=stack.pop()
  ind=node[0]
  dist=node[1]
  if dist==tarX:
    ok=True
    break
  if ind+1<len(Xmove):
    stack.append([ind+1,dist])
    stack.append([ind+1,dist+Xmove[ind]])
    
if not ok:
  print("No")
  exit(0)
  
if (sum(Ymove)-y)%2!=0:
  print("No")
  exit(0)
tarY=(sum(Ymove)-y)//2
stack=[]
stack.append([0,0])
ok=False
while stack:
  node=stack.pop()
  ind=node[0]
  dist=node[1]
  if dist==tarY:
    ok=True
    break
  if ind+1<len(Ymove):
    stack.append([ind+1,dist])
    stack.append([ind+1,dist+Ymove[ind]])

print(("No","Yes")[ok])

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
N = len(s)
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if s[-1]=='F':
  if c%2==0:
    a += [n]
  else:
    b += [n]
sa = sum(a)
sb = sum(b)
dpa1 = [0]*(2*sa+1)
dpa2 = [0]*(2*sa+1)
dpb1= [0]*(2*sb+1)
dpb2 = [0]*(2*sb+1)
dpa1[sa] = 1
dpb1[sb] = 1
if abs(sa)<abs(x) or abs(sb)<abs(y):
  print('No')
  import sys
  sys.exit()

if len(a)%2==0:
  A = dpa1
else:
  A = dpa2
if len(b)%2==0:
  B = dpb1
else:
  B = dpb2

for i in range(len(a)):
  c = a[i]
  if i%2==0:
    for j in range(2*sa+1):
      if dpa1[j]==1:
        dpa1[j] = 0
        dpa2[j-c] = 1
        dpa2[j+c] = 1
  else:
    for j in range(2*sa+1):
      if dpa2[j]==1:
        dpa2[j] = 0
        dpa1[j-c] = 1
        dpa1[j+c] = 1
for i in range(len(b)):
  c = b[i]
  if i%2==0:
    for j in range(2*sb+1):
      if dpb1[j]==1:
        dpb1[j] = 0
        dpb2[j-c] = 1
        dpb2[j+c] = 1
  else:
    for j in range(2*sb+1):
      if dpb2[j]==1:
        dpb2[j] = 0
        dpb1[j-c] = 1
        dpb1[j+c] = 1

if A[x+sa]==1 and B[y+sb]==1:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
N = len(s)
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if c%2==0:
  a += [n]
else:
  b += [n]

sa = sum(a)
sb = sum(b)
dpa1 = [0]*(2*sa+1)
dpa2 = [0]*(2*sa+1)
dpb1= [0]*(2*sb+1)
dpb2 = [0]*(2*sb+1)

dpa1[sa] = 1
dpb1[sb] = 1
if abs(sa)<abs(x) or abs(sb)<abs(y):
  print('No')
  import sys
  sys.exit()

if len(a)%2==0:
  A = dpa1
else:
  A = dpa2
if len(b)%2==0:
  B = dpb1
else:
  B = dpb2

for i in range(len(a)):
  c = a[i]
  if i%2==0:
    for j in range(2*sa+1):
      if dpa1[j]==1:
        dpa1[j] = 0
        dpa2[j-c] = 1
        dpa2[j+c] = 1
  else:
    for j in range(2*sa+1):
      if dpa2[j]==1:
        dpa2[j] = 0
        dpa1[j-c] = 1
        dpa1[j+c] = 1
for i in range(len(b)):
  c = b[i]
  if i%2==0:
    for j in range(2*sb+1):
      if dpb1[j]==1:
        dpb1[j] = 0
        dpb2[j-c] = 1
        dpb2[j+c] = 1
  else:
    for j in range(2*sb+1):
      if dpb2[j]==1:
        dpb2[j] = 0
        dpb1[j-c] = 1
        dpb1[j+c] = 1

if A[x+sa]==1 and B[y+sb]==1:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
N = len(s)
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if c%2==0:
  a += [n]
else:
  b += [n]

sa = sum(a)
sb = sum(b)
dpa1 = [0]*(2*sa+1)
dpa2 = [0]*(2*sa+1)
dpb1= [0]*(2*sb+1)
dpb2 = [0]*(2*sb+1)

dpa1[sa] = 1
dpb1[sb] = 1


if len(a)%2==0:
  A = dpa1
else:
  A = dpa2
if len(b)%2==0:
  B = dpb1
else:
  B = dpb2

for i in range(len(a)):
  c = a[i]
  if i%2==0:
    for j in range(2*sa+1):
      if dpa1[j]==1:
        dpa1[j] = 0
        dpa2[j-c] = 1
        dpa2[j+c] = 1
  else:
    for j in range(2*sa+1):
      if dpa2[j]==1:
        dpa2[j] = 0
        dpa1[j-c] = 1
        dpa1[j+c] = 1
for i in range(len(b)):
  c = b[i]
  if i%2==0:
    for j in range(2*sb+1):
      if dpb1[j]==1:
        dpb1[j] = 0
        dpb2[j-c] = 1
        dpb2[j+c] = 1
  else:
    for j in range(2*sb+1):
      if dpb2[j]==1:
        dpb2[j] = 0
        dpb1[j-c] = 1
        dpb1[j+c] = 1
if abs(sa)<abs(x) or abs(sb)<abs(y):
  print('No')
elif A[x+sa]==1 and B[y+sb]==1:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
N = len(s)
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if c%2==0:
  a += [n]
else:
  b += [n]

dpa = [[0]*(2*sum(a)+1) for i in range(len(a)+1)]
dpb = [[0]*(2*sum(b)+1) for i in range(len(b)+1)]

dpa[0][sum(a)] = 1
dpb[0][sum(b)] = 1

for i in range(1,len(a)+1):
  c = a[i-1]
  for j in range(2*sum(a)+1):
    if dpa[i-1][j]==1:
      if j>=c:
        dpa[i][j-c] = 1
      if j<=2*sum(a)-c:
        dpa[i][j+c] = 1
for i in range(1,len(b)+1):
  c = b[i-1]
  for j in range(2*sum(b)+1):
    if dpb[i-1][j]==1:
      if j>=c:
        dpb[i][j-c] = 1
      if j<=2*sum(b)-c:
        dpb[i][j+c] = 1
if sum(a)<x or sum(b)<y:
  print('No')
elif dpa[-1][x+sum(a)]==1 and dpb[-1][y+sum(b)]==1:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
s = input()
x, y = map(int, input().split())
import sys
start = 0
xy = [0, 0]
t = 0
for i in range(len(s)):
    if s[i] == "T":
        t += 1
    else:
        if t == 0:
            start += 1
        else:
            xy[t%2] += 1

if x < 0:
    if start - x > xy[0]:
        print("No")
        sys.exit(0)

xy[0] -= abs(x)
xy[0] += start
xy[1] -= abs(y)

if xy[0] >= 0 and xy[1] >= 0 and xy[0] % 2 == 0 and xy[1] % 2 == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from pprint import pprint
# 盤面座標は8000x8000(x 2)
N = 8000

s = input()
target_x, target_y = map(int, input().split())

# "FTTFF" -> [1, 0, 2]と変換。'F1TF0TF2T'のこと
dat_f = [len(Fcount) for Fcount in s.split("T")]

# x, yの閾値判定するのが面倒なので倍用意する(index error対策)
# マイナスを含むxとyのDP用配列を作る +1するのは原点用
curmap_x = [False] * ((N * 2 * 2) + 1)
curmap_y = [False] * ((N * 2 * 2) + 1)
nextmap_x = [False] * ((N * 2 * 2) + 1)
nextmap_y = [False] * ((N * 2 * 2) + 1)

# 初期座標 0,0
curmap_x[N * 2] = True
curmap_y[N * 2] = True

# 今がx軸かの判定
direction_x = True

for i in range(len(dat_f)):
    step = dat_f[i]
    #print("go: {0}".format(step))
    if direction_x:
        for j in range(N, N + (N * 2) + 1):
            nextmap_x[j] = True if curmap_x[j - step] or curmap_x[j + step] else False
        curmap_x, nextmap_x = nextmap_x, curmap_x
    else:
        for j in range(N, N + (N * 2) + 1):
            nextmap_y[j] = True if curmap_y[j - step] or curmap_y[j + step] else False
        curmap_y, nextmap_y = nextmap_y, curmap_y

    #print("turn")
    direction_x = not direction_x

print("Yes" if curmap_x[N * 2 + target_x] and curmap_y[N * 2 + target_y] else "No")

Submission status: Wrong Answer

Solution code:
from pprint import pprint
# 盤面座標は8000x8000(x 2)
N = 8000

s = input()
target_x, target_y = map(int, input().split())

# "FTTFF" -> [1, 0, 2]と変換。'F1TF0TF2T'のこと
dat_f = [len(Fcount) for Fcount in s.split("T")]

# x, yの閾値判定するのが面倒なので倍用意する(index error対策)
# マイナスを含むxとyのDP用配列を作る +1するのは原点用
curmap_x = [False] * ((N * 2 * 2) + 1)
curmap_y = [False] * ((N * 2 * 2) + 1)
nextmap_x = [False] * ((N * 2 * 2) + 1)
nextmap_y = [False] * ((N * 2 * 2) + 1)

# 初期座標 0,0
curmap_x[N * 2] = True
curmap_y[N * 2] = True

# 今がx軸かの判定
direction_x = True

for i in range(len(dat_f)):
    step = dat_f[i]
    #print("go: {0}".format(step))
    if direction_x:
        for j in range(N, N + (N * 2) + 1):
            nextmap_x[j] = True if curmap_x[j - step] or curmap_x[j + step] else False
        curmap_x, nextmap_x = nextmap_x, curmap_x
    else:
        for j in range(N, N + (N * 2) + 1):
            nextmap_y[j] = True if curmap_y[j - step] or curmap_y[j + step] else False
        curmap_y, nextmap_y = nextmap_y, curmap_y

    #print("turn")
    direction_x = not direction_x

print("Yes" if curmap_x[N * 2 + target_x] and curmap_y[N * 2 + target_y] else "No")

Submission status: Wrong Answer

Solution code:
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):
    dp=[[0]*16001 for _ in range(len(a))]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-8001,8001):
            dp[i][j-p]+=dp[i-1][j]
            dp[i][j+p]+=dp[i-1][j]
            #print(dp)
            if dp[i][G]>=1:
                return True
    return False
    """#print(a)
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    #print(dp)
    if G in dp:
        return True
    return False"""

x=[]
y=[0]
flg=1
cnt=0
if s[0]=="T":
    x.append(0)
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if flg==1:
            x.append(cnt)
            flg*= -1
            cnt=0
        else:
            y.append(cnt)
            flg*= -1
            cnt=0
if flg==1:
    x.append(cnt)
else:
    y.append(cnt)
#print(x)
#print(y)
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):
    """dp=[[0]*16001 for _ in range(len(a))]
    dp[0][a[0]]=1
    for i in range(1,len(a)):

        for j in range(-8001,8001):
            dp[i][j-a[i]]+=dp[i-1][j]
            dp[i][j+a[i]]+=dp[i-1][j]
            #print(dp)
            if dp[i][G]>=1:
                return True
    return False"""
    #print(a)
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    #print(dp)
    if G in dp:
        return True
    return False

x=[]
y=[0]
flg=1
cnt=0
if s[0]=="T":
    x.append(0)
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if flg==1:
            x.append(cnt)
            flg*= -1
            cnt=0
        else:
            y.append(cnt)
            flg*= -1
            cnt=0
if flg==1:
    x.append(cnt)
else:
    y.append(cnt)
#print(x)
#print(y)
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=input()
X,Y=map(int,input().split())
def solve(a,G):
    dp=[[0]*16001 for _ in range(len(a))]
    dp[0][a[0]]=1
    for i in range(1,len(a)):

        for j in range(-8001,8001):
            dp[i][j-a[i]]+=dp[i-1][j]
            dp[i][j+a[i]]+=dp[i-1][j]
            #print(dp)
            if dp[i][G]>=1:
                return True
    return False

x=[]
y=[0]
flg=1
cnt=0
if s[0]=="T":
    x.append(0)
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if flg==1:
            x.append(cnt)
            flg*= -1
            cnt=0
        else:
            y.append(cnt)
            flg*= -1
            cnt=0
if flg==1:
    x.append(cnt)
else:
    y.append(cnt)
#print(x)
#print(y)
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

x_axis = 1 << 8000
y_axis = 1 << 8000
first = True
axis = 0  # 0 = x, 1 = y

for s in S:
    if s == 'T':
        axis = 1 - axis  # 軸が変わる
        first = False

    else:
        if axis == 0:
            if first:
                x_axis = x_axis << 1
            else:
                x_axis = (x_axis << 1) | (x_axis >> 1)
        else:
            y_axis = (y_axis << 1) | (y_axis >> 1)

if (x_axis >> (8000+x)) & 1 and (y_axis >> (8000+y)) & 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

x_axis = 1 << 8000
y_axis = 1 << 8000

axis = 0  # 0 = x, 1 = y
for s in S:
    if s == 'T':
        axis = 1 - axis  # 軸が変わる

    else:
        if axis == 0:
            x_axis = (x_axis << 1) | (x_axis >> 1)
        else:
            y_axis = (y_axis << 1) | (y_axis >> 1)

if (x_axis >> (8000-x)) & 1 and (y_axis >> (8000-y)) & 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys


s = sys.stdin.readline().rstrip()
x, y = map(int, sys.stdin.readline().split())

def reachable(deltas, goal):
    if not deltas:
        if goal == 0:
            return True
        else:
            return False
    
    s = sum(deltas)
    if goal < -s or s < goal:
        return False

    if (s - goal) & 1:
        return False

    a = (s - goal) // 2

    res = [False] * (a + 1)
    res[0] = True
    for d in deltas:
        for i in range(a+1):
            if res[i] and i + d <= a:
                res[i+d] = True
    return res[a]

def main():
    gx = x; gy = y
    dx = []
    dy = []
    direction = 0

    origin_x = 0
    for i in s:
        if i == 'T':
            break
        origin_x += 1
    gx -= origin_x

    tmp = 0
    for i in s[origin_x:] + 'T':
        if i == 'T':
            if direction == 0:
                if tmp != 0:
                    dx.append(tmp)
                direction = 1
            else:
                if tmp != 0:
                    dy.append(tmp)
                direction = 0
            tmp = 0
        else:
            tmp += 1

    return 'Yes' if reachable(dx, gx) & reachable(dy, gy) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().rstrip()
x, y = map(int, sys.stdin.readline().split())

def reachable(deltas, goal):
    if not deltas:
        if goal == 0:
            return True
        else:
            return False
    
    s = sum(deltas)
    if goal < -s or s < goal:
        return False

    res = [False] * (s * 2 + 1) 
    res[s] = True
    
    for d in deltas:
        prev = res.copy()
        for i in range(s*2+1):
            if prev[i]:
                res[i+d] = res[i-d] = True

    return res[s + goal]


def main():
    return 'Yes' # check
    
    gx = x; gy = y
    dx = []
    dy = []
    direction = 0

    origin_x = 0
    for i in s:
        if i == 'T':
            break
        origin_x += 1
    gx -= origin_x

    tmp = 0
    for i in s[origin_x:] + 'T':
        if i == 'T':
            if direction == 0:
                if tmp != 0:
                    dx.append(tmp)
                direction = 1
            else:
                if tmp != 0:
                    dy.append(tmp)
                direction = 0
            tmp = 0
        else:
            tmp += 1

    return 'Yes' if reachable(dx, gx) & reachable(dy, gy) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

s = sys.stdin.readline().rstrip()
x, y = map(int, sys.stdin.readline().split())

def reachable(deltas, goal):
    if not deltas:
        if goal == 0:
            return True
        else:
            return False
    
    s = sum(deltas)
    if goal < -s or s < goal:
        return False
        
    res = [False] * (s * 2 + 1) 
    res[s] = True
    
    for d in deltas:
        prev = res.copy()
        for i in range(s*2+1):
            if prev[i]:
                res[i+d] = res[i-d] = True

    return res[s + goal]


def main():
    gx = x; gy = y
    dx = []
    dy = []
    direction = 0

    origin_x = 0
    for i in s:
        if i == 'T':
            break
        origin_x += 1
    gx -= origin_x

    tmp = 0
    for i in s[origin_x:] + 'T':
        if i == 'T':
            if direction == 0:
                if tmp != 0:
                    dx.append(tmp)
                direction = 1
            else:
                if tmp != 0:
                    dy.append(tmp)
                direction = 0
            tmp = 0
        else:
            tmp += 1

    return 'Yes' if reachable(dx, gx) & reachable(dy, gy) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input().split("T"))
x, y = map(int, input().split())
s2 = [len(x) for x in s]
LR = [s2[i] for i in range(len(s2)) if i % 2 == 0]
UD = [s2[i] for i in range(len(s2)) if i % 2 == 1]

flag = False
tmp = 1
tmp = tmp << sum(LR)
for d in LR:
    tmp = tmp << d | tmp >> d

if x >= 0:
    tmp = tmp >> sum(LR)
    if (tmp >> x) % 2 == 1:
        flag = True
else:
    if sum(LR) + x >= 0:
        if (tmp >> (sum(LR) + x)) % 2 == 1:
            flag = True
if flag:

    tmp = 1
    tmp = tmp << sum(UD)
    flag = False
    for d in UD:
        tmp = tmp << d | tmp >> d
    if y >= 0:
        tmp = tmp >> sum(UD)
        if (tmp >> y) % 2 == 1:
            flag = True
    else:
        if sum(UD) + y >= 0:
            if (tmp >> (sum(UD) + y)) % 2 == 1:
                flag = True

if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)


if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")   
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
    dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(Xsum+2):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(Ysum+2):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
    #if (dpy[len(ylist)][gy1] or dpy[len(ylist)][gy2]) and (dpx[len(xlist)][gx1] or dpx[len(xlist)][gx2]):

Submission status: Wrong Answer

Solution code:
import copy

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

X = []
Y = []
l = 0
f = 0
A = s + 'T'
for a in A:
  if a == 'T':
    if f == 0:
      X.append(l)
    else:
      Y.append(l)
    f = 1-f
    l = 0
  else:
    l += 1

def pattern(P):
  Q = set()
  Q.add(0)
  for p in P:
    QQ = set()
    for q in Q:
      QQ.add(q+p)
      QQ.add(q-p)
    Q = copy.copy(QQ)
  return Q

XX = pattern(X)
YY = pattern(Y)
if x in XX and y in YY:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
f,*l=map(len,input().split("T"))
x,y=map(int,input().split())
z=8000;bx=1<<f+z;by=1<<z
for dy,dx in zip(*[iter(l)]*2):bx=bx<<dx|bx>>dx;by=by<<dy|by>>dy
print("NYoe s"[bx&(1<<x+z) and by&(1<<y+z)::2])

Submission status: Wrong Answer

Solution code:
f,*l=map(len,input().split("T"))
x,y=map(int,input().split())
z=8000;bx=1<<f+z;by=1<<z
for dx,dy in zip(*[iter(l)]*2):bx=bx<<dx|bx>>dx;by=by<<dy|by>>dy
print("NYoe s"[bx&(1<<x+z) and by&(1<<y+z)::2])

Submission status: Wrong Answer

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+2):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+2):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < gx or sum(y_d) < gy:
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# D - FT Robot

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

f = [len(x) for x in s.split("T")]
x -= f[0]
fx = f[2::2]
fy = f[1::2]

x_possible_set = set([0])
for dx in fx:
    x_possible_set = set([xi + dx for xi in x_possible_set] + [xi - dx for xi in x_possible_set])

y_possible_set = set([0])
for dy in fy:
    y_possible_set = set([yi + dy for yi in y_possible_set] + [yi - dy for yi in y_possible_set])
print(y_possible_set)
print("Yes" if x in x_possible_set and y in y_possible_set else "No")

Submission status: Wrong Answer

Solution code:
import itertools
S=str(input())
x,y=map(int,input().split())
Move=[]#偶数番目がｘ軸の移動量、奇数番目がy軸の移動量
c=0
for i in range(len(S)):
  if S[i]=='T':
    Move += [c]
    c=0
  else:
    c+=1
    if i ==len(S)-1:
      Move +=[c]
Move_x=Move[::2]
Move_y=Move[1::2]

hantei_x=False

for p in itertools.product([0,1],repeat=len(Move_x)):
  goal_x=0
  for i in range(len(Move_x)):
    if p[i]==0:
      goal_x +=Move_x[i]
    else:
      goal_x -=Move_x[i]
  if x==goal_x:
    hantei_x=True
    break
    
hantei_y=False

for p in itertools.product([0,1],repeat=len(Move_y)):
  goal_y=0
  for i in range(len(Move_y)):
    if p[i]==0:
      goal_y +=Move_y[i]
    else:
      goal_y -=Move_y[i]
  if x==goal_x:
    hantei_y=True
    break
print('Yes' if hantei_x and hantei_y else 'No')

Submission status: Wrong Answer

Solution code:
import sys
import re
s = input()
x, y = [int(i) for i in sys.stdin.readline().split()]
s = [len(i) for i in re.split("T", s)]
v_ls = s[1::2]
h_ls = s[::2]
x -= h_ls[0]
h_ls.pop(0)
v_sum = sum(v_ls)
h_sum = sum(h_ls)
que = [(0, 0)]
# memo_v_ls[i][j] : i番目まででj - v_sumができるか
width = max(abs(y), v_sum)
memo_v_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(v_ls) + 1)]
memo_v_ls[0][width] = 1
for j, v in enumerate(v_ls, 1):
    for i in range(width * 2 + 1):
        if i >= v and i <= 2 * width - v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i], memo_v_ls[j - 1][i + v])
        elif i >= v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i])
        elif i <= 2 * width - v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i], memo_v_ls[j - 1][i + v])
        else:
            memo_v_ls[j][i] = memo_v_ls[j - 1][i]

flg = memo_v_ls[-1][y + width] == 1

width = max(abs(x), h_sum)
memo_h_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(h_ls) + 1)]
memo_h_ls[0][width] = 1
for j, h in enumerate(h_ls, 1):
    for i in range(width * 2 + 1):
        if i >= h and i <= 2 * width - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i], memo_h_ls[j - 1][i + h])
        elif i >= h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i])
        elif i <= 2 * width - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i], memo_h_ls[j - 1][i + h])
        else:
            memo_h_ls[j][i] = memo_h_ls[j - 1][i]

flg &= memo_h_ls[-1][x + width] == 1
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import re
s = input()
x, y = [int(i) for i in sys.stdin.readline().split()]
s = [len(i) for i in re.split("T", s)]
v_ls = s[1::2]
h_ls = s[::2]
x -= h_ls[0]
h_ls.pop(0)
v_sum = sum(v_ls)
h_sum = sum(h_ls)
que = [(0, 0)]
# memo_v_ls[i][j] : i番目まででj - v_sumができるか
width = max(abs(y), v_sum)
memo_v_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(v_ls) + 1)]
memo_v_ls[0][width] = 1
for j, v in enumerate(v_ls, 1):
    for i in range(width * 2 + 1):
        if i >= v and i <= width - v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i], memo_v_ls[j - 1][i + v])
        elif i >= v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i])
        elif i <= width - v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i], memo_v_ls[j - 1][i + v])
        else:
            memo_v_ls[j][i] = memo_v_ls[j - 1][i]

flg = memo_v_ls[-1][y + width] == 1

width = max(abs(x), h_sum)
memo_h_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(h_ls) + 1)]
memo_h_ls[0][width] = 1
for j, h in enumerate(h_ls, 1):
    for i in range(width * 2 + 1):
        if i >= h and i <= width - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i], memo_h_ls[j - 1][i + h])
        elif i >= h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i])
        elif i <= width - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i], memo_h_ls[j - 1][i + h])
        else:
            memo_h_ls[j][i] = memo_h_ls[j - 1][i]

flg &= memo_h_ls[-1][x + width] == 1
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import re
s = input()
x, y = [int(i) for i in sys.stdin.readline().split()]
s = [len(i) for i in re.split("T", s)]
v_ls = s[1::2]
h_ls = s[::2]
x -= h_ls[0]
h_ls.pop(0)
v_sum = sum(v_ls)
h_sum = sum(h_ls)
que = [(0, 0)]
# memo_v_ls[i][j] : i番目まででj - v_sumができるか
width = max(abs(y), v_sum)
memo_v_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(v_ls) + 1)]
memo_v_ls[0][width] = 1
for j, v in enumerate(v_ls, 1):
    for i in range(width * 2 + 1):
        if i >= v and i <= v_sum - v:
            memo_v_ls[j][i] = max(memo_v_ls[j-1][i-v], memo_v_ls[j-1][i], memo_v_ls[j-1][i+v])
        elif i >= v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i])
        elif i <= v_sum - v:
            memo_v_ls[j][i] = max(memo_v_ls[j - 1][i - v], memo_v_ls[j - 1][i + v])
        else:
            memo_v_ls[j][i] = memo_v_ls[j - 1][i]

flg = memo_v_ls[-1][y + width] == 1

width = max(abs(x), h_sum)
memo_h_ls = [[0 for i in range(width * 2 + 1)] for j in range(len(h_ls) + 1)]
memo_h_ls[0][width] = 1
for j, h in enumerate(h_ls, 1):
    for i in range(width * 2 + 1):
        if i >= h and i <= h_sum - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i], memo_h_ls[j - 1][i + h])
        elif i >= h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i])
        elif i <= h_sum - h:
            memo_h_ls[j][i] = max(memo_h_ls[j - 1][i - h], memo_h_ls[j - 1][i + h])
        else:
            memo_h_ls[j][i] = memo_h_ls[j - 1][i]

flg &= memo_h_ls[-1][x + width] == 1
if flg:
    print("Yes")
else:
    print("No")