The Rainy Season

2.6

9 votes
Very-Easy
Problem

There is an island in the form of MxN grid where each cell either has a tower built on it or is empty. Each cell is a square of unit area and each tower has a height of 1 unit.
Monsoon has come and rain has started, The king of the island wants to estimate how much volume of water would be trapped in between the towers.
Water will be trapped, only if it does not reach to the corner and flows out. Water from the current cell can reach to another cell only if that cell shares an edge with the current cell.

Constraints
1<= MxN <= 1000000

 

INPUT
The first line will contain two integers M and N, then the following lines will contain a grid of MxN, where ''* denotes that cell is blocked and '.' denotes that it is empty.

OUTPUT
The output would contain the volume of water trapped.

 

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?