Submission #4964834


Source Code Expand

Copy
n, k = map(int, input().split())
s = input()
cnt = 0
if s[0] == "0":
	cnt += 1
for i in range(1, n):
	if s[i-1] == "1" and s[i] == "0":
		cnt += 1
if cnt <= k:
	print(n)
else:

	one_left, one_right = [], []
	#if s[0] == "1":
	one_left.append(0)
	for i in range(1, n):
		if s[i-1] == "0" and s[i] == "1":
			one_left.append(i)
		if s[i-1] == "1" and s[i] == "0":
			one_right.append(i)
	#if s[-1] == "1":
	one_right.append(n)
	if s[0] == "1":
		one_right.pop(0)
	if s[-1] == "1":
		one_left.pop(-1)
	#print(one_left)
	#print(one_right)
	ans = 0
	for i in range(min(len(one_left), len(one_right)-k+1)):
		ans = max(ans, one_right[i+k-1] - one_left[i])
	print(ans)

Submission Info

Submission Time
Task D - Handstand
User anagohirame
Language Python3 (3.4.3)
Score 400
Code Size 692 Byte
Status
Exec Time 96 ms
Memory 7208 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 17 ms 3064 KB
sample_02 17 ms 3064 KB
sample_03 17 ms 3064 KB
testcase_01 24 ms 3064 KB
testcase_02 32 ms 3188 KB
testcase_03 79 ms 5048 KB
testcase_04 17 ms 3064 KB
testcase_05 96 ms 7172 KB
testcase_06 96 ms 7168 KB
testcase_07 84 ms 7040 KB
testcase_08 81 ms 7208 KB
testcase_09 84 ms 7040 KB
testcase_10 58 ms 3188 KB
testcase_11 33 ms 3188 KB
testcase_12 33 ms 3188 KB
testcase_13 37 ms 3188 KB
testcase_14 30 ms 3188 KB
testcase_15 17 ms 3064 KB