#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, m; cin >> n >> m;
vector<vector<int> > a(n, vector<int>(m)), vis(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
vector<pair<int, int>> nei;
nei = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int ans = -5;
auto path = [&](auto&& path, int sz, int mn, int mx, int i, int j, set<pair<int, int>> st) -> void {
st.insert({i, j});
ans = max(ans, mx - mn - sz);
for (auto [x, y] : nei) {
int u = i + x, v = j + y;
if (u < 0 || u >= n || v < 0 || v >= m) continue;
if (a[u][v] >= mn && st.find({u, v}) == st.end()) path(path, sz + 1, mn, max(mx, a[u][v]), u, v, st);
}
return;
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < m; y ++) {
if (x == i && y == j) continue;
ans = max(max(a[i][j], a[x][y]) - min(a[i][j], a[x][y]) - (abs(i - x) + abs(y - j) + 1), ans);
}
}
}
}
cout << ans << endl;
}
int main() {
int t = 1;
// cin >> t;
while (t -- ) solve();
}
# | 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... |