Codeforces Round 689 (Div. 2, based on Zed Code Competition)
B
Find the Spruce
Codeforces
1400
原题
← AC →
翻译中…

Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an $n \times m$ matrix consisting of "*" and ".".

翻译中…

image

翻译中…

To find every spruce first let's define what a spruce in the matrix is. A set of matrix cells is called a spruce of height $k$ with origin at point $(x, y)$ if:

翻译中…
  • All cells in the set contain an "*".
  • For each $1 \le i \le k$ all cells with the row number $x+i-1$ and columns in range $[y - i + 1, y + i - 1]$ must be a part of the set. All other cells cannot belong to the set.
翻译中…

Examples of correct and incorrect spruce trees:

翻译中…

image

翻译中…

Now Rick wants to know how many spruces his $n \times m$ matrix contains. Help Rick solve this problem.

翻译中…

Input

翻译中…

Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$).

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 500$) — matrix size.

翻译中…

Next $n$ lines of each test case contain $m$ characters $c_{i, j}$ — matrix contents. It is guaranteed that $c_{i, j}$ is either a "." or an "*".

翻译中…

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $500^2$ ($\sum n \cdot m \le 500^2$).

翻译中…

Output

翻译中…

For each test case, print single integer — the total number of spruces in the matrix.

翻译中…

Note

翻译中…

In the first test case the first spruce of height $2$ has its origin at point $(1, 2)$, the second spruce of height $1$ has its origin at point $(1, 2)$, the third spruce of height $1$ has its origin at point $(2, 1)$, the fourth spruce of height $1$ has its origin at point $(2, 2)$, the fifth spruce of height $1$ has its origin at point $(2, 3)$.

翻译中…

In the second test case the first spruce of height $1$ has its origin at point $(1, 2)$, the second spruce of height $1$ has its origin at point $(2, 1)$, the third spruce of height $1$ has its origin at point $(2, 2)$.

翻译中…

样例

Input #1
4
2 3
.*.
***
2 3
.*.
**.
4 5
.***.
*****
*****
*.*.*
5 7
..*.*..
.*****.
*******
.*****.
..*.*..
Output #1
5
3
23
34
InputCopy OutputCopy
题目信息
题号
1461B
时间限制
1 s
内存限制
256 MB
标签
暴力
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。