#P4961. Compute 3bv in Minesweeper

    ID: 18201 Type: Default 1000ms 256MiB

Compute 3bv in Minesweeper

Compute 3bv in Minesweeper

Given an \(n \times m\) grid representing a Minesweeper board, where a cell with 1 is a mine and 0 is not, compute the \(\mathrm{3bv}\) of the board.

A non-mine cell is classified as an empty cell (空格) if none of its adjacent 8 cells contains a mine; otherwise, if it is not a mine and has at least one adjacent mine, it is called a number cell (数字). An empty group (空) is a connected component (using 8-connectedness) of empty cells.

The \(\mathrm{3bv}\) is defined as:

\[ \mathrm{3bv} = (\text{number of number cells that have no adjacent empty cell}) + (\text{number of empty groups}) \]

If you have doubts about the calculation, please refer to the tutorial provided in the problem background or consult the sample explanation below.

Eight-connectedness

inputFormat

The first line contains two integers \(n\) and \(m\), representing the number of rows and columns of the board.

Each of the following \(n\) lines contains \(m\) space-separated integers (either 0 or 1), representing the board.

outputFormat

Output a single integer, the \(\mathrm{3bv}\) of the board.

sample

3 3
0 1 0
0 0 0
1 0 1
6