← Home
For problem statement at 0-999/800-899/820-829/828/problemB.txt this is a correct solution, but verifier at 0-999/800-899/820-829/828/verifierB.go ends with All tests passed can you fix the verifier? package main

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

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

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

	minR, minC := n, m
	maxR, maxC := -1, -1
	black := 0

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j, ch := range s {
			if ch == 'B' {
				black++
				if i < minR {
					minR = i
				}
				if i > maxR {
					maxR = i
				}
				if j < minC {
					minC = j
				}
				if j > maxC {
					maxC = j
				}
			}
		}
	}

	if black == 0 {
		fmt.Println(1)
		return
	}

	h := maxR - minR + 1
	w := maxC - minC + 1
	side := h
	if w > side {
		side = w
	}

	if side > n || side > m {
		fmt.Println(-1)
		return
	}

	fmt.Println(side*side - black)
}