제출 #1284786

#제출 시각아이디문제언어결과실행 시간메모리
1284786PlayVoltzRoad Construction (JOI21_road_construction)C++20
100 / 100
1385 ms18064 KiB
#include <cstdio> #include <stdio.h> #include <stdbool.h> #include <iostream> #include <map> #include <vector> #include <climits> #include <stack> #include <string> #include <queue> #include <algorithm> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cctype> #include <bitset> #include <iomanip> #include <cstring> #include <numeric> #include <cassert> #include <random> using namespace std; #define int long long #define pii pair<int,int> #define mp make_pair #define pb push_back #define fi first #define se second int n, k; vector<pii> vect; bool check(int mid){ int c=0; multiset<int> s; for (int i=0, p=0; i<n; ++i){ while (vect[p].fi<vect[i].fi-mid)s.erase(s.lower_bound(vect[p].se)), ++p; for (auto it=s.lower_bound(vect[i].se-mid); it!=s.end()&&*it<=vect[i].se+mid; ++it){ ++c; if (c>=k)return 0; } s.insert(vect[i].se); } return 1; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; vect.resize(n); for (int i=0, a, b; i<n; ++i)cin>>a>>b, vect[i]=mp(a-b, a+b); sort(vect.begin(), vect.end()); int low=-1, high=LLONG_MAX/2; while (low+1<high){ int mid=(low+high)/2; if (check(mid))low=mid; else high=mid; } multiset<pii> s; multiset<int> ans; for (int i=0, p=0; i<n; ++i){ while (vect[p].fi<vect[i].fi-low)s.erase(s.lower_bound(mp(vect[p].se, p))), ++p; for (auto it=s.lower_bound(mp(vect[i].se-low, LLONG_MIN/2)); it!=s.end()&&it->fi<=vect[i].se+low; ++it){ ans.insert(max(abs(vect[i].fi-vect[it->se].fi), abs(vect[i].se-vect[it->se].se))); } s.insert(mp(vect[i].se, i)); } for (auto a:ans)cout<<a<<"\n"; for (int i=0; i<k-ans.size(); ++i)cout<<low+1<<"\n"; }
#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...