For problem statement at 0-999/0-99/60-69/62/problemB.txt this is a correct solution, but verifier at 0-999/0-99/60-69/62/verifierB.go ends with All tests passed can you fix the verifier? package main
import (
"io"
"os"
"sort"
"strconv"
)
func main() {
in := readAll(os.Stdin)
var pos int
nextWord := func() string {
for pos < len(in) && in[pos] <= ' ' {
pos++
}
if pos >= len(in) {
return ""
}
start := pos
for pos < len(in) && in[pos] > ' ' {
pos++
}
return string(in[start:pos])
}
nStr := nextWord()
if nStr == "" {
return
}
n, _ := strconv.Atoi(nStr)
nextWord()
s := nextWord()
positions := make([][]int, 26)
for j := 0; j < len(s); j++ {
ch := s[j] - 'a'
positions[ch] = append(positions[ch], j+1)
}
out := make([]byte, 0, 64*1024)
for i := 0; i < n; i++ {
c := nextWord()
if c == "" {
break
}
var F int64
length := int64(len(c))
for j := 0; j < len(c); j++ {
p := positions[c[j]-'a']
if len(p) == 0 {
F += length
} else {
target := j + 1
idx := sort.SearchInts(p, target)
bestDiff := -1
if idx < len(p) {
bestDiff = p[idx] - target
}
if idx > 0 {
diff := target - p[idx-1]
if bestDiff == -1 || diff < bestDiff {
bestDiff = diff
}
}
F += int64(bestDiff)
}
}
out = strconv.AppendInt(out, F, 10)
out = append(out, '\n')
}
os.Stdout.Write(out)
}
func readAll(r io.Reader) []byte {
b, _ := io.ReadAll(r)
return b
}