Harry Potter and Voldemort's Nose
InterviewTime limit2sMemory limit1024 MB
Count the pairs of horizontally or vertically adjacent free cells in an n by m grid, where each pair can hold the nose.
- Level
Easy2 of 10
- Topics
- Implementation, Matrix
- Solved
- No attempts yet
Statement
At Hogwarts, back when Lord Voldemort was still called Tom Marvolo Riddle, he was a fairly attractive young man. Numerous dark deeds ruined his appearance: they cost him his nose.
Modern plastic surgery can fix this. He signed up for an operation to build an artificial nose, and the only remaining question is where to place it. He approached that question mathematically.
Voldemort's face is simplified to a grid rectangle with rows and columns. His new nose occupies exactly two cells that share a horizontal or vertical side. His eyes and mouth already occupy some cells, and the nose cannot overlap them. He wants to know how many ways he can place the nose on his face.
Input
The first line contains two integers and (), the dimensions of Voldemort's face. Each of the next lines contains characters describing the face. The character # marks a cell that is already occupied, and the character . marks a free cell that may become one of the two cells of the nose.
Output
Print one integer, the number of ways to place the nose on the face.