Problem p03074 (python)

Fixed submission:
from itertools import*
from numpy import*
n,k=map(int,input().split())
k=2*k+1
s=input()
x=[0]*(s[0]=="0")+[len(list(v))for k,v in groupby(s)]+[0]*(s[-1]=="0")
#print(x)
x1=array(x[k:])
x2=array(x[:-k])
x3=sum(x[:k])
y=[x3]+list(x3+cumsum(x1-x2))
print(max(y[::2]))

Buggy submission (verdict: Runtime Error):
from numpy import*
from itertools import*
N, K = map(int, input().split())
S=input()
zeros=[len(list(v)) for k,v in groupby(S) if k=="0"]
ones =[len(list(v)) for k,v in groupby(S) if k=="1"]


#print(zeros,ones)

c_zero= cumsum(zeros)
c_one = cumsum(ones)

#print(c_zero,c_one)

if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range(0, len(zeros) - K):
        aaa = c_zero[i+K]-c_zero[i] + c_one[i+K+1]-c_one[i]
        ans = max(aaa, ans)
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
p=[len(list(v))for k,v in groupby(s)if k=="0"]
q=[len(list(v))for k,v in groupby(s)if k=="1"]
if len(p)==1 and len(q)==0 and k>0:
    print(sum(p))
    exit()
elif len(q)==1 and len(p)==0:
    print(sum(q))
    exit()
if len(p)==1 and len(q)==1:
    if k>0:
        print(sum(p)+sum(q))
        exit()
    else:
        print(q[0])
        exit()

if s[0]=="1" and s[-1]=="0":
    x=[0]+p
    y=[0]+q+[0]
elif s[0]=="0" and s[-1]=="1":
    x=[0]+p+[0]
    y=[0]+q
else:
    x=[0]+p+[0]
    y=[0]+q+[0]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)

print(max(max(t+f),x3+y3))

Buggy submission (verdict: Runtime Error):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
p=[len(list(v))for k,v in groupby(s)if k=="0"]
q=[len(list(v))for k,v in groupby(s)if k=="1"]
if len(p)==1 and len(q)==0 and k>0:
    print(sum(p))
    exit()
elif len(q)==1 and len(p)==0:
    print(sum(q))
    exit()
if s[0]=="1" and s[-1]=="0":
    x=[0]+p
    y=[0]+q+[0]
elif s[0]=="0" and s[-1]=="1":
    x=[0]+p+[0]
    y=[0]+q
else:
    x=[0]+p+[0]
    y=[0]+q+[0]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)
#print(x,y)
#print(t,f)
print(max(max(t+f),x3+y3))

Buggy submission (verdict: Runtime Error):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
if s[0]=="1" and s[-1]=="0":
    x=[0]+[len(list(v))for k,v in groupby(s)if k=="0"]
    y=[0]+[len(list(v))for k,v in groupby(s)if k=="1"]+[0]
elif s[0]=="0" and s[-1]=="1":
    x=[0]+[len(list(v))for k,v in groupby(s)if k=="0"]+[0]
    y=[0]+[len(list(v))for k,v in groupby(s)if k=="1"]
else:
    x=[0]+[len(list(v))for k,v in groupby(s)if k=="0"]+[0]
    y=[0]+[len(list(v))for k,v in groupby(s)if k=="1"]+[0]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)
#print(x,y)
#print(t,f)
print(max(max(t+f),x3+y3))

Buggy submission (verdict: Runtime Error):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
x=[0]+[len(list(v))for k,v in groupby(s)if k=="0"]+[0]
y=[0]+[len(list(v))for k,v in groupby(s)if k=="1"]+[0]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)
#print(x,y)
#print(t,f)
print(max(max(t+f),x3+y3))

Buggy submission (verdict: Runtime Error):
from itertools import*
from numpy import*
n,k=map(int,input().split())
k2=k+1
s=input()
if len(s)==1:
    if s=="1":
        print(1)
    else:
        print(0)
    exit()
x=[len(list(v))for k,v in groupby(s)if k=="0"]
y=[len(list(v))for k,v in groupby(s)if k=="1"]
x1=array(x[:-k])
x2=array(x[k:])
x3=sum(x[:k])
t=x3+cumsum(x2-x1)
y1=array(y[:-k2])
y2=array(y[k2:])
y3=sum(y[:k2])
f=y3+cumsum(y2-y1)
print(max(max(t+f),x3+y3))