← Home
For problem statement at 1000-1999/1500-1599/1590-1599/1592/problemF1.txt this is a correct solution, but verifier at 1000-1999/1500-1599/1590-1599/1592/verifierF1.go ends with All 120 tests passed can you fix the verifier? package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var n, m int
	fmt.Fscan(in, &n, &m)

	a := make([][]int, n+1)
	for i := range a {
		a[i] = make([]int, m+1)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			if s[j] == 'B' {
				a[i][j] = 1
			}
		}
	}

	t := make([][]byte, n)
	cnt := 0
	for i := 0; i < n; i++ {
		t[i] = make([]byte, m)
	}
	for i := n - 1; i >= 0; i-- {
		for j := m - 1; j >= 0; j-- {
			v := a[i][j] ^ a[i+1][j] ^ a[i][j+1] ^ a[i+1][j+1]
			t[i][j] = byte(v)
			cnt += v
		}
	}

	ans := cnt
	if n >= 2 && m >= 2 && t[n-1][m-1] == 1 {
		rowRight := make([]bool, n-1)
		colBottom := make([]bool, m-1)
		for i := 0; i < n-1; i++ {
			rowRight[i] = t[i][m-1] == 1
		}
		for j := 0; j < m-1; j++ {
			colBottom[j] = t[n-1][j] == 1
		}
		found := false
		for i := 0; i < n-1 && !found; i++ {
			if !rowRight[i] {
				continue
			}
			for j := 0; j < m-1; j++ {
				if t[i][j] == 1 && colBottom[j] {
					found = true
					break
				}
			}
		}
		if found {
			ans--
		}
	}

	fmt.Fprintln(out, ans)
}