← Home
For problem statement at 0-999/0-99/30-39/30/problemE.txt this is a correct solution, but verifier at 0-999/0-99/30-39/30/verifierE.go ends with case 7 failed: invalid segments
input:ccbbccbc
exit status 1 can you fix the verifier? package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 200005), 200005)
	if !scanner.Scan() {
		return
	}
	s := scanner.Text()
	n := len(s)
	if n == 0 {
		return
	}

	d := make([]int, n)
	l, r := 0, -1
	for i := 0; i < n; i++ {
		k := 1
		if i <= r {
			if d[l+r-i] < r-i+1 {
				k = d[l+r-i]
			} else {
				k = r-i+1
			}
		}
		for i-k >= 0 && i+k < n && s[i-k] == s[i+k] {
			k++
		}
		d[i] = k
		if i+k-1 > r {
			l = i - k + 1
			r = i + k - 1
		}
	}

	pi := make([]int, n)
	for i := 1; i < n; i++ {
		j := pi[i-1]
		for j > 0 && s[i] != s[j] {
			j = pi[j-1]
		}
		if s[i] == s[j] {
			j++
		}
		pi[i] = j
	}

	match := make([]int, n)
	j := 0
	for i := 0; i < n; i++ {
		for j > 0 && s[n-1-i] != s[j] {
			j = pi[j-1]
		}
		if s[n-1-i] == s[j] {
			j++
		}
		match[i] = j
	}

	maxMatch := make([]int, n)
	posMatch := make([]int, n)
	maxMatch[0] = match[0]
	posMatch[0] = 0
	for i := 1; i < n; i++ {
		if match[i] > maxMatch[i-1] {
			maxMatch[i] = match[i]
			posMatch[i] = i
		} else {
			maxMatch[i] = maxMatch[i-1]
			posMatch[i] = posMatch[i-1]
		}
	}

	bestTotal := 0
	var ansK int
	var ans [3][2]int

	for c := 0; c < n; c++ {
		rad := d[c] - 1
		lm := c - rad
		rm := c + rad

		i := n - rm - 2
		L := 0
		pos := -1
		if i >= 0 {
			L = maxMatch[i]
			if L > lm {
				L = lm
			}
			pos = posMatch[i]
		}

		total := 2*L + 2*rad + 1
		if total > bestTotal {
			bestTotal = total
			if L > 0 {
				ansK = 3
				ans[0] = [2]int{1, L}
				ans[1] = [2]int{lm + 1, 2*rad + 1}
				ans[2] = [2]int{n - pos, L}
			} else {
				ansK = 1
				ans[0] = [2]int{lm + 1, 2*rad + 1}
			}
		}
	}

	fmt.Println(ansK)
	if ansK == 1 {
		fmt.Printf("%d %d\n", ans[0][0], ans[0][1])
	} else {
		fmt.Printf("%d %d\n", ans[0][0], ans[0][1])
		fmt.Printf("%d %d\n", ans[1][0], ans[1][1])
		fmt.Printf("%d %d\n", ans[2][0], ans[2][1])
	}
}