← Home
For problem statement at 1000-1999/1100-1199/1120-1129/1129/problemC.txt this is a correct solution, but verifier at 1000-1999/1100-1199/1120-1129/1129/verifierC.go ends with test 1: runtime error: exit status 2
input:
20
1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 0 can you fix the verifier? ```go
package main

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

const MOD int64 = 1000000007

type Node struct {
	trans [2]int
	link  int
	maxl  int
}

var nodes []Node

func buildSAM(str []byte) {
	nodes = make([]Node, 0, len(str)*2+1)
	nodes = append(nodes, Node{[2]int{0, 0}, -1, 0}) // root 0
	last := 0
	for _, by := range str {
		ch := int(by - '0')
		cur := len(nodes)
		nodes = append(nodes, Node{[2]int{0, 0}, 0, nodes[last].maxl + 1})
		p := last
		for p != -1 && nodes[p].trans[ch] == 0 {
			nodes[p].trans[ch] = cur
			p = nodes[p].link
		}
		if p == -1 {
			nodes[cur].link = 0
		} else {
			q := nodes[p].trans[ch]
			if nodes[p].maxl+1 == nodes[q].maxl {
				nodes[cur].link = q
			} else {
				cl := len(nodes)
				nodes = append(nodes, Node{nodes[q].trans, nodes[q].link, nodes[p].maxl + 1})
				nodes[cur].link = cl
				nodes[q].link = cl
				p2 := p
				for p2 != -1 && nodes[p2].trans[ch] == q {
					nodes[p2].trans[ch] = cl
					p2 = nodes[p2].link
				}
			}
		}
		last = cur
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var m int
	fmt.Sscan(scanner.Text(), &m)

	var S []byte
	var prev_ans int64 = 0

	for i := 0; i < m; i++ {
		scanner.Scan()
		c := scanner.Text()[0]
		S = append(S, c)
		curr_n := len(S)

		var L int
		if curr_n == 1 {
			L = 0
		} else {
			old_rev := make([]byte, curr_n-1)
			for k := 0; k < curr_n-1; k++ {
				old_rev[k] = S[curr_n-2-k]
			}
			buildSAM(old_rev)

			current_state := 0
			l := 0
			for pos := 1; pos <= curr_n; pos++ {
				ch := int(S[curr_n-pos] - '0')
				if nodes[current_state].trans[ch] != 0 {
					current_state = nodes[current_state].trans[ch]
					l = pos
				} else {
					break
				}
			}
			L = l
		}

		dp := make([]int64, curr_n+1)
		dp[0] = 1
		for j := 1; j <= curr_n; j++ {
			dp[j] = 0
			for leng := 1; leng <= 4 && leng <= j; leng++ {
				valid := true
				if leng == 4 {
					b0 := S[curr_n-1-(j-leng)]
					b1 := S[curr_n-1-(j-leng+1)]
					b2 := S[curr_n-1-(j-leng+2)]
					b3 := S[curr_n-1-(j-leng+3)]
					ss := string([]byte{b0, b1, b2, b3})
					if ss == "0011" || ss == "0101" || ss == "1110" || ss == "1111" {
						valid = false
					}
				}
				if valid {
					dp[j] = (dp[j] + dp[j-leng]) % MOD
				}
			}
		}

		var contrib int64 = 0
		for k := L + 1; k <= curr_n; k++ {
			contrib = (contrib + dp[k]) % MOD
		}

		current_ans := (prev_ans + contrib) % MOD
		fmt.Println(current_ans)
		prev_ans = current_ans
	}
}
```