← Home
For problem statement at 0-999/200-299/210-219/212/problemB.txt this is a correct solution, but verifier at 0-999/200-299/210-219/212/verifierB.go ends with reference failed: expected 2033 answers, got 0 (output: "")
exit status 1 can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2000000), 2000000)

	if !scanner.Scan() {
		return
	}
	var s []byte
	for _, b := range scanner.Bytes() {
		if b >= 'a' && b <= 'z' {
			s = append(s, b)
		}
	}
	n := len(s)
	if n == 0 {
		return
	}

	if !scanner.Scan() {
		return
	}
	mStr := strings.TrimSpace(scanner.Text())
	m, _ := strconv.Atoi(mStr)

	numWords := (n + 63) / 64
	bitsets := make([][]uint64, 26)
	for c := 0; c < 26; c++ {
		bitsets[c] = make([]uint64, numWords)
	}
	for i, b := range s {
		c := b - 'a'
		word := i / 64
		bit := i % 64
		bitsets[c][word] |= uint64(1) << bit
	}

	nextPos := make([][26]int32, n+1)
	for c := 0; c < 26; c++ {
		nextPos[n][c] = int32(n)
	}
	for i := n - 1; i >= 0; i-- {
		nextPos[i] = nextPos[i+1]
		nextPos[i][s[i]-'a'] = int32(i)
	}

	valid := make([]uint64, numWords)
	charsInMask := make([]int, 0, 26)
	memo := make(map[uint32]int)

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for i := 0; i < m; i++ {
		scanner.Scan()
		q := scanner.Bytes()

		maskC := uint32(0)
		for _, b := range q {
			if b >= 'a' && b <= 'z' {
				maskC |= 1 << (b - 'a')
			}
		}

		if val, ok := memo[maskC]; ok {
			fmt.Fprintln(out, val)
			continue
		}

		charsInMask = charsInMask[:0]
		for c := 0; c < 26; c++ {
			if (maskC & (1 << c)) != 0 {
				charsInMask = append(charsInMask, c)
			}
		}
		numChars := len(charsInMask)

		for j := 0; j < numWords; j++ {
			valid[j] = 0
		}
		for _, c := range charsInMask {
			bc := bitsets[c]
			for j := 0; j < numWords; j++ {
				valid[j] |= bc[j]
			}
		}

		if n%64 != 0 {
			valid[numWords-1] &= (uint64(1) << (n % 64)) - 1
		}

		count := 0
		inBlock := false
		l := 0

		for j := 0; j < numWords; j++ {
			v := valid[j]
			b := 0
			for b < 64 {
				if inBlock {
					inv := (^v) & (^uint64(0) << b)
					if inv == 0 {
						break
					}
					tz := bits.TrailingZeros64(inv)
					r := j*64 + tz - 1
					if r-l+1 >= numChars {
						ok := true
						for _, c := range charsInMask {
							if nextPos[l][c] > int32(r) {
								ok = false
								break
							}
						}
						if ok {
							count++
						}
					}
					inBlock = false
					b = tz + 1
				} else {
					rem := v & (^uint64(0) << b)
					if rem == 0 {
						break
					}
					tz := bits.TrailingZeros64(rem)
					l = j*64 + tz
					inBlock = true
					b = tz + 1
				}
			}
		}

		if inBlock {
			r := n - 1
			if r-l+1 >= numChars {
				ok := true
				for _, c := range charsInMask {
					if nextPos[l][c] > int32(r) {
						ok = false
						break
					}
				}
				if ok {
					count++
				}
			}
		}

		memo[maskC] = count
		fmt.Fprintln(out, count)
	}
}