#include <random>
#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
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,sse4,tune=native")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
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;
}
inline ll gt(int x, int y, int z, int t) {
return (ll)mat[z][t] - mat[x][y] - abs(z - x) - abs(t - y) - 1;
}
mt19937 aba;
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
ll ans = -1e18;
priority_queue<pair<int, pair<int, int>>> q1, q2, q3, q4;
vector<pair<int, pair<int, int>>> v(n * m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
v[i * m + j] = {mat[i][j], {i, j}};
}
}
shuffle(v.begin(), v.end(), aba);
sort(v.rbegin(), v.rend());
for (auto & el : v) {
int x = el.y.x;
int y = el.y.y;
q1.push({mat[x][y] + x + y, {x, y}});
q2.push({mat[x][y] + x - y, {x, y}});
q3.push({mat[x][y] - x + y, {x, y}});
q4.push({mat[x][y] - x - y, {x, y}});
ans = max(ans, gt(x, y, q1.top().y.x, q1.top().y.y));
ans = max(ans, gt(x, y, q2.top().y.x, q2.top().y.y));
ans = max(ans, gt(x, y, q3.top().y.x, q3.top().y.y));
ans = max(ans, gt(x, y, q4.top().y.x, q4.top().y.y));
}
assert(ans > -2);
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 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
2 ms |
876 KB |
Output is correct |
13 |
Correct |
2 ms |
876 KB |
Output is correct |
14 |
Correct |
2 ms |
876 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
2 ms |
876 KB |
Output is correct |
15 |
Correct |
2 ms |
876 KB |
Output is correct |
16 |
Correct |
2 ms |
876 KB |
Output is correct |
17 |
Correct |
2 ms |
876 KB |
Output is correct |
18 |
Correct |
481 ms |
63300 KB |
Output is correct |
19 |
Execution timed out |
508 ms |
63472 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |