103002: [Atcoder]ABC300 C - Cross

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:12 Solved:0

Description

Score : $300$ points

Problem Statement

We have a grid with $H$ horizontal rows and $W$ vertical columns. We denote by $(i, j)$ the cell at the $i$-th column from the top and $j$-th column from the left of the grid.
Each cell in the grid has a symbol # or . written on it. Let $C[i][j]$ be the character written on $(i, j)$. For integers $i$ and $j$ such that at least one of $1 \leq i \leq H$ and $1 \leq j \leq W$ is violated, we define $C[i][j]$ to be ..

$(4n+1)$ squares, consisting of $(a, b)$ and $(a+d,b+d),(a+d,b-d),(a-d,b+d),(a-d,b-d)$ $(1 \leq d \leq n, 1 \leq n)$, are said to be a cross of size $n$ centered at $(a,b)$ if and only if all of the following conditions are satisfied:

  • $C[a][ b ]$ is #.
  • $C[a+d][b+d],C[a+d][b-d],C[a-d][b+d]$, and $C[a-d][b-d]$ are all #, for all integers $d$ such that $1 \leq d \leq n$,
  • At least one of $C[a+n+1][b+n+1],C[a+n+1][b-n-1],C[a-n-1][b+n+1]$, and $C[a-n-1][b-n-1]$ is ..

For example, the grid in the following figure has a cross of size $1$ centered at $(2, 2)$ and another of size $2$ centered at $(3, 7)$.

image

The grid has some crosses. No # is written on the cells except for those comprising a cross.
Additionally, no two squares that comprise two different crosses share a corner. The two grids in the following figure are the examples of grids where two squares that comprise different crosses share a corner; such grids are not given as an input. For example, the left grid is invalid because $(3, 3)$ and $(4, 4)$ share a corner.

image2

Let $N = \min(H, W)$, and $S_n$ be the number of crosses of size $n$. Find $S_1, S_2, \dots, S_N$.

Constraints

  • $3 \leq H, W \leq 100$
  • $C[i][j]$ is # or ..
  • No two different squares that comprise two different crosses share a corner.
  • $H$ and $W$ are integers.

Input

The input is given from Standard Input in the following format:

$H$ $W$
$C[1][1]C[1][2]\dots C[1][W]$
$C[2][1]C[2][2]\dots C[2][W]$
$\vdots$
$C[H][1]C[H][2]\dots C[H][W]$

Output

Print $S_1, S_2, \dots$, and $S_N$, separated by spaces.


Sample Input 1

5 9
#.#.#...#
.#...#.#.
#.#...#..
.....#.#.
....#...#

Sample Output 1

1 1 0 0 0

As described in the Problem Statement, there are a cross of size $1$ centered at $(2, 2)$ and another of size $2$ centered at $(3, 7)$.


Sample Input 2

3 3
...
...
...

Sample Output 2

0 0 0

There may be no cross.


Sample Input 3

3 16
#.#.....#.#..#.#
.#.......#....#.
#.#.....#.#..#.#

Sample Output 3

3 0 0

Sample Input 4

15 20
#.#..#.............#
.#....#....#.#....#.
#.#....#....#....#..
........#..#.#..#...
#.....#..#.....#....
.#...#....#...#..#.#
..#.#......#.#....#.
...#........#....#.#
..#.#......#.#......
.#...#....#...#.....
#.....#..#.....#....
........#.......#...
#.#....#....#.#..#..
.#....#......#....#.
#.#..#......#.#....#

Sample Output 4

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

Input

题意翻译

给定一个 $H \times W$ 的矩阵(只有 `#` 和 `.` 这两种字符,第 $i$ 行第 $j$ 列的元素记作 $C_{i,j}$),求其中由字符 `#` 组成的、大小为 $i$ 的十字架个数(记作 $S_i$)。 把 $S_{1...\min(H,W)}$ 依次输出。 对大小为 $x$ 的十字架的定义: 如果数对 $(i,j)$ 满足以下条件,则称由 $C_{i,j},C_{i-1,j-1},C_{i-2,j-2},...C_{i-x,j-x},$ $C_{i-1,j+1},C_{i-2,j+2},...C_{i-x,j+x},$ $C_{i+1,j-1},C_{i+2,j-2},...C_{i+x,j-x},$ $C_{i+1,j+1},C_{i+2,j+2},...C_{i+x,j+x},$ 这 $4x+1$ 个点组成的图形为大小为 $x$ 的十字架(不同十字架之间不共享顶点)。 - $C_{i,j}$ 是字符 `#`。 - 对于整数 $d$($ 1 \leq d \leq x $), $C_{i+d,j+d},C_{i+d,j-d},C_{i-d,j+d},C_{i-d,j-d}$ 都是字符 `#`。 - $C_{i+x+1,j+x+1},C_{i+x+1,j-x-1},C_{i-x-1,j+x+1},C_{i-x-1,j-x-1}$ 至少有一个是 `.` 。 数据范围:$3 \leq H,W \leq 100$

Output

题目描述

我们有一个网格,其中包含$H$行和$W$列。我们将表示为$(i, j)$的单元格定义为网格的顶部第$i$行和左侧第$j$列。每个单元格上都写有一个符号#.。令$C[i][j]$表示写在$(i, j)$上的字符。对于使得至少有一个$1 \leq i \leq H$和$1 \leq j \leq W$成立的整数$i$和$j$,我们定义$C[i][j]$为.

$(4n+1)$个正方形,由$(a, b)$和$(a+d,b+d),(a+d,b-d),(a-d,b+d),(a-d,b-d)$ $(1 \leq d \leq n, 1 \leq n)$组成,当且仅当满足以下所有条件时,称为以$(a,b)$为中心的大小为$n$的十字形:

  • $C[a]$是#
  • 对于使得$1 \leq d \leq n$成立的所有整数$d$,$C[a+d][b+d],C[a+d][b-d],C[a-d][b+d]$和$C[a-d][b-d]$都是#
  • 至少有一个$C[a+n+1][b+n+1],C[a+n+1][b-n-1],C[a-n-1][b+n+1]$和$C[a-n-1][b-n-1]$是.

例如,如图所示的网格有一个以$(2, 2)$为中心的大小为$1$的十字形,以及一个以$(3, 7)$为中心的大小为$2$的十字形。

image

网格中有一些十字形。除了构成十字形的单元格外,没有任何单元格写有#。此外,构成两个不同十字形的两个正方形不能共享一个角落。以下是两个共享不同十字形角落的网格的示例;这样的网格不会作为输入给出。例如,左图是无效的,因为$(3, 3)$和$(4, 4)$共享一个角落。

image2

令$N = \min(H, W)$,$S_n$表示大小为$n$的十字形的数量。找到$S_1, S_2, \dots, S_N$。

约束

  • $3 \leq H, W \leq 100$
  • $C[i][j]$是#.
  • 没有两个不同的正方形构成两个不同的十字形并共享一个角落。
  • $H$和$W$是整数。

输入

输入从标准输入以以下格式给出:

$H$ $W$
$C[1][1]C[1][2]\dots C[1][W]$
$C[2][1]C[2][2]\dots C[2][W]$
$\vdots$
$C[H][1]C[H][2]\dots C[H][W]$

输出

以空格分隔的方式打印$S_1, S_2, \dots$和$S_N$。


样例输入 1

5 9
#.#.#...#
.#...#.#.
#.#...#..
.....#.#.
....#...#

样例输出 1

1 1 0 0 0

如问题描述中所述,有一个以$(2, 2)$为中心的大小为$1$的十字形,以及一个以$(3, 7)$为中心的大小为$2$的十字形。


样例输入 2

3 3
...
...
...

样例输出 2

0 0 0

可能没有十字形。


样例输入 3

3 16
#.#.....#.#..#.#
.#.......#....#.
#.#.....#.#..#.#

样例输出 3

3 0 0

样例输入 4

15 20
#.#..#.............#
.#....#....#.#....#.
#.#....#....#....#..		  

HINT

宽度为1、2、3……的4n+1图形分别有多少个?

加入题单

上一题 下一题 算法标签: