This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |