제출 #1124628

#제출 시각아이디문제언어결과실행 시간메모리
1124628votranngocvyRoad Construction (JOI21_road_construction)C++20
12 / 100
732 ms7488 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 (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 (abs((*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++) { 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...