#P2315. [HNOI2005] 数三角形

    ID: 1284 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2005各省省选树状数组湖南枚举,暴力概率论,统计

[HNOI2005] 数三角形

Description

Xiao Su sees an equilateral triangle: each side of the equilateral triangle has length nn and is divided into nn equal parts, so each side has n1n-1 division points. The whole triangle is divided into n2n^2 unit equilateral triangles (with side length 11) by segments that connect division points on two different sides and are parallel to the third side. The figure on the left below shows the case n=5n=5:

Xiao Su wants to know, after deleting some of the short edges, how many triangles are formed by the remaining edges (including all triangles with side length mm (1m<n1 \le m < n), counting both upright and inverted ones). A triangle is counted if all its 3m3m short edges have not been deleted. For example, in the figure on the right above, there are 1919 triangles.

Input Format

All short edges of the large triangle can be regarded as the boundaries of n(n+1)2\dfrac{n(n+1)}{2} unit triangles, as shown by the gray triangles in the figure below. There is 11 gray triangle in the 11st row, 22 gray triangles in the 22nd row, …, and nn gray triangles in the nnth row. Therefore, the input format is specified as follows:

The first line contains a positive integer nn (1n10001 \le n \le 1000), which is the side length of the large triangle.

The next nn lines: on the (i+1)(i+1)-th line there are ii groups of numbers. From left to right, each group describes one triangle. Each group contains 33 numbers, each either 00 or 11, indicating whether the corresponding short edge is deleted. 00 means deleted, 11 means not deleted. The three numbers describe, in order, the left, right, and bottom edges of the triangle. Therefore, the (i+1)(i+1)-th line contains 3i3i numbers, each being 00 or 11.

Output Format

Output a single integer TT, the number of triangles whose boundaries have not been deleted.

5
1 1 1
1 1 0 1 1 0
1 1 1 1 1 1 1 0 1
1 0 1 1 1 1 0 1 1 1 1 1
0 1 1 1 1 1 0 1 1 1 1 1 0 1 1

19

Hint

Translated by ChatGPT 5