zhangxiandong091228 @ 2023-11-20 19:55:44
92
代码如下:
#include <iostream>
using namespace std;
const int NR=2501;
int n,m,i,j,a[NR][NR],leftt[NR][NR],up[NR][NR],f[NR][NR],answer,ans,ans1,ans2;
void fan()
{
for(i=1;i<=(n+1)/2;i++)
for(j=1;j<=(m+1)/2;j++)
{
swap(a[i][j],a[i][m-j+1]);
}
}
int solve()
{
ans=-1;
//leftt
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(a[i][j]==0)
leftt[i][j]=leftt[i][j-1]+1;
else
leftt[i][j]=0;
}
//up
for(j=1;j<=m;j++)
for(i=1;i<=n;i++)
{
if(a[i][j]==0)
up[i][j]=up[i-1][j]+1;
else
up[i][j]=0;
}
//f
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(a[i][j]==0)
f[i][j]=0;
else
{
f[i][j]=min(up[i-1][j],min(leftt[i][j-1],f[i-1][j-1]))+1;
}
ans=max(f[i][j],ans);
}
return ans;
}
int main()
{
ans=-1;
//input
cin>>n>>m;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
cin>>a[i][j];
}
ans1=solve();
fan();
ans2=solve();
cout<<max(ans1,ans2)<<endl;
return 0;
}
分两次DP,分别取左下和右下开吃。
蒟蒻求调!!!
by lzx123123 @ 2024-07-08 12:52:35
@zhangxiandong091228 十年OI一场空,不开long long 见祖宗
by SCP3023 @ 2024-08-05 11:08:09
不是long long的原因 我试了试他的码开long long也不过啊