Submission #1124630

#TimeUsernameProblemLanguageResultExecution timeMemory
1124630votranngocvyRoad Construction (JOI21_road_construction)C++20
12 / 100
792 ms7448 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]; vector<int>vec; int n,k; int dist(int i,int j) { return max(abs(a[i].fi - a[j].fi),abs(a[i].se - a[j].se)); } bool check(int mid) { set<pii>s; vec.clear(); int j = 1; for (int i = 1; i <= n; i++) { while (abs(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++) { if (abs((*it).fi - a[i].se) > mid) break; vec.push_back(dist(i,(*it).se)); 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++) { cin >> a[i].fi >> a[i].se; int x = a[i].fi,y = a[i].se; a[i] = {x + y,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...