Problem p03074 (python)

Fixed submission:

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[min(len(nums_cs)-1,2*K)]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K+1):
    if i % 2 == 0:
        #print(i)
        res = max(res, nums_cs[min(i+2*K,len(nums_cs)-1)]-nums_cs[i-1])


print(res)

Buggy submission (verdict: Runtime Error):

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[2*K]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K+1):
    if i % 2 == 0:
        #print(i)
        res = max(res, nums_cs[min(i+2*K,len(nums_cs)-1)]-nums_cs[i-1])


print(res)

Buggy submission (verdict: Runtime Error):

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[2*K]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K+1):
    if i % 2 == 0:
        print(i)
        res = max(res, nums_cs[min(i+2*K,len(nums_cs)-1)]-nums_cs[i-1])


print(res)

Buggy submission (verdict: Runtime Error):

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[2*K]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K):
    if i % 2 == 0:
        res = max(res, nums_cs[i+2*K]-nums_cs[i-1])


print(res)

Buggy submission (verdict: Runtime Error):

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)


nums_cs = np.cumsum(nums)



#print(res)
if s[0]==1:
    if len(nums_cs) > 1:
       res = nums_cs[min(len(nums_cs)-1,2*K)]
    else:
        res=nums_cs[0]
    for i in range(1,len(nums_cs)-2*K):
        if i%2==0:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i-1])
else:    
    if len(nums_cs) > 1:
       res = nums_cs[min(len(nums_cs)-1,2*K-1)]
    else:
        res=nums_cs[0]

    for i in range(1,len(nums_cs)-2*K-1):
        if i%2==1:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i])


print(res)

Buggy submission (verdict: Runtime Error):

import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)


nums_cs = np.cumsum(nums)

if len(nums_cs) != 1:
       res = nums_cs[2*K-1]
else:
    res=nums_cs[0]

#print(res)
if s[0]==1:

    for i in range(1,len(nums_cs)-2*K-1):
        if i%2==0:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i-1])
else:    

    for i in range(1,len(nums_cs)-2*K-1):
        if i%2==1:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i])


print(res)

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(100000)
import numpy as np

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])


def acinput():
    return list(map(int,input().split(" ")))




import sys
sys.setrecursionlimit(100000)

import numpy as np

directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))

def acinput():
    return list(map(int, input().split(" ")))

N,K=acinput()
s=list(map(int,list(input())))

nums=[1]
for i in range(1,N):
    if s[i]==s[i-1]:
        nums[-1]+=1
    else:
        nums.append(1)


nums_cs=np.cumsum(nums)

if K>1:
    res=nums_cs[2*K-1]
else:
    res=nums_cs[0]
for i in range(len(nums_cs)-2*K-1):
    res=max(res,nums_cs[i+2*K+1]-nums_cs[i])



print(res)