← Home
For problem statement at 0-999/600-699/650-659/659/problemF.txt this is a correct solution, but verifier at 0-999/600-699/650-659/659/verifierF.go ends with All tests passed can you fix the verifier? ```go
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1024), 1<<25)
	scanner.Split(bufio.ScanWords)

	readInt := func() int64 {
		scanner.Scan()
		var num int64
		for _, ch := range scanner.Bytes() {
			num = num*10 + int64(ch-'0')
		}
		return num
	}

	n := int(readInt())
	m := int(readInt())
	k := readInt()
	N := n * m

	type Cell struct {
		val int64
		idx int
	}
	cells := make([]Cell, N)
	grid := make([]int64, N)

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			v := readInt()
			idx := i*m + j
			grid[idx] = v
			cells[idx] = Cell{val: v, idx: idx}
		}
	}

	sort.Slice(cells, func(i, j int) bool {
		return cells[i].val > cells[j].val
	})

	parent := make([]int, N)
	sz := make([]int, N)
	active := make([]bool, N)
	for i := 0; i < N; i++ {
		parent[i] = i
		sz[i] = 1
	}

	var find func(int) int
	find = func(x int) int {
		if parent[x] != x {
			parent[x] = find(parent[x])
		}
		return parent[x]
	}

	union := func(x, y int) {
		x = find(x)
		y = find(y)
		if x == y {
			return
		}
		if sz[x] < sz[y] {
			x, y = y, x
		}
		parent[y] = x
		sz[x] += sz[y]
	}

	dx := []int{-1, 1, 0, 0}
	dy := []int{0, 0, -1, 1}

	for i := 0; i < N; {
		j := i
		H := cells[i].val

		for j < N && cells[j].val == H {
			idx := cells[j].idx
			active[idx] = true
			x := idx / m
			y := idx % m
			for dir := 0; dir < 4; dir++ {
				nx, ny := x+dx[dir], y+dy[dir]
				if nx >= 0 && nx < n && ny >= 0 && ny < m {
					nidx := nx*m + ny
					if active[nidx] {
						union(idx, nidx)
					}
				}
			}
			j++
		}

		if k%H == 0 {
			need := k / H
			if need > int64(N) {
				break
			}
			for p := i; p < j; p++ {
				idx := cells[p].idx
				root := find(idx)
				if int64(sz[root]) >= need {
					res := make([][]int64, n)
					for ii := range res {
						res[ii] = make([]int64, m)
					}
					visited := make([]bool, N)
					queue := make([]int, 0, need)
					queue = append(queue, idx)
					visited[idx] = true
					var collected int64 = 0

					for len(queue) > 0 && collected < need {
						cur := queue[0]
						queue = queue[1:]
						cx, cy := cur/m, cur%m
						res[cx][cy] = H
						collected++

						for dir := 0; dir < 4; dir++ {
							nx, ny := cx+dx[dir], cy+dy[dir]
							if nx >= 0 && nx < n && ny >= 0 && ny < m {
								nidx := nx*m + ny
								if active[nidx] && !visited[nidx] {
									visited[nidx] = true
									queue = append(queue, nidx)
								}
							}
						}
					}

					fmt.Println("YES")
					for ii := 0; ii < n; ii++ {
						for jj := 0; jj < m; jj++ {
							if jj > 0 {
								fmt.Print(" ")
							}
							fmt.Print(res[ii][jj])
						}
						fmt.Println()
					}
					return
				}
			}
		}

		i = j
	}

	fmt.Println("NO")
}
```