← Home
For problem statement at 1000-1999/1800-1899/1890-1899/1895/problemC.txt this is a correct solution, but verifier at 1000-1999/1800-1899/1890-1899/1895/verifierC.go ends with case 37 failed
input:
5
69926
578
92
41580
5896
expected 6 got 7
exit status 1 can you fix the verifier? package main

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

type Ticket struct {
	l   int
	s   int
	pre [6]int
}

func main() {
	data, _ := io.ReadAll(os.Stdin)
	idx := 0

	nextInt := func() int {
		for idx < len(data) && data[idx] <= ' ' {
			idx++
		}
		val := 0
		for idx < len(data) && data[idx] > ' ' {
			val = val*10 + int(data[idx]-'0')
			idx++
		}
		return val
	}

	nextStr := func() []byte {
		for idx < len(data) && data[idx] <= ' ' {
			idx++
		}
		start := idx
		for idx < len(data) && data[idx] > ' ' {
			idx++
		}
		return data[start:idx]
	}

	n := nextInt()
	arr := make([]Ticket, n)
	var cnt [6][46]int64

	for i := 0; i < n; i++ {
		b := nextStr()
		l := len(b)
		var pre [6]int
		sum := 0
		for j := 0; j < l; j++ {
			sum += int(b[j] - '0')
			pre[j+1] = sum
		}
		arr[i] = Ticket{l: l, s: sum, pre: pre}
		cnt[l][sum]++
	}

	var ans int64

	for _, t := range arr {
		x := t.l
		for y := 1; y <= x; y++ {
			if (x+y)%2 != 0 {
				continue
			}
			h := (x + y) / 2
			req := 2*t.pre[h] - t.s
			if req >= y && req <= 9*y {
				ans += cnt[y][req]
			}
		}
	}

	for _, t := range arr {
		y := t.l
		for x := 1; x < y; x++ {
			if (x+y)%2 != 0 {
				continue
			}
			k := (y - x) / 2
			req := t.s - 2*t.pre[k]
			if req >= x && req <= 9*x {
				ans += cnt[x][req]
			}
		}
	}

	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, ans)
	out.Flush()
}