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;
const int INF=1e9;
int a[1005][1005],dp[4][1005][1005];
int kecil(int a,int b,int c,int d){
return min(a,min(b,min(c,d)));
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
}
for(int i=1;i<=m;i++){
for(int j=0;j<4;j++){
dp[j][0][i]=INF;
dp[j][n+1][i]=INF;
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<4;j++){
dp[j][i][0]=INF;
dp[j][i][m+1]=INF;
}
}
//kuadran 2
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[0][i][j]=min(a[i][j]+1,min(dp[0][i-1][j],dp[0][i][j-1])+1);
}
}
//kuadran 1
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
dp[1][i][j]=min(a[i][j]+1,min(dp[1][i-1][j],dp[1][i][j+1])+1);
}
}
//kuadran 3
for(int i=n;i>=1;i--){
for(int j=1;j<=m;j++){
dp[2][i][j]=min(a[i][j]+1,min(dp[2][i+1][j],dp[2][i][j-1])+1);
}
}
//kuadran 4
for(int i=n;i>=1;i--){
for(int j=m;j>=1;j--){
dp[3][i][j]=min(a[i][j]+1,min(dp[3][i+1][j],dp[3][i][j+1])+1);
}
}
//pasti max pathnya diawali dengan bil minimum di path tsb dan diakhari dengan bil maksimum di path tsb
int ans=-1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
//maksimum di (i,j)
ans=max(ans,a[i][j]-kecil(dp[0][i][j],dp[1][i][j],dp[2][i][j],dp[3][i][j]));
}
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
12 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
maxcomp.cpp:14:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
14 | for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
# | 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... |