아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

White Lines

시간 제한1.5초메모리 제한256 MB

요약
n x n 흑백 격자에서 k x k 정사각형 하나를 지워 완전히 흰색이 되는 행과 열의 수를 최대로 만든다.
난이도

보통10점 중 7점

유형
누적 합, 구현, 배열, 슬라이딩 윈도우
정답자
아직 제출이 없습니다

문제

Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of nn rows and nn columns of square cells. The rows are numbered from 11 to nn, from top to bottom, and the columns are numbered from 11 to nn, from left to right. The position of a cell at row rr and column cc is represented as (r,c)(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 kk (1≤k≤n1\le k\le n). To use the eraser, Gildong needs to click on a cell (i,j)(i,j) where 1≤i,j≤n−k+11\le i,j\le n-k+1. When a cell (i,j)(i,j) is clicked, all of the cells (i′,j′)(i',j') where i≤i′≤i+k−1i\le i'\le i+k-1 and j≤j′≤j+k−1j\le j'\le j+k-1 become white. In other words, a square with side equal to kk cells and top left corner at (i,j)(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 nn and kk (1≤k≤n≤20001\le k\le n\le 2000) --- the number of rows and columns, and the size of the eraser.

The next nn lines contain nn characters each without spaces. The jj-th character in the ii-th line represents the cell at (i,j)(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.

힌트

In the first example, Gildong can click the cell (2,2)(2,2), then the working screen becomes:

BWWW
WWWW
WWWW
WWWB

Then there are four white lines --- the 22-nd and 33-rd row, and the 22-nd and 33-rd column.

In the second example, clicking the cell (2,3)(2,3) makes the 22-nd row a white line.

In the third example, both the 22-nd column and 55-th row become white lines by clicking the cell (3,2)(3,2).

예제5

  1. 예제 1

    입력
    4 2
    BWWW
    WBBW
    WBBW
    WWWB
    
    예상 출력
    4
    
  2. 예제 2

    입력
    3 1
    BWB
    WWB
    BWB
    
    예상 출력
    2
    
  3. 예제 3

    입력
    5 3
    BWBBB
    BWBBB
    BBBBB
    BBBBB
    WBBBW
    
    예상 출력
    2
    
  4. 예제 4

    입력
    2 2
    BW
    WB
    
    예상 출력
    4
    
  5. 예제 5

    입력
    2 1
    WW
    WW
    
    예상 출력
    4