Submission #1125964

#TimeUsernameProblemLanguageResultExecution timeMemory
1125964Kel_MahmutRoad Construction (JOI21_road_construction)C++20
18 / 100
215 ms7628 KiB
#include <bits/stdc++.h> #define pb push_back #define endl ("\n") #define all(aa) aa.begin(), aa.end() typedef long long ll; using namespace std; int main(){ int n, k; cin >> n >> k; vector<pair<ll, ll>> v(n); for(int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; if(n <= 1000){ auto calc = [&](pair<ll, ll> a, pair<ll, ll> b){ return abs(a.first - b.first) + abs(a.second - b.second); }; priority_queue<ll, vector<ll>, greater<ll>> pq; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ pq.push(calc(v[i], v[j])); } } for(int i = 0; i < k; i++){ cout << pq.top() << endl; pq.pop(); } exit(0); } auto calc = [&](pair<ll, ll> a, pair<ll, ll> b){ return abs(a.first - b.first) + abs(a.second - b.second); }; sort(all(v)); auto check = [&](ll l){ int cnt = 0; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(calc(v[i], v[j]) <= l) cnt++; else break; } if(cnt >= k) break; } return cnt >= k; }; ll tl = 0, tr = 1e12; while(tr - tl > 1){ ll tm = (tl + tr) / 2; if(check(tm)) tr = tm; else tl = tm; } priority_queue<ll, vector<ll>, greater<ll>> pq; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(calc(v[i], v[j]) < tr) pq.push(calc(v[i], v[j])); else break; } } assert(pq.size() < k); while( (int) pq.size() < k){ pq.push(tr); } for(int i = 0; i < k; i++){ cout << pq.top() << endl; pq.pop(); } }
#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...