Submission #995530

#TimeUsernameProblemLanguageResultExecution timeMemory
995530vladiliusRoad Construction (JOI21_road_construction)C++17
100 / 100
1628 ms26224 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; #define pb push_back #define ff first #define ss second #define ins insert const ll inf = 1e9; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin>>n>>k; vector<pii> p(n + 1); for (int i = 1; i <= n; i++){ cin>>p[i].ff>>p[i].ss; } sort(p.begin() + 1, p.end()); vector<ll> dist; auto get = [&](ll r, bool ind){ multiset<pii> st; int j = 1; for (int i = 1; i <= n; i++){ if (ind && dist.size() >= k) break; while (j < i && (p[i].ff - p[j].ff) > r){ st.erase(st.find({p[j].ss, p[j].ff})); j++; } auto it = st.lower_bound({p[i].ss - r, -inf}); ll R = p[i].ss + r; while (it != st.end() && (*it).ff <= R){ ll d = abs(p[i].ff - (*it).ss) + abs(p[i].ss - (*it).ff); if (d <= r){ dist.pb(d); } it++; } st.insert({p[i].ss, p[i].ff}); } }; ll l = 0, r = 4LL * inf; while (l + 1 < r){ ll m = (l + r) / 2; get(m, 1); if (dist.size() < k){ l = m + 1; } else { r = m; } dist.clear(); } get(r, 0); assert(dist.size() >= k); sort(dist.begin(), dist.end()); for (int i = 0; i < k; i++){ cout<<dist[i]<<"\n"; } }

Compilation message (stderr)

road_construction.cpp: In lambda function:
road_construction.cpp:27:36: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (ind && dist.size() >= k) break;
      |                        ~~~~~~~~~~~~^~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:49:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if (dist.size() < k){
      |             ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from road_construction.cpp:1:
road_construction.cpp:58:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |     assert(dist.size() >= k);
      |            ~~~~~~~~~~~~^~~~
#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...