本来打算用暴力写来着,我这差劲的眼力见都没看出来是二维前缀和,练习还是不够啊
#include<iostream>
using namespace std;
const int maxn = 1e4 + 4;
char tp[maxn][maxn];
int map[maxn][maxn];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++) {
cin >> tp[i][j];
if (tp[i][j] == '1') map[i][j] = 1;
map[i][j] += map[i - 1][j] + map[i][j - 1] - map[i - 1][j - 1];
}
int ans = 0;
for (int i = k;i <= n;i++)
for (int j = k;j <= m;j++) {
int temp = map[i][j] - map[i - k][j] - map[i][j - k] + map[i - k][j - k];
if (temp != 0)
ans++;
}
cout << ans << endl;
return 0;
}