A12847 | White Lines
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of $n$ rows and $n$ columns of square cells. The rows are numbered from $1$ to $n$ , from top to bottom, and the columns are numbered from $1$ to $n$ , from left to right. The position of a cell at row $r$ and column $c$ is represented as $(r, c)$ . There are only two colors for the cells in cfpaint — black and white.
There is a tool named eraser in cfpaint. The eraser has an integer size $k$ ( $1 \le k \le n$ ). To use the eraser, Gildong needs to click on a cell $(i, j)$ where $1 \le i, j \le n - k + 1$ . When a cell $(i, j)$ is clicked, all of the cells $(i', j')$ where $i \le i' \le i + k - 1$ and $j \le j' \le j + k - 1$ become white. In other words, a square with side equal to $k$ cells and top left corner at $(i, j)$ is colored white.
A white line is a row or a column without any black cells.
Gildong has worked with cfpaint for some time, so some of the cells (possibly zero or all) are currently black. He wants to know the maximum number of white lines after using the eraser exactly once. Help Gildong find the answer to his question.
There is a tool named eraser in cfpaint. The eraser has an integer size $k$ ( $1 \le k \le n$ ). To use the eraser, Gildong needs to click on a cell $(i, j)$ where $1 \le i, j \le n - k + 1$ . When a cell $(i, j)$ is clicked, all of the cells $(i', j')$ where $i \le i' \le i + k - 1$ and $j \le j' \le j + k - 1$ become white. In other words, a square with side equal to $k$ cells and top left corner at $(i, j)$ is colored white.
A white line is a row or a column without any black cells.
Gildong has worked with cfpaint for some time, so some of the cells (possibly zero or all) are currently black. He wants to know the maximum number of white lines after using the eraser exactly once. Help Gildong find the answer to his question.
输入格式
The first line contains two integers $n$ and $k$ ( $1 \le k \le n \le 2000$ ) — the number of rows and columns, and the size of the eraser.
The next $n$ lines contain $n$ characters each without spaces. The $j$ -th character in the $i$ -th line represents the cell at $(i,j)$ . Each character is given as either 'B' representing a black cell, or 'W' representing a white cell.
The next $n$ lines contain $n$ characters each without spaces. The $j$ -th character in the $i$ -th line represents the cell at $(i,j)$ . Each character is given as either 'B' representing a black cell, or 'W' representing a white cell.
输出格式
Print one integer: the maximum number of white lines after using the eraser exactly once.
输入输出样例
输入 #1
4 2 BWWW WBBW WBBW WWWB
输出 #1
4
输入 #2
3 1 BWB WWB BWB
输出 #2
2
输入 #3
5 3 BWBBB BWBBB BBBBB BBBBB WBBBW
输出 #3
2
输入 #4
2 2 BW WB
输出 #4
4
输入 #5
2 1 WW WW
输出 #5
4
In the first example, Gildong can click the cell $(2, 2)$ , then the working screen becomes:
```
<pre class="verbatim">BWWW<br></br>WWWW<br></br>WWWW<br></br>WWWB<br></br>
```
Then there are four white lines — the $2$ -nd and $3$ -rd row, and the $2$ -nd and $3$ -rd column.
In the second example, clicking the cell $(2, 3)$ makes the $2$ -nd row a white line.
In the third example, both the $2$ -nd column and $5$ -th row become white lines by clicking the cell $(3, 2)$ .
```
<pre class="verbatim">BWWW<br></br>WWWW<br></br>WWWW<br></br>WWWB<br></br>
```
Then there are four white lines — the $2$ -nd and $3$ -rd row, and the $2$ -nd and $3$ -rd column.
In the second example, clicking the cell $(2, 3)$ makes the $2$ -nd row a white line.
In the third example, both the $2$ -nd column and $5$ -th row become white lines by clicking the cell $(3, 2)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted