凯撒大帝
思路:
nm预处理以每个点为右下角的矩形中1的个数。
对于每个点处理以该点为左上角的最大的全部为1的正方形,考虑二分边长,找到之后所有边长少于等于mid的正方形加1。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define N 2010
using namespace std;
int n, m, p;
int mp[N][N], sum[N][N];
int cnt[N], q[N];
char s[N];
int main(){
scanf("%d%d%d", &n, &m, &p);
for(int i=1; i<=n; i++){
scanf("%s", s+1);
for(int j=1; j<=m; j++){
int cc = s[j] - '0';
mp[i][j] = cc;
sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + mp[i][j]);
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
int l = 0, r = min(n-i+1, m-j+1);
while( l < r ){
int mid = ( (l + r) >> 1 ) + 1;
int cc = sum[i+mid-1][j+mid-1] - sum[i+mid-1][j-1] - sum[i-1][j+mid-1] + sum[i-1][j-1];
if(cc == mid*mid) l = mid;
else r = mid-1;
}
for(int j=l; j>=1; j--){
cnt[j]++;
}
}
}
for(int i=1; i<=p; i++) scanf("%d", &q[i]);
for(int i=1; i<=p; i++) printf("%d\n", cnt[q[i]]);
return 0;
}