Submission #946974

#TimeUsernameProblemLanguageResultExecution timeMemory
946974siewjhRoad Construction (JOI21_road_construction)C++17
100 / 100
1577 ms13656 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 250005; const ll inf = 1e18; pair<ll, ll> arr[MAXN]; vector<ll> dvec; int nums, k; bool gen(ll d){ dvec.clear(); set<pair<ll, ll>> active; int lind = 0; for (int i = 0; i < nums; i++){ ll x, y; tie(x, y) = arr[i]; while (arr[lind].first < x - d){ active.erase({arr[lind].second, arr[lind].first}); lind++; } for (auto it = active.lower_bound({y - d, -inf}); it != active.end() && it->first <= y + d; it++){ dvec.push_back(max(abs(x - it->second), abs(y - it->first))); if (dvec.size() > k) return 0; } active.insert({y, x}); } return 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> nums >> k; for (int i = 0; i < nums; i++){ ll x, y; cin >> x >> y; arr[i] = {x + y, x - y}; } sort(arr, arr + nums); ll l = 0, r = 4e9, ans; while (l <= r){ ll m = (l + r) >> 1; if (gen(m)){ ans = m; l = m + 1; } else r = m - 1; } gen(ans); sort(dvec.begin(), dvec.end()); for (ll x : dvec) cout << x << '\n'; for (int i = dvec.size(); i < k; i++) cout << ans + 1 << '\n'; }

Compilation message (stderr)

road_construction.cpp: In function 'bool gen(ll)':
road_construction.cpp:21:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |    if (dvec.size() > k) return 0;
      |        ~~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48:54: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |  for (int i = dvec.size(); i < k; i++) cout << ans + 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...