Floor Decoration
InterviewTime limit2sMemory limit128 MB
Count the number of wooden planks by counting maximal runs of consecutive '-' in each row and '|' in each column of a grid.
- Level
Easy2 of 10
- Topics
- Matrix, Implementation, Simulation
- Solved
- No attempts yet
Problem
Hyeongtaek is an architect who designed the floor decoration for Gihoon's room. The floor is a rectangle divided into square cells parallel to the walls, and each cell contains either - or |.
Each wooden plank has width 1 and a positive integer length. Adjacent - cells in the same row belong to one horizontal plank. Adjacent | cells in the same column belong to one vertical plank.
Given the floor pattern, determine how many wooden planks are needed.
Input
The first line contains two natural numbers N and M, the height and width of the floor.
Each of the next N lines contains a string of length M. These strings describe the floor pattern and consist only of - and |.
Both N and M are at most 50.
Output
Print the number of wooden planks needed.