luogu#P4813. [CCO 2014] Troy 与三角形

[CCO 2014] Troy 与三角形

Problem Description

This problem is translated from CCO 2014 Day 1 T1 “Troyangles”.

Troy likes triangles, so he especially likes counting triangles. He has an N×NN \times N grid consisting of . and #. Help him count how many triangles made only of # appear in the grid. A triangle looks like this:

          #
    #    ###
#, ###, #####, ...

More formally, a triangle of height hh has hh rows, where hh is a positive integer. Row ii has 2i12i-1 # characters (1ih)(1 \le i \le h). The rows are centered above each other, so the triangle is symmetric about its vertical center line.

Input Format

The first line contains an integer NN, the size of the grid. The next NN lines each contain NN characters describing the grid.

Output Format

Output the number of triangles in the grid.

5
.....
.###.
.###.
#####
.....
16

Hint

For 20%20\% of the testdata, 1N501 \le N \le 50.

For 100%100\% of the testdata, 1N20001 \le N \le 2000.

Translated by ChatGPT 5