For problem statement at 1000-1999/1200-1299/1240-1249/1244/problemF.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1240-1249/1244/verifierF.go ends with all tests passed can you fix the verifier? package main
import (
"bufio"
"io"
"os"
)
var data []byte
var idx int
func nextInt() int {
for idx < len(data) && data[idx] <= ' ' {
idx++
}
sign := 1
if idx < len(data) && data[idx] == '-' {
sign = -1
idx++
}
val := 0
for idx < len(data) && data[idx] > ' ' {
val = val*10 + int(data[idx]-'0')
idx++
}
return sign * val
}
func nextString() string {
for idx < len(data) && data[idx] <= ' ' {
idx++
}
start := idx
for idx < len(data) && data[idx] > ' ' {
idx++
}
return string(data[start:idx])
}
func flip(c byte) byte {
if c == 'W' {
return 'B'
}
return 'W'
}
func main() {
data, _ = io.ReadAll(os.Stdin)
n := nextInt()
k := nextInt()
s := []byte(nextString())
good := make([]bool, n)
has := false
for i := 0; i < n; i++ {
j := i + 1
if j == n {
j = 0
}
if s[i] == s[j] {
good[i] = true
good[j] = true
has = true
}
}
res := make([]byte, n)
if !has {
if k%2 == 0 {
copy(res, s)
} else {
for i := 0; i < n; i++ {
res[i] = flip(s[i])
}
}
w := bufio.NewWriterSize(os.Stdout, 1<<20)
w.Write(res)
w.Flush()
return
}
dist := make([]int, n)
for i := 0; i < n; i++ {
dist[i] = -1
}
color := make([]byte, n)
q := make([]int, 0, n)
for i := 0; i < n; i++ {
if good[i] {
dist[i] = 0
color[i] = s[i]
q = append(q, i)
}
}
for head := 0; head < len(q); head++ {
v := q[head]
u := v - 1
if u < 0 {
u = n - 1
}
if dist[u] == -1 {
dist[u] = dist[v] + 1
color[u] = color[v]
q = append(q, u)
}
u = v + 1
if u == n {
u = 0
}
if dist[u] == -1 {
dist[u] = dist[v] + 1
color[u] = color[v]
q = append(q, u)
}
}
parity := k % 2
for i := 0; i < n; i++ {
if dist[i] <= k {
res[i] = color[i]
} else {
if parity == 0 {
res[i] = s[i]
} else {
res[i] = flip(s[i])
}
}
}
w := bufio.NewWriterSize(os.Stdout, 1<<20)
w.Write(res)
w.Flush()
}