CF679C.Bear and Square Grid
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X').
Two empty cells are directly connected if they share a side. Two cells (_r_1, _c_1) (located in the row _r_1 and column _c_1) and (_r_2, _c_2) are connected if there exists a sequence of empty cells that starts with (_r_1, _c_1), finishes with (_r_2, _c_2), and any two consecutive cells in this sequence are directly connected. A connected component is a set of empty cells such that any two cells in the component are connected, and there is no cell in this set that is connected to some cell not in this set.
Your friend Limak is a big grizzly bear. He is able to destroy any obstacles in some range. More precisely, you can choose a square of size k × k in the grid and Limak will transform all blocked cells there to empty ones. However, you can ask Limak to help only once.
The chosen square must be completely inside the grid. It's possible that Limak won't change anything because all cells are empty anyway.
You like big connected components. After Limak helps you, what is the maximum possible size of the biggest connected component in the grid?
你有一个 n 行 n 列的网格。每个格子要么是空的(用 . 表示),要么是被阻挡的(用 X 表示)。
若两个空格子共享一条边,则称它们直接相连。设两个格子 (r1,c1)(位于第 r1 行、第 c1 列)与 (r2,c2),若存在一个由空格子构成的序列,该序列以 (r1,c1) 开始、以 (r2,c2) 结束,且序列中任意两个相邻格子均直接相连,则称这两个格子连通。一个连通块是指一个空格子集合,满足:集合中任意两个格子均连通,且集合中不存在某个格子与集合外的某个格子连通。
你的朋友 Limak 是一只体型庞大的灰熊。他有能力清除某一范围内所有障碍物。更准确地说,你可以选择网格中一个大小为 k×k 的正方形区域,Limak 将把该区域内所有被阻挡的格子(即 X)全部变为空格子(即 .)。但你只能请求 Limak 帮助一次。
所选正方形必须完全位于网格内部。有可能 Limak 实际上不进行任何改变,例如该正方形区域内原本就全是空格子。
你偏爱较大的连通块。在 Limak 帮助你之后,整个网格中最大连通块的尺寸最多可能为多少?
输入格式
The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 500) — the size of the grid and Limak's range, respectively.
Each of the next n lines contains a string with n characters, denoting the i-th row of the grid. Each character is '.' or 'X', denoting an empty cell or a blocked one, respectively.
输入的第一行包含两个整数 n 和 k(1 ≤ k ≤ n ≤ 500),分别表示网格的大小以及 Limak 的移动范围。
接下来的 n 行中,每行包含一个长度为 n 的字符串,表示网格的第 i 行。每个字符为 . 或 X,分别表示空单元格或被阻塞的单元格。
输出格式
Print the maximum possible size (the number of cells) of the biggest connected component, after using Limak's help.
输出在使用 Limak 的帮助后,最大的连通块(所含单元格数量)可能达到的最大尺寸。
输入输出样例
输入#1
5 2 ..XXX XX.XX X.XXX X...X XXXX.
输出#1
10
输入#2
5 3 ..... .XXX. .XXX. .XXX. .....
输出#2
25
说明/提示
In the first sample, you can choose a square of size 2 × 2. It's optimal to choose a square in the red frame on the left drawing below. Then, you will get a connected component with 10 cells, marked blue in the right drawing.

在第一个样例中,你可以选择一个 2×2 的正方形。最优的选择是左图中红色框标出的正方形。随后,你将得到一个包含 10 个格子的连通块,如右图中蓝色标记所示。

输入解题思路,AI测评打分。不知道怎么写?