#include <bits/stdc++.h>
std::vector <std::vector <int>> g(2001, std::vector <int> (2001, 0));
int n, m;
int mx = 0, mn = 1 << 30;
bool tr(int mid) {
int ptr = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) if (g[i][j] + mid < mx) ptr = std::max(ptr, j + 1);
for (int j = 0; j < m; j++) if (g[i][j] - mid > mn) if (j < ptr) return false;
}
return true;
}
void invc() {
for (int i = 0; i < n; i++) for (int j = 0; j < (m >> 1); j++) std::swap(g[i][j], g[i][m - 1 - j]);
}
void invr() {
for (int i = 0; i < (n >> 1); i++) for (int j = 0; j < m; j++) std::swap(g[i][j], g[n - 1 - i][j]);
}
int go() {
int l = 0, r = mx - mn;
while (l <= r) {
int mid = (l + r) >> 1;
if (tr(mid)) r = mid - 1;
else l = mid + 1;
}
return l + 1;
}
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
std::cin >> n >> m;
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) std::cin >> g[i][j], mx = std::max(mx, g[i][j]), mn = std::min(mn, g[i][j]);
int ans = go();
invr(); ans = std::min(ans, go());
invc(); ans = std::min(ans, go());
invr(); ans = std::min(ans, go());
std::cout << ans << std::endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |