Submission #762157

#TimeUsernameProblemLanguageResultExecution timeMemory
762157hazzleRoad Construction (JOI21_road_construction)C++17
100 / 100
2744 ms27004 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("avx2") using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define all(m) (m).begin(), (m).end() #define rall(m) (m).rbegin(), (m).rend() #define vec vector #define sz(a) (int) (a).size() #define mpp make_pair #define mtt make_tuple typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <ll, ll> pll; typedef pair <int, int> pii; typedef tuple <int, int, int> tui; template <typename T> using prq = priority_queue <T>; template <typename T> using pgq = priority_queue <T, vec <T>, greater <T>>; template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; } inline int solve(){ int n, k; cin >> n >> k; vec <pii> a(n); for (int i = 0; i < n; ++i){ int x, y; cin >> x >> y; a[i] = {x + y, x - y}; } sort(all(a)); vec <ll> res; auto work = [&](ll d, bool fl){ vec <ll> ans; set <pll> s; for (int r = 0, l = 0; r < n; ++r){ while(a[l].fi + d < a[r].fi){ s.erase({a[l].se, a[l].fi}), ++l; } auto [x, y] = a[r]; auto it = s.lower_bound({y - d, -3e9}); while(sz(ans) < k){ if (it == s.end()) break; auto [cy, cx] = *it; if (y + d < cy) break; ans.push_back(max(abs(x - cx), abs(y - cy))); ++it; } s.insert({a[r].se, a[r].fi}); } if (fl){ while(sz(ans) < k){ ans.push_back(d + 1); } res = ans; } return sz(ans) >= k; }; ll len = 0; for (int i = 31; ~i; --i){ len += 1LL << i; if (work(len, 0)){ len -= 1LL << i; } } work(len, 1); sort(all(res)); for (auto &i: res){ cout << i << "\n"; } return 0; } inline void precalc(){} signed main(){ // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tst = 1; //cin >> tst; precalc(); while(tst--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...