← Home
For problem statement at 1000-1999/1900-1999/1940-1949/1948/problemC.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1940-1949/1948/verifierC.go ends with case 3: expected NO, got YES

exit status 1 can you fix the verifier? package main

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

type FastScanner struct {
	data []byte
	idx  int
	n    int
}

func NewFastScanner() *FastScanner {
	data, _ := io.ReadAll(os.Stdin)
	return &FastScanner{data: data, n: len(data)}
}

func (fs *FastScanner) skip() {
	for fs.idx < fs.n {
		b := fs.data[fs.idx]
		if b > ' ' {
			break
		}
		fs.idx++
	}
}

func (fs *FastScanner) NextInt() int {
	fs.skip()
	val := 0
	for fs.idx < fs.n {
		b := fs.data[fs.idx]
		if b < '0' || b > '9' {
			break
		}
		val = val*10 + int(b-'0')
		fs.idx++
	}
	return val
}

func (fs *FastScanner) NextBytes() []byte {
	fs.skip()
	start := fs.idx
	for fs.idx < fs.n && fs.data[fs.idx] > ' ' {
		fs.idx++
	}
	return fs.data[start:fs.idx]
}

func solve(n int, a, b []byte) bool {
	rows := [2][]byte{a, b}
	off := 2 * n
	total := 4 * n

	vis := make([]bool, total)
	q := make([]int, total)
	head, tail := 0, 0

	vis[0] = true
	q[tail] = 0
	tail++

	for head < tail {
		id := q[head]
		head++

		phase := 0
		if id >= off {
			phase = 1
			id -= off
		}

		row := id / n
		col := id % n

		if row == 1 && col == n-1 {
			return true
		}

		if phase == 0 {
			if col > 0 {
				nid := off + row*n + col - 1
				if !vis[nid] {
					vis[nid] = true
					q[tail] = nid
					tail++
				}
			}
			if col+1 < n {
				nid := off + row*n + col + 1
				if !vis[nid] {
					vis[nid] = true
					q[tail] = nid
					tail++
				}
			}
			nid := off + (1-row)*n + col
			if !vis[nid] {
				vis[nid] = true
				q[tail] = nid
				tail++
			}
		} else {
			nc := col - 1
			if rows[row][col] == '>' {
				nc = col + 1
			}
			nid := row*n + nc
			if !vis[nid] {
				vis[nid] = true
				q[tail] = nid
				tail++
			}
		}
	}

	return false
}

func main() {
	fs := NewFastScanner()
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	t := fs.NextInt()
	for ; t > 0; t-- {
		n := fs.NextInt()
		a := fs.NextBytes()
		b := fs.NextBytes()
		if solve(n, a, b) {
			out.WriteString("YES\n")
		} else {
			out.WriteString("NO\n")
		}
	}
}