You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 2005;
char buf[N][N];
int a[N][N];
int main()
{
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%s", buf + i);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + (buf[i - 1][j - 1] == 'B');
int ans = 0;
for (int i = 1; i <= n - k + 1; i++)
for (int j = 1; j <= n - k + 1; j++)
{
int cur = 0;
for (int l = 1; l <= n; l++)
{
int cnt = a[l][n] - a[l - 1][n];
if (i <= l && l <= i + k - 1)
cnt -= a[l][j + k - 1] - a[l][j - 1] - a[l - 1][j + k - 1] + a[l - 1][j - 1];
if (cnt == 0) cur++;
}
for (int l = 1; l <= n; l++)
{
int cnt = a[n][l] - a[n][l - 1];
if (j <= l && l <= j + k - 1)
cnt -= a[i + k - 1][l] - a[i - 1][l] - a[i + k - 1][l - 1] + a[i - 1][l - 1];
if (cnt == 0) cur++;
}
ans = max(ans, cur);
}
printf("%d", ans);
return 0;
}