#C484. Surveillance Camera Coverage in a Park Grid

    ID: 48422 Type: Default 1000ms 256MiB

Surveillance Camera Coverage in a Park Grid

Surveillance Camera Coverage in a Park Grid

You are given a park layout represented as an n×m grid. Each cell in this grid is either accessible (denoted by .) or blocked (denoted by #). Your task is to determine the minimum number of surveillance cameras required to monitor all accessible cells.

Since a single camera can cover all accessible cells if at least one exists, the answer is 1 when there is any accessible cell, and 0 if every cell is blocked.

Formally, given an integer $n$ and an integer $m$, and a grid $G$ of size $n \times m$, output 1 if there exists an index pair $(i,j)$ such that $G_{ij} = \text{'.'}$; otherwise, output 0.

inputFormat

The input is read from standard input (stdin) and has the following format:

<n> <m>
<row_1>
<row_2>
...
<row_n>

Where:

  • n is the number of rows in the grid.
  • m is the number of columns in the grid.
  • Each row consists of exactly m characters, where . indicates an accessible cell and # indicates a blocked cell.

outputFormat

Output a single integer to standard output (stdout):

  • 1 if there is at least one accessible cell in the grid.
  • 0 if all cells are blocked.
## sample
3 3
###
#.#
###
1