This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
int n,m;
const ll inf=1e11+10;
ll a[1009][1009];
ll b[1009][1009];
int main()
{
fast;
cin>>n>>m;
for(int i=1;i<n+1;i++)
{
for(int j=1;j<m+1;j++)
{
cin>>a[i][j];
}
}
ll re=-1;
for(int i=1;i<n+1;i++)
{
ll mx=0;
for(int j=1;j<m+1;j++)
{
b[i][j]=max(b[i-1][j]-1,a[i][j]);
}
for(int j=1;j<m+1;j++)
{
mx=max(mx,b[i][j]);
re=max(re,mx-a[i][j]-1);
mx--;
}
mx=0;
for(int j=m;j>0;j--)
{
mx=max(mx,b[i][j]);
re=max(re,mx-a[i][j]-1);
mx--;
}
}
memset(b,0,sizeof b);
for(int j=1;j<m+1;j++)
b[0][j]=inf;
for(int i=1;i<n+1;i++)
{
ll mx=inf;
for(int j=1;j<m+1;j++)
{
b[i][j]=min(b[i-1][j]+1,a[i][j]);
}
for(int j=1;j<m+1;j++)
{
mx=min(mx,b[i][j]);
re=max(re,a[i][j]-1-mx);
mx++;
}
mx=inf;
for(int j=m;j>0;j--)
{
mx=min(mx,b[i][j]);
re=max(re,a[i][j]-1-mx);
mx++;
}
}
cout<<re;
}
# | 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... |