Problem p03488 (python)

Fixed submission:
order = list(input())
X, Y = map(int, input().split())
 
Xs = []
Ys = []
cnt = 0
now_lis = Xs
x_dir = 1
for s in order:
    if s=='T':
        if not cnt==0:
            now_lis.append(cnt)
        now_lis = Ys if x_dir else Xs
        x_dir = not x_dir
        cnt = 0
    else:
        cnt += 1
if not cnt==0:
    now_lis.append(cnt)

if order[0]=='T':
    x_start = 0
else:
    x_start = Xs[0]
    del Xs[0]

def dp(start, lis, goal):
    nodes = set([start])
    for x in lis:
        nx = set()
        L = list(nodes)
        for l in L:
            nx.add(l+x)
            nx.add(l-x)
        nodes = nx
    return goal in nodes
 
if dp(x_start, Xs, X) and dp(0, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())
 
Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        if not cnt==0:
            now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
if not cnt==0:
    now_lis.append(cnt)

if order[0]=='T':
    x_start = 0
else:
    x_start = Xs[0]
    del Xs[0]

def dp(start, lis, goal):
    M = sum(lis)
    length = len(lis)
    dp = [[0]*(M*2+1) for _ in range(length+1)]
    dp[0][M+start] = 1
    for i, x in enumerate(lis, 1):
        for j in range(M*2+1):
            if dp[i-1][j]==1:
                if not j+x>=M*2+1:
                    dp[i][j+x] = 1
                if not j-x<0:
                    dp[i][j-x] = 1
    if goal+M>=M*2+1 or goal+M<0:
        return 0
    return dp[-1][goal+M]
 
if dp(x_start, Xs, X) and dp(0, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())
 
Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        if not cnt==0:
            now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
if not cnt==0:
    now_lis.append(cnt)

def dp(length, lis, goal, isX):
    M = sum(lis)
    dp = [[0]*(M*2+1) for _ in range(length+1)]
    dp[0][M] = 1
    for i, x in enumerate(lis, 1):
        for j in range(M*2):
            if dp[i-1][j]==1:
                if not (j+x>=M*2+1 or j+x<0):
                    dp[i][j+x] = 1
                if not (j-x<0 or j-x>=M*2+1):
                    if not isX and i!=1:
                        dp[i][j-x] = 1
    if goal+M>=M*2+1 or goal+M<0:
        return 0
    return dp[-1][goal+M]
 
if dp(lx, Xs, X, 1) and dp(ly, Ys, Y, 1):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)

def dp(length, lis, goal):
    M = sum(lis)
    dp = [[0]*(M*2) for _ in range(length+1)]
    dp[0][M] = 1
    for i, x in enumerate(lis, 1):
        for j in range(M*2):
            if dp[i-1][j]==1:
                if not (j+x>=M*2 or j+x<0):
                    dp[i][j+x] = 1
                if not (j-x<0 or j-x>=M*2):
                    dp[i][j-x] = 1
    return dp[-1][goal+M]

if dp(lx, Xs, X) and dp(ly, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)

def dp(length, lis, goal):
    M = sum(lis)
    dp = [[0]*(M*2+1) for _ in range(length+1)]
    dp[0][M] = 1
    for i, x in enumerate(lis, 1):
        for j in range(M*2):
            if dp[i-1][j]==1:
                if not j+x>=M*2 or not j+x<0:
                    dp[i][j+x] = 1
                if not j-x<0 or not j-x>=M*2:
                    dp[i][j-x] = 1
    return dp[-1][goal+M]

if dp(lx, Xs, X) and dp(ly, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)

def dp(length, lis, goal):
    dp = [[0]*16000 for _ in range(length+1)]
    dp[0][8000] = 1
    for i, x in enumerate(lis, 1):
        for j in range(16000):
            if dp[i-1][j]==1:
                if not j+x>=16000 or not j+x<0:
                    dp[i][j+x] = 1
                if not j-x<0 or not j-x>=16000:
                    dp[i][j-x] = 1
    return dp[-1][goal+8000]

if dp(lx, Xs, X) and dp(ly, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)

def dp(length, lis, goal):
    dp = [[0]*16000 for _ in range(length+1)]
    dp[0][8000] = 1
    for i, x in enumerate(lis, 1):
        for j in range(16000):
            if dp[i-1][j]==1:
                if not j+x>=16000 or not j+x<0:
                    dp[i][j+x] = 1
                if not j-x<0 or not j-x>=16000:
                    dp[i][j-x] = 1
    return dp[-1][goal+8000]

if dp(xdp, Xs, X) and dp(ydp, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)
xdp = [[0]*16000 for _ in range(lx+1)]
ydp = [[0]*16000 for _ in range(ly+1)]
xdp[0][8000] = 1
ydp[0][8000] = 1

def dp(dp, lis, goal):
    for i, x in enumerate(lis, 1):
        for j in range(16000):
            if dp[i-1][j]==1:
                if not j+x>=16000:
                    dp[i][j+x] = 1
                if not j-x<0:
                    dp[i][j-x] = 1
    return dp[-1][goal+8000]

if dp(xdp, Xs, X) and dp(ydp, Ys, Y):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
order = list(input())
X, Y = map(int, input().split())

Xs = []
Ys = []
now_lis = Xs
cnt = 0
for s in order:
    if s=='T':
        now_lis.append(cnt)
        now_lis = Ys if now_lis==Xs else Xs
        cnt = 0
    else:
        cnt += 1
now_lis.append(cnt)
lx = len(Xs)
ly = len(Ys)
xdp = [[0]*8000 for _ in range(lx+1)]
ydp = [[0]*8000 for _ in range(ly+1)]
xdp[0][4000] = 1
ydp[0][4000] = 1

def dp(dp, lis, goal):
    for i, x in enumerate(lis, 1):
        for j in range(8000):
            if dp[i-1][j]==1:
                if not j+x>=8000:
                    dp[i][j+x] = 1
                if not j-x<0:
                    dp[i][j-x] = 1
    return dp[-1][goal+4000]

if dp(xdp, Xs, X) and dp(ydp, Ys, Y):
    print('Yes')
else:
    print('No')