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 n,m,a[1005][1005],dp[1005][1005],ans;
int main() {
cin>>n>>m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin>>a[i][j];
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
dp[i][j]=a[i][j];
if(i>1) dp[i][j]=max(dp[i][j], dp[i-1][j]-1);
if(j>1) dp[i][j]=max(dp[i][j],dp[i][j-1]-1);
}
}
for (int i=n; i>=1; i--) {
for (int j=m; j>=1; j--) {
dp[i][j]=max(a[i][j],dp[i][j]);
if(j<m) dp[i][j]=max(dp[i][j], dp[i][j+1]-1);
if(i<n) dp[i][j]=max(dp[i][j],dp[i+1][j]-1);
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
ans=max(ans,dp[i][j]-a[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... |