Submission #1104554

#TimeUsernameProblemLanguageResultExecution timeMemory
1104554penguinhackerRoad Construction (JOI21_road_construction)C++17
100 / 100
1623 ms13768 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=250000; int n, k; ar<ll, 2> a[mxN]; vector<ll> ans; bool ok(ll x) { ans.clear(); set<ar<ll, 2>> s; for (int i=0, j=0; ans.size()<k&&i<n; ++i) { for (; a[i][0]-a[j][0]>x; ++j) s.erase({a[j][1], a[j][0]}); for (auto it=s.lower_bound({a[i][1]-x, (ll)-1e10}); ans.size()<k&&it!=s.end()&&(*it)[0]<=a[i][1]+x; ++it) ans.push_back(max(a[i][0]-(*it)[1], abs(a[i][1]-(*it)[0]))); s.insert({a[i][1], a[i][0]}); } return ans.size()<k; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i=0; i<n; ++i) { ll x, y; cin >> x >> y; a[i]={x+y, x-y}; } sort(a, a+n); ll lb=0, rb=4e9; while(lb<rb) { ll mid=(lb+rb+1)/2; // look for max number so <k roads with that many if (ok(mid)) lb=mid; else rb=mid-1; } ok(lb); sort(ans.begin(), ans.end()); for (ll i : ans) cout << i << "\n"; for (int i=0; i<k-ans.size(); ++i) cout << lb+1 << "\n"; return 0; }

Compilation message (stderr)

road_construction.cpp: In function 'bool ok(long long int)':
road_construction.cpp:15:31: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |  for (int i=0, j=0; ans.size()<k&&i<n; ++i) {
      |                     ~~~~~~~~~~^~
road_construction.cpp:18:65: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |   for (auto it=s.lower_bound({a[i][1]-x, (ll)-1e10}); ans.size()<k&&it!=s.end()&&(*it)[0]<=a[i][1]+x; ++it)
      |                                                       ~~~~~~~~~~^~
road_construction.cpp:22:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |  return ans.size()<k;
      |         ~~~~~~~~~~^~
road_construction.cpp: In function 'int main()':
road_construction.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for (int i=0; i<k-ans.size(); ++i)
      |                ~^~~~~~~~~~~~~
#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...