Submission #363131

#TimeUsernameProblemLanguageResultExecution timeMemory
363131lukameladzeMaxcomp (info1cup18_maxcomp)C++14
100 / 100
409 ms19308 KiB
# 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...