← Home
For problem statement at 1000-1999/1900-1999/1920-1929/1924/problemA.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1920-1929/1924/verifierA.go ends with case 3 mismatch
expected:
NO
aaa
got:
NO
bbb
input:
1
3 4 11
acbdcbddacd
exit status 1 can you fix the verifier? ```go
package main

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

type State struct {
	l int
	p int
}

type Prev struct {
	p int
	c int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for test := 0; test < t; test++ {
		var n, k, m int
		fmt.Fscan(in, &n, &k, &m)
		var s string
		fmt.Fscan(in, &s)

		full := (uint64(1) << k) - 1
		maskk := make([]uint64, m+1)
		maskk[m] = 0
		for i := m - 1; i >= 0; i-- {
			let := int(s[i] - byte('a'))
			maskk[i] = maskk[i+1] | (uint64(1) << let)
		}

		nextpos := make([][]int, m+1)
		for i := 0; i <= m; i++ {
			nextpos[i] = make([]int, k)
		}
		for cc := 0; cc < k; cc++ {
			nextpos[m][cc] = m
			for qq := m - 1; qq >= 0; qq-- {
				if int(s[qq]-byte('a')) == cc {
					nextpos[qq][cc] = qq
				} else {
					nextpos[qq][cc] = nextpos[qq+1][cc]
				}
			}
		}

		reached := make([][]bool, n+1)
		for i := 0; i <= n; i++ {
			reached[i] = make([]bool, m+1)
		}
		prevv := make([][]Prev, n+1)
		for i := 0; i <= n; i++ {
			prevv[i] = make([]Prev, m+1)
		}

		var q []State
		q = append(q, State{0, 0})
		reached[0][0] = true

		for len(q) > 0 {
			cur := q[0]
			q = q[1:]
			cl := cur.l
			cp := cur.p
			if cl >= n {
				continue
			}
			for cc := 0; cc < k; cc++ {
				np := nextpos[cp][cc]
				if np >= m {
					continue
				}
				newp := np + 1
				newl := cl + 1
				if newl > n {
					continue
				}
				if !reached[newl][newp] {
					reached[newl][newp] = true
					prevv[newl][newp] = Prev{cp, cc}
					q = append(q, State{newl, newp})
				}
			}
		}

		found := false
		var badL, badP, badC int
		var ans string
	outer:
		for ll := 0; ll < n; ll++ {
			for pp := 0; pp <= m; pp++ {
				if reached[ll][pp] && (maskk[pp]&full) != full {
					found = true
					badL = ll
					badP = pp
					for bc := 0; bc < k; bc++ {
						if nextpos[pp][bc] == m {
							badC = bc
							break
						}
					}
					break outer
				}
			}
		}

		if !found {
			fmt.Fprintln(out, "YES")
			continue
		}

		// reconstruct
		var seq []byte
		currentL := badL
		currentP := badP
		for currentL > 0 {
			pc := prevv[currentL][currentP].c
			seq = append([]byte{byte('a') + byte(pc)}, seq...)
			currentP = prevv[currentL][currentP].p
			currentL--
		}
		seq = append(seq, byte('a')+byte(badC))
		currentLen := badL + 1
		for currentLen < n {
			seq = append(seq, byte('a'))
			currentLen++
		}
		ans = string(seq)

		fmt.Fprintln(out, "NO")
		fmt.Fprintln(out, ans)
	}
}
```