#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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
712 KB |
Output is correct |
4 |
Correct |
2 ms |
712 KB |
Output is correct |
5 |
Correct |
2 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
712 KB |
Output is correct |
2 |
Correct |
2 ms |
712 KB |
Output is correct |
3 |
Correct |
2 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
712 KB |
Output is correct |
4 |
Correct |
2 ms |
712 KB |
Output is correct |
5 |
Correct |
2 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
9 |
Correct |
4 ms |
1692 KB |
Output is correct |
10 |
Correct |
4 ms |
1712 KB |
Output is correct |
11 |
Correct |
3 ms |
1752 KB |
Output is correct |
12 |
Correct |
4 ms |
1776 KB |
Output is correct |
13 |
Correct |
4 ms |
1800 KB |
Output is correct |
14 |
Correct |
3 ms |
1824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
712 KB |
Output is correct |
4 |
Correct |
2 ms |
712 KB |
Output is correct |
5 |
Correct |
2 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
712 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
11 |
Correct |
2 ms |
776 KB |
Output is correct |
12 |
Correct |
4 ms |
1692 KB |
Output is correct |
13 |
Correct |
4 ms |
1712 KB |
Output is correct |
14 |
Correct |
3 ms |
1752 KB |
Output is correct |
15 |
Correct |
4 ms |
1776 KB |
Output is correct |
16 |
Correct |
4 ms |
1800 KB |
Output is correct |
17 |
Correct |
3 ms |
1824 KB |
Output is correct |
18 |
Correct |
198 ms |
20696 KB |
Output is correct |
19 |
Correct |
171 ms |
29256 KB |
Output is correct |
20 |
Correct |
154 ms |
37624 KB |
Output is correct |
21 |
Correct |
165 ms |
46032 KB |
Output is correct |
22 |
Correct |
162 ms |
54620 KB |
Output is correct |
23 |
Correct |
160 ms |
63100 KB |
Output is correct |
24 |
Correct |
161 ms |
71436 KB |
Output is correct |