← Home
For problem statement at 1000-1999/1400-1499/1430-1439/1439/problemA2.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1430-1439/1439/verifierA2.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var moves = [4][3][2]int{
	{{0, 0}, {1, 0}, {0, 1}},
	{{0, 0}, {0, 1}, {1, 1}},
	{{0, 0}, {1, 0}, {1, 1}},
	{{0, 1}, {1, 0}, {1, 1}},
}

var parent [16]int
var moveTo [16]int

func init() {
	for i := 0; i < 16; i++ {
		parent[i] = -1
	}
	queue := []int{0}
	parent[0] = -2
	for len(queue) > 0 {
		cur := queue[0]
		queue = queue[1:]
		for mi := 0; mi < 4; mi++ {
			next := cur
			for _, c := range moves[mi] {
				bit := c[0]*2 + c[1]
				next ^= (1 << bit)
			}
			if parent[next] == -1 {
				parent[next] = cur
				moveTo[next] = mi
				queue = append(queue, next)
			}
		}
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for ; t > 0; t-- {
		scanner.Scan()
		line := scanner.Text()
		for line == "" {
			scanner.Scan()
			line = scanner.Text()
		}
		parts := strings.Fields(line)
		n, _ := strconv.Atoi(parts[0])
		m, _ := strconv.Atoi(parts[1])
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			rowStr := scanner.Text()
			grid[i] = make([]int, m)
			for j, ch := range rowStr {
				if ch == '1' {
					grid[i][j] = 1
				}
			}
		}

		ops := [][6]int{}
		addOp := func(r1, c1, r2, c2, r3, c3 int) {
			ops = append(ops, [6]int{r1 + 1, c1 + 1, r2 + 1, c2 + 1, r3 + 1, c3 + 1})
			grid[r1][c1] ^= 1
			grid[r2][c2] ^= 1
			grid[r3][c3] ^= 1
		}

		for i := 0; i < n-2; i++ {
			for j := 0; j < m-2; j++ {
				if grid[i][j] == 1 {
					addOp(i, j, i+1, j, i, j+1)
				}
			}
		}

		if n >= 2 && m >= 2 {
			for j := 0; j < m-2; j++ {
				a := grid[n-2][j]
				b := grid[n-1][j]
				if a == 1 && b == 1 {
					addOp(n-2, j, n-1, j, n-2, j+1)
				} else if a == 1 {
					addOp(n-2, j, n-2, j+1, n-1, j+1)
				} else if b == 1 {
					addOp(n-1, j, n-2, j+1, n-1, j+1)
				}
			}
		}

		if n >= 2 && m >= 2 {
			for i := 0; i < n-2; i++ {
				a := grid[i][m-2]
				b := grid[i][m-1]
				if a == 1 && b == 1 {
					addOp(i, m-2, i, m-1, i+1, m-2)
				} else if a == 1 {
					addOp(i, m-2, i+1, m-2, i+1, m-1)
				} else if b == 1 {
					addOp(i, m-1, i+1, m-2, i+1, m-1)
				}
			}
		}

		if n >= 2 && m >= 2 {
			baseR := n - 2
			baseC := m - 2
			state := 0
			if grid[baseR][baseC] == 1 {
				state |= 1
			}
			if grid[baseR][baseC+1] == 1 {
				state |= 2
			}
			if grid[baseR+1][baseC] == 1 {
				state |= 4
			}
			if grid[baseR+1][baseC+1] == 1 {
				state |= 8
			}
			var seq []int
			for state != 0 {
				mi := moveTo[state]
				seq = append(seq, mi)
				state = parent[state]
			}
			for _, mi := range seq {
				cells := moves[mi]
				addOp(baseR+cells[0][0], baseC+cells[0][1],
					baseR+cells[1][0], baseC+cells[1][1],
					baseR+cells[2][0], baseC+cells[2][1])
			}
		}

		fmt.Println(len(ops))
		for _, op := range ops {
			fmt.Printf("%d %d %d %d %d %d\n", op[0], op[1], op[2], op[3], op[4], op[5])
		}
	}
}
```