Submission #84092

#TimeUsernameProblemLanguageResultExecution timeMemory
84092alextodoranMaxcomp (info1cup18_maxcomp)C++14
100 / 100
198 ms71436 KiB
#include <bits/stdc++.h>

#define NM 1002

using namespace std;

int n, m;

int ma[NM][NM];

int mx1[NM][NM], mx2[NM][NM], mx3[NM][NM], mx4[NM][NM], mx = -1;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> ma[i][j];
            mx1[i][j] = max(max(mx1[i - 1][j], mx1[i][j - 1]) - 1, ma[i][j] - 1);
        }
        for(int j = m; j >= 1; j--)
            mx2[i][j] = max(max(mx2[i - 1][j], mx2[i][j + 1]) - 1, ma[i][j] - 1);
    }
    for(int i = n; i >= 1; i--)
    {
        for(int j = 1; j <= m; j++)
            mx3[i][j] = max(max(mx3[i + 1][j], mx3[i][j - 1]) - 1, ma[i][j] - 1);
        for(int j = m; j >= 1; j--)
            mx4[i][j] = max(max(mx4[i + 1][j], mx4[i][j + 1]) - 1, ma[i][j] - 1);
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            mx = max(mx, max(max(mx1[i][j], mx2[i][j]), max(mx3[i][j], mx4[i][j])) - ma[i][j]);
    cout << mx << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...