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>
using namespace std;
int m,n;
int a[1005][1005];
int b[1005][1005];
int minn[1005][100];
int ans=-1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>m>>n;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
cin>>a[i][j];
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=a[i][j]-i-j;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++) {
minn[i][j]=min({minn[i-1][j],minn[i][j-1],b[i][j]});
ans=max(ans,a[i][j]-i-j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=a[i][j]-i+j;
for(int i=1; i<=m; i++)
for(int j=n; j>=1; j--) {
minn[i][j]=min({minn[i-1][j],minn[i][j+1],b[i][j]});
ans=max(ans,a[i][j]-i+j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=-a[i][j]-i-j;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++) {
minn[i][j]=min({minn[i-1][j],minn[i][j-1],b[i][j]});
ans=max(ans,-a[i][j]-i-j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=-a[i][j]-i+j;
for(int i=1; i<=m; i++)
for(int j=n; j>=1; j--) {
minn[i][j]=min({minn[i-1][j],minn[i][j+1],b[i][j]});
ans=max(ans,-a[i][j]-i+j-minn[i][j]-1);
}
cout<<ans;
return 0;
}
# | 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... |