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:
#!python3

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


def forward(st):
    ret = set()
    for v in st:
        ret.add(v + 1)
        ret.add(v - 1)
    return ret


def main():
    xset, yset = {0}, {0}
    side = True
    for s in S:
        if s == "F":
            if side:
                xset = forward(xset)
            else:
                yset = forward(yset)
        else:
            side = not side
    
    ans = "Yes" if X in xset and Y in yset else "No"
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

X, Y = {next(S)}, {0}
XY = [X, Y]
for i, d in enumerate(S, 1):
    A = XY[i % 2]
    A |= {a + d for a in A} | {a - d for a in A}

if x in X and y in Y:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
s=list(input())
x,y=map(int,input().split())
f=0
t=0
s.append('T')
n=len(s)
xl=[]
yl=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else:
        if f>0:
            if t%2==0:
                xl.append(f)
            else:
                yl.append(f)
            f=0
        t+=1
def solve(x,l):
    n=len(l)
    k=2*8000+1
    dp=[[-1 for p in range(k)] for q in range(n+1)]
    dp[0][k//2]=0
    for i in range(1,n+1):
        for j in range(k):
            if dp[i-1][j]>=0:
                dp[i][j-l[i-1]]=1
                dp[i][j+l[i-1]]=1
                #print(j)
    if dp[-1][x+k//2]>=0:
        return True
    else:
        return False
if solve(x,xl) and solve(y,yl):
    print('Yes')
else:
    print('No')
#print(xl,yl)

Submission status: Wrong Answer

Solution code:
s=list(input())
x,y=map(int,input().split())
f=0
t=0
s.append('T')
n=len(s)
xl=[]
yl=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else:
        if f>0:
            if t%2==0:
                xl.append(f)
            else:
                yl.append(f)
            f=0
        t+=1
def solve(x,l):
    n=len(l)
    k=2*8000+1
    dp=[[-1 for p in range(k)] for q in range(n+1)]
    dp[0][k//2]=0
    for i in range(1,n+1):
        for j in range(k):
            if dp[i-1][j]>=0:
                dp[i][j-l[i-1]]=1
                dp[i][j+l[i-1]]=1
    if dp[n][x]>=0:
        return True
    else:
        return False
if solve(x,xl) and solve(y,yl):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=list(input())
x,y=map(int,input().split())
f=0
t=0
s.append('T')
n=len(s)
xl=[]
yl=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else:
        if t%2==0:
            xl.append(f)
        else:
            yl.append(f)
        f=0
        t+=1
def solve(x,l):
    n=len(l)
    k=2*8000+1
    dp=[[-1 for p in range(k)] for q in range(n+1)]
    dp[0][k//2]=0
    for i in range(1,n+1):
        for j in range(k):
            if dp[i-1][j]>=0:
                dp[i][j-l[i-1]]=1
                dp[i][j+l[i-1]]=1
    if dp[n][x]>=0:
        return True
    else:
        return False
if solve(x,xl) and solve(y,yl):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=list(input())
x,y=map(int,input().split())
f=0
t=0
s.append('T')
n=len(s)
xl=[]
yl=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else:
        if t%2==0:
            xl.append(f)
        else:
            yl.append(f)
        f=0
        t+=1
def solve(x,l):
    n=len(l)
    k=2*8000+1
    dp=[[-1 for p in range(k)] for q in range(n+1)]
    dp[0][k//2]=0
    for i in range(1,n+1):
        for j in range(k):
            if dp[i][j]>=0:
                dp[i+1][j-l[i]]=1
                dp[i+1][j+l[i]]=1
    if dp[n][x]>=0:
        return True
    else:
        return False
if solve(x,xl) and solve(y,yl):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s=list(input())
x,y=map(int,input().split())
f=0
t=0
s.append('T')
n=len(s)
xl=[]
yl=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else:
        if t%2==0:
            xl.append(f)
        else:
            yl.append(f)
        f=0
        t+=1
def solve(x,l):
    n=len(l)
    k=2*8000+1
    dp=[[-1 for p in range(k)] for q in range(n+1)]
    dp[0][k//2]=0
    for i in range(1,n+1):
        for j in range(k):
            if dp[i][j]==i:
                dp[i+1][j-l[i]]=i
    if dp[n][x]>0:
        return True
    else:
        return False
if solve(x,xl) and solve(y,yl):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
s = input().strip()
Xs = list(map(int, input().split()))
bs = [[],[]]
bb=t=0
for c in s:
    if c == 'T':
        bs[bb].append(t)
        bb=1-bb
        t = 0
    else:
        t += 1
bs[bb].append(t)
for i in range(2):
    t = 1<<8000
    for x in bs[i]:
        t = (t<<x) | (t>>x)
    if not (t>>(Xs[i]+8000))%2:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for i in range(len(s)):
    if s[i]=='F':
        buf+=1
    else:
        if buf!=0:
            dp[t].append(buf)
            buf=0
        t=1-t
#print(s)  
#print(dp)
xb=1<<(len(s))
yb=1<<(len(s))

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x)==0:
    print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y)==0:
    #print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for i in range(len(s)):
    if s[i]=='F':
        buf+=1
    else:
        if buf!=0:
            dp[t].append(buf)
            buf=0
        t=1-t
#print(s)  
#print(dp)
xb=1<<(len(s))
yb=1<<(len(s))

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x)==0:
    #print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y)==0:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for i in range(len(s)):
    if s[i]=='F':
        buf+=1
    else:
        if buf!=0:
            dp[t].append(buf)
            buf=0
        t=1-t
        
#print(dp)
xb=1<<(len(s)+1)
yb=1<<(len(s)+1)

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x+1)==0:
    print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y+1)==0:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for i in range(len(s)):
    if s[i]=='F':
        buf+=1
    else:
        dp[t].append(buf)
        t=1-t
        buf=0
#print(dp)
xb=1<<(len(s)+1)
yb=1<<(len(s)+1)

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x+1)==0:
    print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y+1)==0:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for i in range(len(s)):
    if s[i]=='F':
        buf+=1
    else:
        dp[t].append(buf)
        t=1-t
        buf=0
#print(dp)
xb=1<<len(s)
yb=1<<len(s)

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x)==0:
    print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y)==0:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False

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

if S_str[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif(sorted([iniF]+xS), difx) if iniF !=0 else   exist_dif(xS, difx) 
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(sorted([-iniF]+xS), difx) if iniF !=0 else   exist_dif(xS, difx) 

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False

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

if S_str[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif(sorted([iniF]+xS), difx) if iniF !=0 else   exist_dif(xS, difx) 
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(sorted([-iniF]+xS), difx) if iniF !=0 else   exist_dif(xS, difx) 

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False

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

if S_str[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif(sorted([iniF]+xS), difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(sorted([-iniF]+xS), difx)

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False

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

if S_str[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif([iniF]+xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif([-iniF]+xS, difx)

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())

if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)

xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif([iniF]+xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif([-iniF]+xS, difx)

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())

if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)


xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS+iniF - x
    if difx%2==0:
      xflag = exist_dif([iniF]+xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif([-iniF]+xS, difx)

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

def exist_dif(inputS, difx):
  tmpi = bisect.bisect(inputS,difx//2)
  #print(inputS, difx, tmpi)
  
  if inputS[0] == difx//2:
    return True

  tmp_acmS = list(accumulate(inputS[:min(tmpi,len(inputS))]))

  len_tmp_acmS = len(tmp_acmS)
  for i in range(len_tmp_acmS):
    for j in range(i+1,len_tmp_acmS):
      if tmp_acmS[j]-tmp_acmS[i]==difx//2:
        return True
  return False
        
S = input().split('T')
x,y = map(int,input().split())

if S[0] == 'F':
  iniF = len(S[0])
  xS = sorted([len(s) for s in S[2::2]]) if len(S) > 2 else []
else:
  iniF = 0
  xS = sorted([len(s) for s in S[::2]])
  
yS = sorted([len(s) for s in S[1::2]]) if len(S) > 1 else []

sumxS = sum(xS)
sumyS = sum(yS)


xflag = False
if len(xS) == 0:
  if iniF == x: xflag = True
elif x >=0:
  if sumxS+iniF == x:
    xflag = True
  elif sumxS+iniF > x:
    difx = sumxS - x
    if difx%2==0:
      xflag = exist_dif(xS, difx)              
else:
  if sumxS-iniF == -x:
    xflag = True
  elif sumxS-iniF > -x:
    difx = sumxS-iniF + x
    if difx%2==0:
      xflag = exist_dif(xS, difx)

yflag = False
if len(yS) == 0:
  if y == 0:
    yflag = True
elif y >= 0:
  if sumyS == y:
    yflag = True
  elif sumyS > y:
    dify = sumyS - y
    if dify%2==0:
      yflag = exist_dif(yS, dify)            
else:
  if sumyS == -y:
    yflag = True
  elif sumyS > -y:
    dify = sumyS + y
    if dify%2==0:
      yfalg = exist_dif(yS, dify)     
print('Yes' if xflag==True and yflag==True else 'No')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def ok(dir):
        goal = abs(xy[dir])
        dp = [False] * (goal + 1)
        dp[0] = True
        for d in dd[dir]:
            for i in range(goal + 1):
                if i - d >= 0: dp[i] |= dp[i - d]
            if dp[-1]:return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                dd[dir].append(cnt)
            dir = 1 - dir
            cnt = 0
    dd[dir].append(cnt)

    # print(xy, dd, total)
    for dir in range(2):
        if not ok(dir): no()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def dfs(dir, d, i=0, s=0):
        if s == d: return True
        if s > d or i == len(dd[dir]): return False
        if dfs(dir, d, i + 1, s): return True
        if dfs(dir, d, i + 1, s + dd[dir][i]): return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total = [0, 0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                dd[dir].append(cnt)
                total[dir] += cnt
            dir = 1 - dir
            cnt = 0
    dd[dir].append(cnt)
    total[dir] += cnt

    #print(xy, dd, total)
    for dir in range(2):
        if not -total[dir] <= xy[dir] <= total[dir]: no()
        d = abs(total[dir] - xy[dir])
        if d % 2: no()
        d //= 2
        if not dfs(dir, min(d, total[dir] - d)): no()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def dfs(dir, d, i=0, s=0):
        if s == d: return True
        if s > d or i == len(dd[dir]): return False
        if dfs(dir, d, i + 1, s): return True
        if dfs(dir, d, i + 1, s + dd[dir][i]): return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total = [0, 0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                dd[dir].append(cnt)
                total[dir] += cnt
            dir = 1 - dir
            cnt = 0
    dd[dir].append(cnt)
    total[dir] += cnt

    # print(xy, dd, total)
    for dir in range(2):
        if not -total[dir] <= xy[dir] <= total[dir]: no()
        d = abs(total[dir] - xy[dir])
        if d % 2: no()
        if not dfs(dir, d // 2): no()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def dfs(dir, d, i=0, s=0):
        if s == d: return True
        if s > d or i == len(dd[dir]): return False
        if dfs(dir, d, i + 1, s): return True
        if dfs(dir, d, i + 1, s + dd[dir][i]): return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total = [0, 0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                dd[dir].append(cnt)
                total[dir] += cnt
            dir = 1 - dir
            cnt = 0
    dd[dir].append(cnt)
    total[dir] += cnt

    print(xy, dd, total)
    for dir in range(2):
        if not -total[dir] <= xy[dir] <= total[dir]: no()
        d = abs(total[dir] - xy[dir])
        if d % 2: no()
        if not dfs(dir, d // 2): no()
    print("Yes")

main()

Submission status: Wrong Answer

Solution code:
#FT Robot
s = input()
x,y = map(int, input().split())
stack = 0
xy = 0
initial = 1
p = [0]; q = [0]

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    elif s[i] == "T":
        if initial == 1:
            p[0] = stack
            stack = 0
            initial = 0
            xy = 1
        elif initial == 0 and xy == 0:
            pa = []
            for j in range(len(p)):
                pa.append(p[j]+stack)
                pa.append(p[j]-stack)
            p = pa
            stack = 0
            xy = 1
        else:
            qa = []
            for j in range(len(q)):
                qa.append(q[j]+stack)
                qa.append(q[j]-stack)
            q = qa
            stack = 0
            xy = 0
if stack != 0:
    if xy == 0:
        pa = []
        for j in range(len(p)):
            pa.append(p[j]+stack)
            pa.append(p[j]-stack)
        p = pa
        stack = 0
    else:
        qa = []
        for j in range(len(q)):
            qa.append(q[j]+stack)
            qa.append(q[j]-stack)
        q = qa
        stack = 0
if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#FT Robots
s = input()
x,y = map(int, input().split())
stack = 0
xy = 0
initial = 1
p = [0]; q = [0]

for i in range(len(s)):
    if s[i] == "F":
        stack = stack + 1
    elif s[i] == "T":
        if initial == 1:
            p[0] = stack
            stack = 0
            initial = 0
            xy = 1
        elif initial == 0 and xy == 0:
            pa = []
            for j in range(len(p)):
                pa.append(p[j]+stack)
                pa.append(p[j]-stack)
            p = pa
            stack = 0
            xy = 1
        else:
            qa = []
            for j in range(len(q)):
                qa.append(q[j]+stack)
                qa.append(q[j]-stack)
            q = qa
            stack = 0
            xy = 0
if stack != 0:
    if xy == 0:
        pa = []
        for j in range(len(p)):
            pa.append(p[j]+stack)
            pa.append(p[j]-stack)
        p = pa
        stack = 0
    else:
        qa = []
        for j in range(len(q)):
            qa.append(q[j]+stack)
            qa.append(q[j]-stack)
        q = qa
        stack = 0
if x in p and y in q:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:

S = [len(x) for x in input().split('T')]

x,y = map(int,input().split(" "))
xstart = 0
dir = 0 # 0→ x方向 1 →y方向
first = True

temp = 0
spin_count = 0
x_array = []
y_array = []

xstart = S[0]
for c in S[1:]:
    if c != 0:
        dir += 1
        dir %= 2
        temp = c
        if dir == 0:
            x_array.append(temp)
        else:
            y_array.append(temp)
    else:
        dir += 1






dpx ={}
dpx[xstart] = 1


for i in x_array:
    temp = []
    for k  in dpx.keys():
        temp.append(k + i)
        temp.append(k - i)
    for k in temp:
        dpx[k] = 1
dpy ={}
dpy[0] = 1
for i in y_array:
    temp = []
    for k  in dpy.keys():
        temp.append(k + i)
        temp.append(k - i)
    for k in temp:
        dpy[k] = 1


if x in dpx and y in dpy:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S = input()
x, y = map(int, input().split())
X = []
Y = []
N = len(S)
now = 'x'
tmp = 0
for s in S:
    if s == 'F':
        tmp+=1
    else:
        if now == 'x':
            X.append(tmp)
            now = 'y'
            tmp = 0
        else:
            Y.append(tmp)
            now = 'x'
            tmp = 0
if now == 'x':
    X.append(tmp)
else:
    Y.append(tmp)
def C(List, x):
    n = len(List)
    dp = [[0]*(N*2+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        s = List[i-1]
        for j in range(-N, N+1):
            if j+s<=N:
                dp[i][j]+=dp[i-1][j+s]
            if j-s>=-N:
                dp[i][j]+=dp[i-1][j-s]
    return dp[n][x]
if C(X, x) and C(Y, y):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    GX, GY = map(int, input().split())

    S_parsed = []
    prev = S[0]
    seq = 1
    for c in S[1:]:
        if c == "F":
            if c == prev:
                seq += 1
            else:
                prev = c
                if seq % 2 == 0:
                    pass
                else:
                    S_parsed.append("T")
                seq = 1
        elif c == "T":
            if c == prev:
                seq += 1
            else:
                S_parsed.append(seq)
                seq = 1
            prev = c
    else:
        if S[-1] == "F":
            S_parsed.append(seq)

    x_move = []
    y_move = []

    dir_x = True
    for c in S_parsed:
        if c == "T":
            dir_x = not dir_x
        else:
            if dir_x:
                x_move.append(c)
            else:
                y_move.append(c)

    dp_x = defaultdict(bool)
    if len(x_move) > 0:
        dp_x[x_move[0]] = True
    else:
        dp_x[0] = True

    for x in x_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_x.items():
            tmp[key+x] = True
            tmp[key-x] = True
        dp_x = tmp

    dp_y = defaultdict(bool)
    if len(y_move) == 0:
        dp_y[0] = True
    else:
        dp_y[y_move[0]] = True
        dp_y[-y_move[0]] = True
    for y in y_move[1:]:
        tmp = defaultdict(bool)
        for key, val in dp_y.items():
            tmp[key+y] = True
            tmp[key-y] = True
        dp_y = tmp

    if dp_x[GX]and dp_y[GY]:
        print("Yes")
    else:
        print("No")


solve()