#P8325. [COCI 2021/2022 #5] Dijamant

[COCI 2021/2022 #5] Dijamant

Problem Description

Several “diamonds” are placed on the table.

When a square is rotated by 4545^\circ, it forms a “rhombus” shape. A shape whose outline looks like a “rhombus”, with the entire outer border made of #\texttt \# and the entire interior made of .\texttt . is defined as one “diamond”.

Given a table of size n×mn \times m, count how many “diamonds” are placed on the table.

Input Format

The first line contains two positive integers n,mn, m, representing the size of the table.

The next nn lines each contain mm characters #\texttt \# or .\texttt . , representing the table.

Output Format

The number of “diamonds”.

7 25
.#...#....#....#.....#...
#.#..#...#.#...#....#.#..
.#...#..#...#..#...#...#.
.....#...#.#...#..#.....#
.....#....#....#...#...#.
.....#.........#....#.#..
.....#.........#.....#...
3
11 17
.....#........#..
....#.#........#.
...#...#....#...#
..#.....#....#.#.
.#....#..#....#..
#....#.#..#......
.#....#..#.......
..#.....#........
...#...#.........
....#.#..........
.....#...........
1
5 11
##.#.#.#.##
#.#.#.#.#.#
.#.#.#.#.#.
#.#.#.#.#.#
##.#.#.#.##
14

Hint

[Sample 2 Explanation]

It looks like there are 33 diamonds, but in fact two “rhombuses” contain each other, so they do not meet the definition “outer border is all #\texttt \# but the interior is all .\texttt .”. Therefore, there is only 11 diamond.

[Constraints and Notes]

This problem uses bundled tests.

  • Subtask 1 (20 pts): 1n,m1001 \le n, m \le 100.
  • Subtask 2 (50 pts): no special restrictions.

For 100%100\% of the testdata, 1n,m20001 \le n, m \le 2000.

[Source] COCI 2021-2022#5 Task 2 Dijamant.

Translated by ChatGPT 5