#include <iostream>
using namespace std;
const int N=1e3+10;
int a[N][N],tmp[N][N],b[N][N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
int ans=-1e9;
for(int rot=0;rot<4;rot++)
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
tmp[i][j]=2e9;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
tmp[i][j]=min(min(tmp[i][j-1],tmp[i-1][j]),a[i][j]-i-j);
// if(a[i][j]+i+j - tmp[i][j] - 1 == 6)
// {
// cout<<"Hola "<<i<<' '<<j<<' '<<tmp[i][j]<<endl;
// }
// cout<<a[i][j]+i+j<<' ';
ans=max(ans,a[i][j]-i-j - tmp[i][j] - 1);
}
cout<<endl;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
tmp[i][j]=min(min(tmp[i][j-1],tmp[i-1][j]),-a[i][j]-i-j);
ans=max(ans,-a[i][j]-i-j - tmp[i][j] - 1);
}
}
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++)
{
b[j][n+1-i]=a[i][j];
}
}
swap(n,m);
// cout<<"Rotating"<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
a[i][j]=b[i][j];
// cout<<a[i][j]<<' ';
}
// cout<<endl;
}
// cout<<"Rotated"<<endl;
}
cout<<ans<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |