#include <bits/stdc++.h>
using namespace std;
int dis(pair <int,int>a, pair <int,int> b) {
return abs(a.first - b.first) + abs(a.second - b.second);
}
int main(void) {
int n, m;
cin >> n >> m;
if(n == 1) {
vector <int> a(m);
for(int i = 0; i < m; i ++) cin >> a[i];
int ans = INT_MIN;
for(int i = 0; i < m; i ++) {
for(int end = i; end < m; end ++) {
ans = max(ans, *max_element(a.begin() + i, a.begin() + end) - *min_element(a.begin() + i, a.begin() + end) - (end - i));
// cout << *max_element(a.begin() + i, a.begin() + end) << " " << *min_element(a.begin() + i, a.begin() + end) << endl;
}
}
cout << ans;
return false;
}
vector <vector <int> > g(n+2, vector <int> (m+2, -1));
function <int(int,int,int,int)> mxg = [ &](int a, int b, int c, int d) {
int mx = 0;
for(int i = a; i <= c; i ++) {
for(int j = b; j <= d; j ++) {
mx = max(mx, g[i][j]);
}
}
return mx;
};
function <int(int,int,int,int)> mng = [ &](int a, int b, int c, int d) {
int mx = 1e9;
for(int i = a; i <= c; i ++) {
for(int j = b; j <= d; j ++) {
mx = min(mx, g[i][j]);
}
}
return mx;
};
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) cin >> g[i][j];
}
int ans = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
for(int k = i; k <= n; k ++) {
for(int l = j; l <= m; l ++) {
ans = max(ans, mxg(i, j, k, l) - mng(i, j, k, l) - dis({i, j}, {k, l}) - 1);
// cout << mxg(i, j, k, l) << " " << mng(i, j, k, l) << endl;
}
}
}
}
cout << ans;
return false;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
330 ms |
324 KB |
Output is correct |
2 |
Correct |
323 ms |
204 KB |
Output is correct |
3 |
Correct |
328 ms |
272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |