#C2202. Finding the Largest Lake in a Grid
Finding the Largest Lake in a Grid
Finding the Largest Lake in a Grid
You are given a grid of size \(n \times m\) consisting of characters '0' and '1'. The character '0' represents water and '1' represents land. A lake is defined as a set of connected water cells (cells with '0') where connectivity is considered in the four cardinal directions (up, down, left, right). Your task is to determine the area (i.e., the number of cells) of the largest lake in the grid.
Input Format: The grid is provided via standard input. The first line contains two integers \(n\) and \(m\) separated by a space, representing the number of rows and columns, respectively. Each of the next \(n\) lines contains \(m\) characters (each being either '0' or '1') separated by spaces.
Output Format: Output a single integer representing the area of the largest lake found in the grid. If there is no water cell, output 0.
Example:
Input:
4 5 1 0 1 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1
Output:
7
Note: The connectivity is defined only in the horizontal and vertical directions.
inputFormat
The first line contains two space-separated integers \(n\) and \(m\) indicating the number of rows and columns of the grid. The next \(n\) lines each contain \(m\) space-separated characters ('0' or '1').
outputFormat
Output a single integer which is the area of the largest lake found in the grid.
## sample4 5
1 0 1 1 0
0 0 1 0 0
1 0 0 1 0
0 0 1 0 1
7