← Home
For problem statement at 2000-2999/2000-2099/2040-2049/2041/problemD.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2040-2049/2041/verifierD.go ends with reference runtime error: exec: "ref2041D.bin": executable file not found in $PATH can you fix the verifier? ```go
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscan(reader, &n, &m)
	reader.ReadString('\n')

	grid := make([]string, n)
	startR, startC := 0, 0
	endR, endC := 0, 0

	for i := 0; i < n; i++ {
		line, _ := reader.ReadString('\n')
		// trim trailing newline/carriage return
		for len(line) > 0 && (line[len(line)-1] == '\n' || line[len(line)-1] == '\r') {
			line = line[:len(line)-1]
		}
		grid[i] = line
		for j := 0; j < len(line); j++ {
			if line[j] == 'S' {
				startR, startC = i, j
			} else if line[j] == 'T' {
				endR, endC = i, j
			}
		}
	}

	// BFS with state (row, col, direction, consecutive_steps)
	// direction: 0=up, 1=down, 2=left, 3=right, 4=none (start)
	// consecutive: 1..3
	// State encoding: (row * m + col) * 4 * 3 + dir * 3 + (consec - 1)
	// But for the start state, we have no direction, so we handle it specially.

	// directions: 0=up, 1=down, 2=left, 3=right
	dr := [4]int{-1, 1, 0, 0}
	dc := [4]int{0, 0, -1, 1}

	// State: (r, c, dir, consec) where dir in [0..3], consec in [1..3]
	// Total states: n * m * 4 * 3
	// Plus the initial state with no direction.

	stateCount := n * m * 4 * 3
	dist := make([]int, stateCount)
	for i := range dist {
		dist[i] = -1
	}

	encode := func(r, c, d, consec int) int {
		return ((r*m+c)*4+d)*3 + (consec - 1)
	}

	queue := make([]int32, 0, stateCount)

	// From start, try all 4 directions with consec=1
	for d := 0; d < 4; d++ {
		nr := startR + dr[d]
		nc := startC + dc[d]
		if nr >= 0 && nr < n && nc >= 0 && nc < m && grid[nr][nc] != '#' {
			s := encode(nr, nc, d, 1)
			if dist[s] == -1 {
				dist[s] = 1
				queue = append(queue, int32(s))
			}
		}
	}

	head := 0
	for head < len(queue) {
		s := int(queue[head])
		head++

		rem := s
		consec := rem%3 + 1
		rem /= 3
		d := rem % 4
		rem /= 4
		c := rem % m
		r := rem / m

		curDist := dist[s]

		if r == endR && c == endC {
			fmt.Println(curDist)
			return
		}

		for nd := 0; nd < 4; nd++ {
			nr := r + dr[nd]
			nc := c + dc[nd]
			if nr < 0 || nr >= n || nc < 0 || nc >= m || grid[nr][nc] == '#' {
				continue
			}
			var newConsec int
			if nd == d {
				newConsec = consec + 1
			} else {
				newConsec = 1
			}
			if newConsec > 3 {
				continue
			}
			ns := encode(nr, nc, nd, newConsec)
			if dist[ns] == -1 {
				dist[ns] = curDist + 1
				queue = append(queue, int32(ns))
			}
		}
	}

	fmt.Println(-1)
}
```