Submission #76572

# Submission time Handle Problem Language Result Execution time Memory
76572 2018-09-14T21:32:46 Z Vardanyan Maxcomp (info1cup18_maxcomp) C++14
15 / 100
3 ms 672 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N][N];
int dp1[N][N];
int dp2[N][N];
int dp3[N][N];
int dp4[N][N];
int ans = -1000007;
void update(int i,int j){
    ans = max(ans,a[i][j]-i-j+dp1[i][j]);
    ans = max(ans,a[i][j]-i+j+dp2[i][j]);
    ans = max(ans,a[i][j]+i-j+dp3[i][j]);
    ans = max(ans,a[i][j]+i+j+dp4[i][j]);
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0;i<=n+2;i++){
        for(int j = 0;j<=m+2;j++){
            dp1[i][j] = dp2[i][j] = dp3[i][j] = dp4[i][j] = -200007;
        }
    }
    for(int i = 1;i<=n;i++)
        for(int j = 1;j<=m;j++) scanf("%d",&a[i][j]);
    /*
    memset(dp1,-1,sizeof(dp1));
    memset(dp2,-1,sizeof(dp2));
    memset(dp3,-1,sizeof(dp3));
    memset(dp4,-1,sizeof(dp4));*/
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            dp1[i][j] = max(max(dp1[i-1][j],i+j-a[i][j]),dp1[i][j-1]);
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = m;j>=1;j--){
            dp2[i][j] = max(max(dp2[i-1][j],i-j-a[i][j]),dp2[i][j+1]);
        }
    }
    for(int i = n;i>=1;i--){
        for(int j = 1;j<=m;j++){
            dp3[i][j] = max(max(dp3[i][j],-i+j-a[i][j]),dp3[i][j-1]);
        }
    }
    for(int i = n;i>=1;i--){
        for(int j = m;j>=1;j--){
            dp4[i][j] = max(max(dp4[i+1][j],-i-j-a[i][j]),dp4[i][j+1]);
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            update(i,j);
        }
    }
    ans--;
    cout<<ans<<endl;
    return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
maxcomp.cpp:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j = 1;j<=m;j++) scanf("%d",&a[i][j]);
                                 ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Incorrect 2 ms 576 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Incorrect 2 ms 576 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Incorrect 2 ms 576 KB Output isn't correct
4 Halted 0 ms 0 KB -