1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
const int MAXN = 2e3 + 5;
char s[MAXN][MAXN];
int cols[MAXN], rows[MAXN];
bool l[MAXN][MAXN], r[MAXN][MAXN], u[MAXN][MAXN], d[MAXN][MAXN], mark[MAXN];
int sc[MAXN][MAXN], sr[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n, k;
cin >> n >> k;
FOR(i, 1, n + 1) { cin >> (s[i] + 1); }
FOR(i, 1, n + 1) {
int x = 1;
FOR(j, 1, n + 1) {
if (s[i][j] == 'B') {
x = 0;
break;
}
}
rows[i] = rows[i - 1] + x;
}
FOR(i, 1, n + 1) {
int x = 1;
FOR(j, 1, n + 1) {
if (s[j][i] == 'B') {
x = 0;
break;
}
}
cols[i] = cols[i - 1] + x;
}
fill(mark + 1, mark + n + 1, 1);
FOR(i, 1, n + 1) {
FOR(j, 1, n + 1) {
u[i][j] = mark[j];
if (s[i][j] == 'B') {
mark[j] = 0;
}
}
}
fill(mark + 1, mark + n + 1, 1);
FOR(j, 1, n + 1) {
FOR(i, 1, n + 1) {
l[i][j] = mark[i];
if (s[i][j] == 'B') {
mark[i] = 0;
}
}
}
fill(mark + 1, mark + n + 1, 1);
REP(i, 1, n + 1) {
FOR(j, 1, n + 1) {
d[i][j] = mark[j];
if (s[i][j] == 'B') {
mark[j] = 0;
}
}
}
fill(mark + 1, mark + n + 1, 1);
REP(j, 1, n + 1) {
FOR(i, 1, n + 1) {
r[i][j] = mark[i];
if (s[i][j] == 'B') {
mark[i] = 0;
}
}
}
/*
FOR(i, 1, n + 1) { debug("%d rows:%d cols:%d\n", i, rows[i], cols[i]); }
FOR2(i, 1, n + 1, j, 1, n + 1) {
debug("(%d,%d) l:%d r:%d u:%d d:%d\n", i, j, l[i][j], r[i][j], u[i][j],
d[i][j]);
}
*/
FOR2(i, 1, n + 1, j, 1, n + 1) {
if (j >= k) {
sr[i][j] = sr[i - 1][j] + (l[i][j - k + 1] && r[i][j]);
}
if (i >= k) {
sc[i][j] = sc[i][j - 1] + (u[i - k + 1][j] && d[i][j]);
}
// debug("(%d,%d) sr:%d sc:%d\n", i, j, sr[i][j], sc[i][j]);
}
int ans = 0;
FOR2(i, k, n + 1, j, k, n + 1) {
ans =
max(ans, rows[i - k] + rows[n] - rows[i] + sr[i][j] - sr[i - k][j] +
cols[j - k] + cols[n] - cols[j] + sc[i][j] - sc[i][j - k]);
}
cout << ans << "\n";
return 0;
}
|