Problem p03488 (python)

Fixed submission:
s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(da,dp,G):
    for i in range(len(da)):
        tmp=set()
        for j in dp:
            tmp.add(j-da[i])
            tmp.add(j+da[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False
    """amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][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"""

d=[len(x) for x in s.split("T")]

dx=d[2::2]
dy=d[1::2]

if solve(dx,{d[0]},X) and solve(dy,{0},Y):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):

    amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):

    amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):

    amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False

    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):

    amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False

    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
import copy
def solve(a,G):
    amax=0
    for i in a:
        amax+=abs(i)

    dp=[[0]*2*amax for _ in range(len(a))]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
def solve(a,G):
    dp=[[0]*16001 for _ in range(len(x))]
    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")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
def solve(a,G):
    dp=[[0]*20000 for _ in range(len(x))]
    dp[0][a[0]]=1

    for i in range(1,len(a)):

        for j in range(-9000,9000):
            dp[i][j-a[i]]+=dp[i-1][j]
            dp[i][j+a[i]]+=dp[i-1][j]
            #print(dp)
    for i in range(len(a)):
        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 not solve(y,Y):
    print("a")
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()
X,Y=map(int,input().split())
def solve(a,G):
    dp=[[0]*20 for _ in range(len(x))]
    dp[0][a[0]]=1

    for i in range(1,len(a)):

        for j in range(-9,9):
            dp[i][j-a[i]]+=dp[i-1][j]
            dp[i][j+a[i]]+=dp[i-1][j]
            #print(dp)
    for i in range(len(a)):
        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 not solve(y,Y):
    print("a")
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")