← Home
For problem statement at 1000-1999/1100-1199/1110-1119/1112/problemE.txt this is a correct solution, but verifier at 1000-1999/1100-1199/1110-1119/1112/verifierE.go ends with case 53 failed: expected 4
1 -1
1 -1
2 -1
2 -1 got 4
1 -1
2 -1
1 -1
2 -1
input:
3
347
105
exit status 1 can you fix the verifier? package main

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

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

	var n int
	var a, b string
	if _, err := fmt.Fscan(in, &n, &a, &b); err != nil {
		return
	}

	cur := make([]int, n+1)
	d := make([]int64, n+1)
	for i := 0; i < n; i++ {
		cur[i+1] = int(a[i] - '0')
		d[i+1] = int64(int(b[i]-'0') - cur[i+1])
	}

	t := make([]int64, n)
	t[1] = d[1]
	for i := 2; i <= n-1; i++ {
		t[i] = d[i] - t[i-1]
	}
	if t[n-1] != d[n] {
		fmt.Fprintln(out, -1)
		return
	}

	var c int64
	for i := 1; i <= n-1; i++ {
		if t[i] < 0 {
			c -= t[i]
		} else {
			c += t[i]
		}
	}

	legal := func(i int) bool {
		if i < 1 || i >= n || t[i] == 0 {
			return false
		}
		if t[i] > 0 {
			return cur[i] < 9 && cur[i+1] < 9
		}
		if i == 1 {
			return cur[i] > 1 && cur[i+1] > 0
		}
		return cur[i] > 0 && cur[i+1] > 0
	}

	limit := c
	if limit > 100000 {
		limit = 100000
	}

	movesI := make([]int, 0, int(limit))
	movesS := make([]int, 0, int(limit))

	q := make([]int, 0, n+int(limit)*3+5)
	for i := 1; i <= n-1; i++ {
		if legal(i) {
			q = append(q, i)
		}
	}

	head := 0
	for int64(len(movesI)) < limit {
		for head < len(q) && !legal(q[head]) {
			head++
		}
		if head == len(q) {
			break
		}
		i := q[head]
		head++

		s := 1
		if t[i] < 0 {
			s = -1
		}

		cur[i] += s
		cur[i+1] += s
		t[i] -= int64(s)

		movesI = append(movesI, i)
		movesS = append(movesS, s)

		for j := i - 1; j <= i+1; j++ {
			if j >= 1 && j < n && legal(j) {
				q = append(q, j)
			}
		}
	}

	fmt.Fprintln(out, c)
	for i := 0; i < len(movesI); i++ {
		fmt.Fprintln(out, movesI[i], movesS[i])
	}
}