For problem statement at 2000-2999/2000-2099/2020-2029/2022/problemC.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2020-2029/2022/verifierC.go ends with All tests passed can you fix the verifier? package main
import (
"bytes"
"io"
"os"
"strconv"
)
type Transition struct {
next int
need byte
cnt byte
types [2]byte
}
var trans [64][]Transition
var typeMask = [6]int{21, 7, 11, 13, 42, 14}
var typeNeed = [6]int{2, 1, 1, 1, 2, 1}
func initTransitions() {
var dfs func(start, mask, cnt, need int, types [2]byte)
dfs = func(start, mask, cnt, need int, types [2]byte) {
if mask&3 == 3 {
trans[start] = append(trans[start], Transition{
next: mask >> 2,
need: byte(need),
cnt: byte(cnt),
types: types,
})
return
}
if mask&1 == 0 {
for _, t := range [...]int{0, 1, 2, 3} {
pm := typeMask[t]
if mask&pm == 0 {
nt := types
nt[cnt] = byte(t)
nneed := need
if typeNeed[t] > nneed {
nneed = typeNeed[t]
}
dfs(start, mask|pm, cnt+1, nneed, nt)
}
}
} else if mask&2 == 0 {
for _, t := range [...]int{4, 5} {
pm := typeMask[t]
if mask&pm == 0 {
nt := types
nt[cnt] = byte(t)
nneed := need
if typeNeed[t] > nneed {
nneed = typeNeed[t]
}
dfs(start, mask|pm, cnt+1, nneed, nt)
}
}
}
}
for m := 0; m < 64; m++ {
var types [2]byte
dfs(m, m, 0, 0, types)
}
}
func main() {
initTransitions()
data, _ := io.ReadAll(os.Stdin)
idx := 0
nextInt := func() int {
for idx < len(data) && data[idx] <= ' ' {
idx++
}
x := 0
for idx < len(data) && data[idx] > ' ' {
x = x*10 + int(data[idx]-'0')
idx++
}
return x
}
nextBytes := func() []byte {
for idx < len(data) && data[idx] <= ' ' {
idx++
}
start := idx
for idx < len(data) && data[idx] > ' ' {
idx++
}
return data[start:idx]
}
t := nextInt()
const neg = -1 << 30
var out bytes.Buffer
for ; t > 0; t-- {
n := nextInt()
s0 := nextBytes()
s1 := nextBytes()
var curr, next [64]int
for i := 0; i < 64; i++ {
curr[i] = neg
}
curr[0] = 0
for i := 0; i < n; i++ {
for j := 0; j < 64; j++ {
next[j] = neg
}
a0, b0 := 0, 0
if s0[i] == 'A' {
a0 = 1
}
if s1[i] == 'A' {
b0 = 1
}
a1, b1, a2, b2 := 0, 0, 0, 0
if i+1 < n {
if s0[i+1] == 'A' {
a1 = 1
}
if s1[i+1] == 'A' {
b1 = 1
}
}
if i+2 < n {
if s0[i+2] == 'A' {
a2 = 1
}
if s1[i+2] == 'A' {
b2 = 1
}
}
var gains [6]int
if i+1 < n {
if a0+b0+a1 >= 2 {
gains[1] = 1
}
if a0+b0+b1 >= 2 {
gains[2] = 1
}
if a0+a1+b1 >= 2 {
gains[3] = 1
}
if b0+a1+b1 >= 2 {
gains[5] = 1
}
}
if i+2 < n {
if a0+a1+a2 >= 2 {
gains[0] = 1
}
if b0+b1+b2 >= 2 {
gains[4] = 1
}
}
for mask := 0; mask < 64; mask++ {
v := curr[mask]
if v == neg {
continue
}
for _, tr := range trans[mask] {
if i+int(tr.need) >= n {
continue
}
add := 0
if tr.cnt > 0 {
add += gains[tr.types[0]]
if tr.cnt > 1 {
add += gains[tr.types[1]]
}
}
nv := v + add
if nv > next[tr.next] {
next[tr.next] = nv
}
}
}
curr = next
}
out.WriteString(strconv.Itoa(curr[0]))
out.WriteByte('\n')
}
os.Stdout.Write(out.Bytes())
}