#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int dp[1001][1001]; /// dp[n][m] = minim - d pana la (n, m) (dp[n][m] = minim)
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
cin >> a[i][j];
}
int ans = -1;
for (int rep=0; rep<4; rep++)
{
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
dp[i][j] = a[i][j] + 1;
if (i > 1)
{
dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
dp[i][j] = min(dp[i][j], a[i-1][j] +2);
}
if (j > 1)
{
dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
dp[i][j] = min(dp[i][j], a[i][j-1]+2);
}
ans = max(ans, a[i][j] - dp[i][j]);
}
}
/// rotate matrix a
for (int i=1; i<=n; i++)
{
reverse(a+1, a+m+1);
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
swap(a[i][j], a[j][i]);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4180 KB |
Output is correct |
2 |
Correct |
4 ms |
4172 KB |
Output is correct |
3 |
Correct |
4 ms |
4172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |