← Home
For problem statement at 0-999/700-799/770-779/774/problemL.txt this is a correct solution, but verifier at 0-999/700-799/770-779/774/verifierL.go ends with All tests passed can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, k int
	fmt.Fscan(reader, &n, &k)
	var s string
	fmt.Fscan(reader, &s)

	prevZero := make([]int, n)
	last := 0
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			last = i
		}
		prevZero[i] = last
	}

	isValid := func(D int) bool {
		curr := 0
		count := 1
		for curr < n-1 {
			next := curr + D
			if next >= n-1 {
				count++
				break
			}
			best := prevZero[next]
			if best <= curr {
				return false
			}
			curr = best
			count++
		}
		return count <= k
	}

	ans := n - 1
	low, high := 1, n-1
	for low <= high {
		mid := low + (high-low)/2
		if isValid(mid) {
			ans = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	fmt.Println(ans - 1)
}