← Home
For problem statement at 1000-1999/1400-1499/1490-1499/1492/problemE.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1490-1499/1492/verifierE.go ends with case 17 failed
input:
3 4
10 9 5 8
7 1 5 9
9 2 8 8
expected:
Yes
9 1 5 8
got:
Yes
7 2 5 8
exit status 1 can you fix the verifier? package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	m, _ := strconv.Atoi(scanner.Text())

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
		for j := 0; j < m; j++ {
			scanner.Scan()
			A[i][j], _ = strconv.Atoi(scanner.Text())
		}
	}

	var solve func(X []int, changes int) []int
	solve = func(X []int, changes int) []int {
		for i := 0; i < n; i++ {
			diffCount := 0
			for j := 0; j < m; j++ {
				if X[j] != A[i][j] {
					diffCount++
				}
			}
			if diffCount > 2 {
				k := diffCount - 2
				if k > changes {
					return nil
				}

				diffs := make([]int, 0, diffCount)
				for j := 0; j < m; j++ {
					if X[j] != A[i][j] {
						diffs = append(diffs, j)
					}
				}

				var subsets [][]int
				if k == 1 {
					for _, d := range diffs {
						subsets = append(subsets, []int{d})
					}
				} else if k == 2 {
					for x := 0; x < len(diffs); x++ {
						for y := x + 1; y < len(diffs); y++ {
							subsets = append(subsets, []int{diffs[x], diffs[y]})
						}
					}
				}

				for _, subset := range subsets {
					X_new := make([]int, m)
					copy(X_new, X)
					for _, idx := range subset {
						X_new[idx] = A[i][idx]
					}
					res := solve(X_new, changes-k)
					if res != nil {
						return res
					}
				}
				return nil
			}
		}
		return X
	}

	ans := solve(A[0], 2)
	if ans != nil {
		fmt.Println("Yes")
		out := make([]string, m)
		for i, val := range ans {
			out[i] = strconv.Itoa(val)
		}
		fmt.Println(strings.Join(out, " "))
	} else {
		fmt.Println("No")
	}
}