P27210 [AtCoder] Illumination
提高+
题目描述

Problem Description

The building of JOI Inc. is shaped by connecting regular hexagons with sides of 1 meter, as shown in the figure. As Christmas is approaching, JOI Inc. decided to decorate the building's wall surfaces with illumination. However, it would be wasteful to install illumination on parts that are not visible from the outside, so they decided to only decorate the wall surfaces that can be reached without entering the building.

Example of the layout of JOI Inc.'s building

The figure above is an example of the layout of JOI Inc.'s building viewed from above. The numbers inside the hexagons represent coordinates. Gray hexagons indicate areas where buildings are located, while white hexagons indicate areas where there are no buildings. In this example, the parts indicated by the red solid lines are the wall surfaces to be decorated with illumination, and the total length of these wall surfaces is 64 meters.

Given a map representing the layout of JOI Inc.'s buildings, create a program to calculate the total length of the wall surfaces to be decorated with illumination. Note that the outer side of the map is freely accessible, and it is impossible to pass between adjacent buildings.


Input Format

The first line of the input file contains two integers \( W, H \) (\( 1 \leq W \leq 100 \), \( 1 \leq H \leq 100 \)) separated by a space. The following \( H \) lines contain the layout of JOI Inc.'s buildings. The \( i + 1 \)-th line (\( 1 \leq i \leq H \)) contains \( W \) integers separated by spaces, where the \( j \)-th integer (\( 1 \leq j \leq W \)) is 1 if there is a building at coordinate \( (j, i) \) and 0 if there is no building. The given input data always contains at least one building.

The map is described according to the following rules:
The most northwestern hexagon in the northernmost row has coordinate \( (1, 1) \).
The eastern adjacent hexagon to the hexagon at coordinate \( (x, y) \) has coordinate \( (x + 1, y) \).
If \( y \) is odd, the southwestern adjacent hexagon to the hexagon at coordinate \( (x, y) \) has coordinate \( (x, y + 1) \).
If \( y \) is even, the southeastern adjacent hexagon to the hexagon at coordinate \( (x, y) \) has coordinate \( (x, y + 1) \).

Output Format

Output the total length of the wall surfaces to be decorated with illumination in one line.


Sample Input and Output

Sample Input #1

8 4
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 0
1 0 1 0 1 1 1 1
0 1 1 0 1 0 1 0

Sample Output #1

64

Sample Input #2

8 5
0 1 1 1 0 1 1 1
0 1 0 0 1 1 0 0
1 0 0 1 1 1 1 1
0 1 0 1 1 0 1 0
0 1 1 0 1 1 0 0

Sample Output #2

56

Notes/Hints

Sample Explanation 1

The input/output example 1 corresponds to the example in the problem statement, where the total length of the wall surfaces to be decorated with illumination is 64 meters.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
8 4 0 1 0 1 0 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0
样例输出
64