#K53817. Minimum Sprinkler Problem

    ID: 29616 Type: Default 1000ms 256MiB

Minimum Sprinkler Problem

Minimum Sprinkler Problem

You are given a rectangular garden represented as an n x m grid of characters. Each cell in the grid is either a plant represented by '*' or an empty cell represented by '.'. The garden is arranged in rows and columns. A sprinkler placed on the garden can water an entire row or an entire column. The goal is to determine the minimum number of sprinklers required to water every plant in the garden.

Note: Even if there are no plants in the garden, the answer is 0.

Core Idea: Identify the rows and columns that contain plants and the answer is the minimum of the count of such rows and columns, i.e., \(\min(\text{number of rows with plants}, \text{number of columns with plants})\).

inputFormat

The input is read from stdin and consists of:

  1. The first line contains two integers n and m representing the number of rows and columns of the garden.
  2. Each of the following n lines contains a string of length m representing one row of the garden. Each character is either '*' (a plant) or '.' (an empty cell).

outputFormat

Output to stdout a single integer which is the minimum number of sprinklers required to water all the plants in the garden.

## sample
3 4
.*..
..*.
....
2