Submission #1124624

#TimeUsernameProblemLanguageResultExecution timeMemory
1124624votranngocvyRoad Construction (JOI21_road_construction)C++20
12 / 100
760 ms7464 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define fi first #define se second const int N = 25e4 + 5; pii a[N]; set<pii>s; vector<int>vec; int n,k; bool check(int mid) { s.clear(); vec.clear(); int j = 1; for (int i = 1; i <= n; i++) { while (j < i && a[i].fi - a[j].fi > mid) { s.erase({a[j].se,j}); j++; } for (auto it = s.lower_bound({a[i].se - mid,-1}); it != s.end(); it = next(it)) { if ((*it).fi > a[i].se + mid) break; vec.push_back(max(abs(a[i].se - (*it).fi),abs(a[i].fi - a[(*it).se].fi))); if ((int)vec.size() == k) return true; } s.insert({a[i].se,i}); } return ((int)vec.size() >= k); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { int x,y; cin >> x >> y; a[i].fi = x + y; a[i].se = x - y; } sort(a + 1,a + n + 1); int l = 0,r = 4e9,ans = 4e9; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) ans = mid,r = mid - 1; else l = mid + 1; } check(ans); sort(vec.begin(),vec.end()); for (auto x: vec) cout << x << "\n"; } //Hint: xoay bảng 45 độ để chuyển khoảng cách Mahattan thành khoảng cách Cherbyshev //(x,y) -> (x + y,x - y)
#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...