Submission #542732

# Submission time Handle Problem Language Result Execution time Memory
542732 2022-03-27T18:41:20 Z ala2 Maxcomp (info1cup18_maxcomp) C++14
100 / 100
376 ms 48640 KB
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define B begin()
#define E end()
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int a[1005][1005];
int dp[1005][1005];
int dp2[1005][1005];
int dp3[1005][1005];
int dp4[1005][1005];
signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
        }
    } // cout
    memset(dp,-1,sizeof dp);
    memset(dp3,-1,sizeof dp3);
     memset(dp4,-1,sizeof dp4);
      memset(dp2,-1,sizeof dp2);
  //  cout<<endl;
    dp[0][0]=a[0][0]+1;
    for(int i=1; i<n; i++)
    {
        dp[i][0]=min(dp[i-1][0]+1,a[i][0]+1);
    }
    for(int i=1; i<m; i++)
    {
        dp[0][i]=min(dp[0][i-1]+1,a[0][i]+1);
    }
    for(int i=1; i<n; i++)
    {
        for(int j=1; j<m; j++)
        {
            dp[i][j]=min( {a[i][j]+1,dp[i-1][j]+1,dp[i][j-1]+1} );
        }
    }
    dp2[0][m-1]=a[0][m-1]+1;
    for(int i=1; i<n; i++)
    {
        dp2[i][m-1]=min(dp2[i-1][m-1]+1,a[i][m-1]+1);
    }
    for(int i=m-2; i>=0; i--)
    {
        dp2[0][i]=min(dp2[0][i+1]+1,a[0][i]+1);
    }
    for(int i=1; i<n; i++)
    {
        for(int j=m-2; j>=0; j--)
        {
            dp2[i][j]=min( {a[i][j]+1,dp2[i-1][j]+1,dp2[i][j+1]+1} );
        }
    }
    //int mx=0;





    dp3[n-1][0]=a[n-1][0]+1;
    for(int i=n-2; i>=0; i--)
    {
        dp3[i][0]=min(dp3[i+1][0]+1,a[i][0]+1);
    }
    for(int i=1; i<m; i++)
    {
        dp3[n-1][i]=min(dp3[n-1][i-1]+1,a[n-1][i]+1);
    }
    for(int i=n-2;i>=0;i--)
    {
        for(int j=1;j<m;j++)
        {
            dp3[i][j]=min( {a[i][j]+1, dp3[i+1][j]+1,dp3[i][j-1]+1} );
        }
    }

    dp4[n-1][m-1]=a[n-1][m-1]+1;
    for(int i=n-2; i>=0; i--)
    {
        dp4[i][m-1]=min(dp4[i+1][m-1]+1,a[i][m-1]+1);
    }
    for(int i=m-2; i>=0; i--)
    {
        dp4[n-1][i]=min(dp4[n-1][i+1]+1,a[n-1][i]+1);
    }
    for(int i=n-2;i>=0;i--)
    {
        for(int j=m-2;j>=0;j--)
        {
            dp4[i][j]=min( { a[i][j]+1,dp4[i+1][j]+1,dp4[i][j+1]+1 }  );
        }
    }


    int mx=-1;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            mx= max(mx,a[i][j]- min({dp[i][j],dp2[i][j],dp3[i][j],dp4[i][j]}));

        }
    }
    cout<<mx<<endl;

}









//111

# Verdict Execution time Memory Grader output
1 Correct 13 ms 31828 KB Output is correct
2 Correct 13 ms 31940 KB Output is correct
3 Correct 13 ms 31888 KB Output is correct
4 Correct 13 ms 31824 KB Output is correct
5 Correct 14 ms 31828 KB Output is correct
6 Correct 13 ms 31940 KB Output is correct
7 Correct 15 ms 31828 KB Output is correct
8 Correct 12 ms 31900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31872 KB Output is correct
2 Correct 13 ms 31956 KB Output is correct
3 Correct 12 ms 31948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31828 KB Output is correct
2 Correct 13 ms 31940 KB Output is correct
3 Correct 13 ms 31888 KB Output is correct
4 Correct 13 ms 31824 KB Output is correct
5 Correct 14 ms 31828 KB Output is correct
6 Correct 13 ms 31940 KB Output is correct
7 Correct 15 ms 31828 KB Output is correct
8 Correct 12 ms 31900 KB Output is correct
9 Correct 13 ms 32084 KB Output is correct
10 Correct 15 ms 32084 KB Output is correct
11 Correct 14 ms 32084 KB Output is correct
12 Correct 14 ms 32072 KB Output is correct
13 Correct 13 ms 32136 KB Output is correct
14 Correct 12 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31828 KB Output is correct
2 Correct 13 ms 31940 KB Output is correct
3 Correct 13 ms 31888 KB Output is correct
4 Correct 13 ms 31824 KB Output is correct
5 Correct 14 ms 31828 KB Output is correct
6 Correct 13 ms 31940 KB Output is correct
7 Correct 15 ms 31828 KB Output is correct
8 Correct 12 ms 31900 KB Output is correct
9 Correct 13 ms 31872 KB Output is correct
10 Correct 13 ms 31956 KB Output is correct
11 Correct 12 ms 31948 KB Output is correct
12 Correct 13 ms 32084 KB Output is correct
13 Correct 15 ms 32084 KB Output is correct
14 Correct 14 ms 32084 KB Output is correct
15 Correct 14 ms 32072 KB Output is correct
16 Correct 13 ms 32136 KB Output is correct
17 Correct 12 ms 32084 KB Output is correct
18 Correct 358 ms 48296 KB Output is correct
19 Correct 352 ms 48316 KB Output is correct
20 Correct 339 ms 47960 KB Output is correct
21 Correct 366 ms 48224 KB Output is correct
22 Correct 367 ms 48344 KB Output is correct
23 Correct 359 ms 48392 KB Output is correct
24 Correct 376 ms 48640 KB Output is correct