1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector>
#define FILE_IN(__fname) freopen(__fname, "r", stdin) #define FILE_OUT(__fname) freopen(__fname, "w", stdout) #define countdown(s) while (s --> 0) #define IMPROVE_IO() std::ios::sync_with_stdio(false)
using std::cin; using std::cout; using std::endl; using std::min; using std::max;
typedef long long int lli;
int getint() { int x; scanf("%d", &x); return x; } lli getll() { long long int x; scanf("%lld", &x); return x; }
const int MAXN = 20000 + 10; const int INF = 0x3f3f3f3f;
lli n, maxx = -(0x3f3f3f3f), minx = (0x3f3f3f3f), maxy = -(0x3f3f3f3f), miny = (0x3f3f3f3f); lli x[MAXN], y[MAXN]; int cov[MAXN];
inline void _Cover(int lx, int rx, int ly, int ry, int ts) { for (int i = 1; i <= n; ++i) if (!cov[i] && lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry) cov[i] = ts; }
inline void Uncover(int ts) { for (int i = 1; i <= n; ++i) if (cov[i] == ts) cov[i] = 0; }
inline int _CHECK(int mid, int depth) { lli minx = INF, maxx = -INF, miny = INF, maxy = -INF; for (int i = 1; i <= n; ++i) if (!cov[i]) { minx = min(minx, x[i]); maxx = max(maxx, x[i]); miny = min(miny, y[i]); maxy = max(maxy, y[i]); } if (max(maxx - minx, maxy - miny) <= mid) return 1; if (depth == 3) return 0; _Cover(minx, minx + mid, miny, miny + mid, depth); if (_CHECK(mid, depth + 1)) return 1; Uncover(depth); _Cover(minx, minx + mid, maxy - mid, maxy, depth); if (_CHECK(mid, depth + 1)) return 1; Uncover(depth); _Cover(maxx - mid, maxx, miny, miny + mid, depth); if (_CHECK(mid, depth + 1)) return 1; Uncover(depth); _Cover(maxx - mid, maxx, maxy - mid, maxy, depth); if (_CHECK(mid, depth + 1)) return 1; Uncover(depth); return 0; }
bool Check(int mid) { memset(cov, 0, sizeof cov); return _CHECK(mid, 1); }
int main() { n = getint(); for (int i = 1; i <= n; ++i) { x[i] = getint(); y[i] = getint(); } int l = 0, r = 2e9; while (l < r) { int mid = (l + r) >> 1; if (Check(mid)) r = mid; else l = mid + 1; } printf("%d\n", l); return 0; }
|