제출 #1124622

#제출 시각아이디문제언어결과실행 시간메모리
1124622votranngocvyRoad Construction (JOI21_road_construction)C++20
12 / 100
697 ms7480 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 false; } 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 = 1e10,ans = 0; 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...