CF1200D.White Lines
普及+/提高
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤k≤n). To use the eraser, Gildong needs to click on a cell (i,j) where 1≤i,j≤n−k+1. When a cell (i,j) is clicked, all of the cells (i′,j′) where i≤i′≤i+k−1 and j≤j′≤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.
吉尔东购买了一款著名的绘图软件 cfpaint。cfpaint 的工作界面是一个正方形,由 n 行和 n 列的方形单元格组成。行从上到下编号为 1 至 n,列从左到右编号为 1 至 n。位于第 r 行、第 c 列的单元格记作 (r,c)。cfpaint 中单元格仅有两种颜色:黑色和白色。
cfpaint 中有一个名为“橡皮擦”的工具,其尺寸为整数 k(1≤k≤n)。使用橡皮擦时,吉尔东需点击一个单元格 (i,j),其中 1≤i,j≤n−k+1。当点击单元格 (i,j) 后,所有满足 i≤i′≤i+k−1 且 j≤j′≤j+k−1 的单元格 (i′,j′) 均变为白色。换言之,以 (i,j) 为左上角、边长为 k 个单元格的正方形区域将被涂成白色。
一条“白线”指某一行或某一列中不包含任何黑色单元格。
吉尔东已使用 cfpaint 一段时间,因此当前部分单元格(可能为零个、也可能全部)为黑色。他想知道:恰好使用一次橡皮擦后,最多能获得多少条白线? 请帮助吉尔东解答这个问题。
输入格式
The first line contains two integers n and k (1≤k≤n≤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.
第一行包含两个整数 n 和 k(1≤k≤n≤2000)—— 分别表示行数与列数,以及橡皮擦的尺寸。
接下来的 n 行,每行包含 n 个无空格的字符。第 i 行中的第 j 个字符表示位于 (i,j) 的格子。每个字符为 'B'(表示黑色格子)或 'W'(表示白色格子)。
输出格式
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:
BWWW
WWWW
WWWW
WWWB
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).
在第一个例子中,吉隆可以点击单元格 (2,2),此时工作界面变为:
BWWW
WWWW
WWWW
WWWB
此时共有四条白色直线——第 2 行、第 3 行、第 2 列和第 3 列。
在第二个例子中,点击单元格 (2,3) 可使第 2 行成为一条白色直线。
在第三个例子中,点击单元格 (3,2) 可使第 2 列和第 5 行同时成为白色直线。
输入解题思路,AI测评打分。不知道怎么写?