Codeforces Round 1031 (Div. 2)
C
Smilo and Minecraft
Codeforces
1700
原题
← BD →
翻译中…

The boy Smilo is playing Minecraft! To prepare for the battle with the dragon, he needs a lot of golden apples, and for that, he requires a lot of gold. Therefore, Smilo goes to the mine.

翻译中…

The mine is a rectangular grid of size $n \times m$, where each cell can be either gold ore, stone, or an empty cell. Smilo can blow up dynamite in any empty cell. When dynamite explodes in an empty cell with coordinates $(x, y)$, all cells within a square of side $2k + 1$ centered at cell $(x, y)$ become empty. If gold ore was located strictly inside this square (not on the boundary), it disappears. However, if the gold ore was on the boundary of this square, Smilo collects that gold.

翻译中…

Dynamite can only be detonated inside the mine, but the explosion square can extend beyond the mine's boundaries.

翻译中…

Determine the maximum amount of gold that Smilo can collect.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains three integers $n$, $m$, and $k$ ($1 \leq n, m, k \leq 500$) — the number of rows, columns, and the explosion parameter $k$, respectively.

翻译中…

Each of the following $n$ lines contains $m$ characters, each of which is equal to '.', '#', or 'g', where '.' — is an empty cell, '#' — is stone, 'g' — is gold. It is guaranteed that at least one of the cells is empty.

翻译中…

It is guaranteed that the sum $n \cdot m$ across all test cases does not exceed $2.5 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum amount of gold that can be obtained.

翻译中…

Note

翻译中…

In the first test case, Smilo can detonate the dynamite in any empty cell and obtain $2$ gold:

翻译中…

image

翻译中…

In the second test case, no matter what Smilo does, he will not be able to obtain any gold:

翻译中…

image

翻译中…

In the third test case, it is possible to detonate the dynamite in the bottom right corner to obtain $2$ gold, and then make another explosion one cell to the left to obtain the remaining $2$ gold:

翻译中…

image

翻译中…

样例

Input #1
3
2 3 1
#.#
g.g
2 3 2
#.#
g.g
3 4 2
.gg.
g..#
g##.
Output #1
2
0
4
InputCopy OutputCopy
题目信息
题号
2113C
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
贪心

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