#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 3;
int n, m, a[N][N];
int mi = INT_MAX, mx = 0;
bool chk(int d) {
for (int i = 1, p = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i][j] + d < mx) p = max(p, j + 1);
}
for (int j = 1; j <= m; ++j) {
if (a[i][j] - d > mi && j < p) return 0;
}
}
return 1;
}
int calc() {
int l = 0, r = mx - mi, ans, mid;
while (l < r) {
mid = (l + r) >> 1;
if (chk(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
return ans;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
mx = max(mx, a[i][j]);
mi = min(mi, a[i][j]);
}
}
int ans = calc();
reverse(a + 1, a + n + 1);
ans = min(ans, calc());
for (int i = 1; i <= n; ++i)
reverse(a[i] + 1, a[i] + m + 1);
ans = min(ans, calc());
reverse(a + 1, a + n + 1);
ans = min(ans, calc());
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
Compilation message
joioi.cpp: In function 'int calc()':
joioi.cpp:27:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | return ans;
| ^~~
joioi.cpp: In function 'void solve()':
joioi.cpp:21:29: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
21 | int l = 0, r = mx - mi, ans, mid;
| ^~~
joioi.cpp:21:29: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
joioi.cpp:21:29: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
joioi.cpp:21:29: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |