Submission #48551

#TimeUsernameProblemLanguageResultExecution timeMemory
48551PajarajaMaxcomp (info1cup18_maxcomp)C++17
100 / 100
256 ms79944 KiB
#include <bits/stdc++.h> using namespace std; int a[1007][1007],ul[1007][1007],ud[1007][1007],ll[1007][1007],ld[1007][1007]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]); for(int i=0;i<n;i++) for(int j=0;j<m;j++) { ul[i][j]=-2000000000; if(i>0) ul[i][j]=fmax(ul[i][j],ul[i-1][j]); if(j>0) ul[i][j]=fmax(ul[i][j],ul[i][j-1]); ul[i][j]=fmax(ul[i][j],-a[i][j]+i+j); } for(int i=0;i<n;i++) for(int j=m-1;j>=0;j--) { ud[i][j]=-2000000000; if(i>0) ud[i][j]=fmax(ud[i][j],ud[i-1][j]); if(j<m-1) ud[i][j]=fmax(ud[i][j],ud[i][j+1]); ud[i][j]=fmax(ud[i][j],-a[i][j]+i-j); } for(int i=n-1;i>=0;i--) for(int j=0;j<m;j++) { ll[i][j]=-2000000000; if(i<n-1) ll[i][j]=fmax(ll[i][j],ll[i+1][j]); if(j>0) ll[i][j]=fmax(ll[i][j],ll[i][j-1]); ll[i][j]=fmax(ll[i][j],-a[i][j]-i+j); } for(int i=n-1;i>=0;i--) for(int j=m-1;j>=0;j--) { ld[i][j]=-2000000000; if(i<n-1) ld[i][j]=fmax(ld[i][j],ld[i+1][j]); if(j<m-1) ld[i][j]=fmax(ld[i][j],ld[i][j+1]); ld[i][j]=fmax(ld[i][j],-a[i][j]-i-j); } int sol=-2000000000; for(int i=0;i<n;i++) for(int j=0;j<m;j++) { sol=fmax(sol,a[i][j]-i-j+ul[i][j]); sol=fmax(sol,a[i][j]-i+j+ud[i][j]); sol=fmax(sol,a[i][j]+i-j+ll[i][j]); sol=fmax(sol,a[i][j]+i+j+ld[i][j]); } printf("%d",sol-1); }

Compilation message (stderr)

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
maxcomp.cpp:8:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
                                            ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...