#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <string>
#include <algorithm>
#include <tuple>
#include <cassert>
using namespace std;
#define x first
#define y second
#define int long long
const int maxn = 1e3 + 10;
int mat[maxn][maxn];
int opt[maxn][maxn];
vector<pair<int, int>> dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
int n, m;
bool check(int x, int y) {
return x >= 0 && y >= 0 && x < n && y < m;
}
int solve() {
int ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int i2 = 0; i2 < n; i2++) {
for (int j2 = 0; j2 < m; j2++) {
if (mat[i][j] <= mat[i2][j2])
ans = max(ans, mat[i2][j2] - mat[i][j] - abs(i - i2) - abs(j - j2) - 1);
}
}
}
}
return ans;
}
int gt(int x, int y, int z, int t) {
return mat[z][t] - mat[x][y] - abs(z - x) - abs(t - y) - 1;
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
int ans = -1;
set<pair<int, pair<int, int>>> q1, q2, q3, q4;
vector<pair<int, pair<int, int>>> v;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
opt[i][j] = -1;
v.push_back({mat[i][j], {i, j}});
}
}
bool f = 0;
sort(v.rbegin(), v.rend());
for (auto & el : v) {
int x = el.y.x;
int y = el.y.y;
if (f) {
ans = max(ans, gt(x, y, q1.rbegin()->y.x, q1.rbegin()->y.y));
ans = max(ans, gt(x, y, q2.rbegin()->y.x, q1.rbegin()->y.y));
ans = max(ans, gt(x, y, q3.rbegin()->y.x, q1.rbegin()->y.y));
ans = max(ans, gt(x, y, q4.rbegin()->y.x, q1.rbegin()->y.y));
}
q1.insert({mat[x][y] + x + y, {x, y}});
q2.insert({mat[x][y] + x - y, {x, y}});
q3.insert({mat[x][y] - x + y, {x, y}});
q4.insert({mat[x][y] - x - y, {x, y}});
f = 1;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Incorrect |
3 ms |
620 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |