← Home
For problem statement at 1000-1999/1600-1699/1670-1679/1671/problemE.txt this is a correct solution, but verifier at 1000-1999/1600-1699/1670-1679/1671/verifierE.go ends with All tests passed can you fix the verifier? package main

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

const MOD int64 = 998244353

type Key struct {
	c    byte
	a, b int
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var n int
	var s string
	fmt.Fscan(in, &n, &s)

	N := (1 << n) - 1
	ids := make([]int, N+2)

	cnt := make([]int64, 3, N+3)
	cnt[1], cnt[2] = 1, 1

	leafStart := 1 << (n - 1)
	for i := leafStart; i <= N; i++ {
		if s[i-1] == 'A' {
			ids[i] = 1
		} else {
			ids[i] = 2
		}
	}

	mp := make(map[Key]int, N)
	nextID := 3

	for i := leafStart - 1; i >= 1; i-- {
		l, r := ids[i*2], ids[i*2+1]
		if l > r {
			l, r = r, l
		}
		k := Key{c: s[i-1], a: l, b: r}
		id, ok := mp[k]
		if !ok {
			id = nextID
			nextID++
			mp[k] = id
			var v int64
			if l == r {
				v = cnt[l] * cnt[r] % MOD
			} else {
				v = 2 * cnt[l] % MOD * cnt[r] % MOD
			}
			cnt = append(cnt, v)
		}
		ids[i] = id
	}

	fmt.Fprint(out, cnt[ids[1]]%MOD)
}