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;
long long mx1[3001][3001],mx2[3001][3001],mx3[3001][3001],mx4[3001][3001];
long long arr[3001][3001];
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;cin>>n>>m;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin>>arr[i][j];
}
}
long long inf = 1e18;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
mx1[i][j] = min(arr[i][j],(j?mx1[i][j-1]+1:inf));
}
}
for(int j = 0;j<m;j++){
for(int i = 0;i<n;i++){
mx1[i][j] = min(mx1[i][j],(i?mx1[i-1][j]+1:inf));
}
}
for(int i = 0;i<n;i++){
for(int j = m-1;j>=0;j--){
mx2[i][j] = min(arr[i][j],(j<(m-1)?mx2[i][j+1]+1:inf));
}
}
for(int j = m-1;j>=0;j--){
for(int i = 0;i<n;i++){
mx2[i][j] = min(mx2[i][j],(i?mx2[i-1][j]+1:inf));
}
}
for(int i = n-1;i>=0;i--){
for(int j = 0;j<m;j++){
mx3[i][j] = min(arr[i][j],(j?mx3[i][j-1]+1:inf));
}
}
for(int j = 0;j<m;j++){
for(int i = n-1;i>=0;i--){
mx3[i][j] = min(mx3[i][j],(i<(n-1)?mx3[i+1][j]+1:inf));
}
}
for(int i = n-1;i>=0;i--){
for(int j = m-1;j>=0;j--){
mx4[i][j] = min(arr[i][j],(j<(m-1)?mx4[i][j+1]+1:inf));
}
}
for(int j = m-1;j>=0;j--){
for(int i = n-1;i>=0;i--){
mx4[i][j] = min(mx4[i][j],(i<(n-1)?mx4[i+1][j]+1:inf));
}
}
long long ans = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
ans = max(ans,arr[i][j]-min({mx1[i][j],mx2[i][j],mx3[i][j],mx4[i][j]}));
}
}
cout<<ans-1<<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... |