思路应该没问题吧,为什么五颜六色呢?
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,k,a[1005][1005];
bool check(int x){
if(x==0)return true;
for(int i2=1;i2+2*x-2<=n;i2++){
for(int j2=1;j2+2*x-2<=m;j2++){
int l1=i2,r1=i2+2*x-2,l2=j2,r2=j2+2*x-2,cnt=0;
for(int i=l1;i<=r1;i++){
for(int j=l2;j<=r2;j++){
if(a[i][j]<=min(min(i-l1+1,r1-i+1),min(j-l2+1,r2-j+1)))cnt+=min(min(i-l1+1,r1-i+1),min(j-l2+1,r2-j+1))-a[i][j];
else goto tz;
if(cnt>k)goto tz;
}
}
if(cnt<=k)return true;
tz:;
}
}
return false;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int l=0,r=100000000,ans=0;
while(l<=r){
int mid=l+r>>1;
if(check(mid)){
ans=mid;
l=mid+1;
}
else r=mid-1;
}
cout<<ans<<endl;
}
return 0;
}
悬关。