Beach
InterviewTime limit2sMemory limit512 MB
Count the hexagon edges that separate land from water, ignoring any edge on the outer border of the map.
- Level
Medium4 of 10
- Topics
- Implementation, Matrix, Simulation, Geometry
- Solved
- No attempts yet
Problem
You are given a map made of unit regular hexagons. Write a program that computes the length of the beach.
A beach is a hexagon edge with water on one side and land on the other. Each edge has length 1. The area outside the map counts as neither water nor land, so an edge on the border of the map is never a beach.
The map has rows, and each row is hexagons placed side by side. Counting from the top, every even-numbered row (the 2nd, the 4th, and so on) is shifted half a cell to the right of the row directly above it. The figure below shows the map of the second example, with the beach edges drawn in red.

Input
The first line contains the height and the width of the map. ()
Each of the next lines contains one row of the map as a string of length . . is water and # is land.
Output
Print the length of the beach on the first line.