← Home
For problem statement at 0-999/200-299/270-279/279/problemE.txt this is a correct solution, but verifier at 0-999/200-299/270-279/279/verifierE.go ends with All tests passed can you fix the verifier? package main

import (
	"bytes"
	"fmt"
	"io"
	"os"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	s := bytes.TrimSpace(data)

	const INF = int(1 << 30)
	dp0, dp1 := 0, INF

	for i := len(s) - 1; i >= 0; i-- {
		b := int(s[i] - '0')
		ndp0, ndp1 := INF, INF

		if dp0 < INF {
			if b == 0 {
				if dp0 < ndp0 {
					ndp0 = dp0
				}
			} else {
				if dp0+1 < ndp0 {
					ndp0 = dp0 + 1
				}
				if dp0+1 < ndp1 {
					ndp1 = dp0 + 1
				}
			}
		}

		if dp1 < INF {
			if b == 0 {
				if dp1+1 < ndp0 {
					ndp0 = dp1 + 1
				}
				if dp1+1 < ndp1 {
					ndp1 = dp1 + 1
				}
			} else {
				if dp1 < ndp1 {
					ndp1 = dp1
				}
			}
		}

		dp0, dp1 = ndp0, ndp1
	}

	ans := dp0
	if dp1+1 < ans {
		ans = dp1 + 1
	}

	fmt.Print(ans)
}