結果
問題 | No.2436 Min Diff Distance |
ユーザー | Kude |
提出日時 | 2023-08-19 00:58:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,370 bytes |
コンパイル時間 | 3,188 ms |
コンパイル使用メモリ | 252,704 KB |
実行使用メモリ | 33,164 KB |
最終ジャッジ日時 | 2024-11-28 13:14:07 |
合計ジャッジ時間 | 39,086 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,824 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,824 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 1,380 ms
18,172 KB |
testcase_12 | AC | 1,405 ms
19,616 KB |
testcase_13 | AC | 1,786 ms
16,968 KB |
testcase_14 | AC | 224 ms
6,816 KB |
testcase_15 | TLE | - |
testcase_16 | AC | 1,175 ms
11,020 KB |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 1,581 ms
12,936 KB |
testcase_21 | AC | 645 ms
7,200 KB |
testcase_22 | AC | 235 ms
6,824 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; template<class T> vector<T> manhattan_dist_max(vector<pair<T, T>> ps) { T v1, v2, v3, v4; v1 = v3 = numeric_limits<T>::max(); v2 = v4 = numeric_limits<T>::min(); for(auto [x, y] : ps) { T s = x + y; T t = -x + y; chmin(v1, s); chmax(v2, s); chmin(v3, t); chmax(v4, t); } int n = ps.size(); vector<T> res; res.reserve(n); for(auto [x, y] : ps) { T s = x + y; T t = -x + y; res.emplace_back(max({s - v1, v2 - s, t - v3, v4 - t})); } return res; } template<class T> vector<T> manhattan_dist_min(const vector<pair<T, T>>& points) { const int n = points.size(); assert(n >= 2); struct S { int x, y, i; }; vector<S> ps(n); for (int i = 0; i < n; i++) { auto [x, y] = points[i]; ps[i] = {x + y, -x + y, i}; } sort(ps.begin(), ps.end(), [](const S& p1, const S& p2) { return p1.x < p2.x; }); vector<T> vals(n); for (int i = 0; i < n; i++) vals[i] = ps[i].y; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); const int sz = vals.size(); vector<T> ls(n, -1), rs(n); auto dist = [&](const S& p1, const S& p2) { return max(abs(p1.x - p2.x), abs(p1.y - p2.y)); }; for (int i = 1; i < n; i++) rs[0] = rs[i] = dist(ps[0], ps[i]); vector<tuple<T, bool, int>> evs; fenwick_tree<int> ft(sz); vector<int> cnt(n); while(true) { evs.clear(); for (int i = 0; i < n; i++) if (rs[i] - ls[i] > 1) { T c = (rs[i] + ls[i]) / 2; assert(c >= 0); evs.emplace_back(ps[i].x - c, false, i); evs.emplace_back(ps[i].x + c, true, i); } if (evs.empty()) break; sort(evs.begin(), evs.end()); int ptr = 0; for (auto [x, t, i] : evs) { while(ptr < n && ((!t && ps[ptr].x < x) || (t && ps[ptr].x <= x))) { ft.add(lower_bound(vals.begin(), vals.end(), ps[ptr++].y) - vals.begin(), 1); } T c = (rs[i] + ls[i]) / 2; int l = lower_bound(vals.begin(), vals.end(), ps[i].y - c) - vals.begin(); int r = upper_bound(vals.begin(), vals.end(), ps[i].y + c) - vals.begin(); int sm = ft.sum(l, r); if (!t) { cnt[i] = sm; } else { assert(cnt[i] + 1 <= sm); (cnt[i] + 1 == sm ? ls[i] : rs[i]) = c; } } } vector<T> res(n); for (int i = 0; i < n; i++) res[ps[i].i] = rs[i]; return res; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<P> xy(n); for(auto& [x, y] : xy) cin >> x >> y; VI mx = manhattan_dist_max(xy); VI mn = manhattan_dist_min(xy); int ans = 2001001001; rep(i, n) chmin(ans, mx[i] - mn[i]); cout << ans << '\n'; }