Submission #601166

#TimeUsernameProblemLanguageResultExecution timeMemory
601166lordlorincRoad Construction (JOI21_road_construction)C++17
100 / 100
3784 ms28948 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n, k; vector<pair<ll, ll> > sor; set<pair<ll, ll> > ck; vector<ll> mo; vector<ll> calc(ll r){ ck.clear(); vector<ll> res; ll ind = 0; for (ll i = 0; i < n; i++){ // cout << sor[i].first << " " << sor[i].second << ": " << endl; while (ind < i && sor[i].first - sor[ind].first > r) { ck.erase(make_pair(sor[ind].second, sor[ind].first)); ind++; } // for (auto x : ck){ // cout << x.first << " " << x.second << endl; // } auto it = ck.lower_bound(make_pair(sor[i].second - r, -4000000001)); while (res.size() < k && it != ck.end() && it -> first <= sor[i].second + r){ // cout << it -> first << " " << it -> second << endl; ll x1 = (sor[i].first + sor[i].second) / 2, y1 = (sor[i].first - sor[i].second) / 2; ll x2 = (it -> first + it -> second) / 2, y2 = (it -> second - it -> first) / 2; // cout << x1 << " " << y1 << " " << x2 << " " << y2 << ": " << abs(x1 - x2) + abs(y1 - y2) << endl; res.push_back(abs(x1 - x2) + abs(y1 - y2)); it++; } ck.insert(make_pair(sor[i].second, sor[i].first)); } return res; } int main(){ cin >> n >> k; sor.resize(n); for (ll i = 0; i < n; i++) { ll a, b; cin >> a >> b; sor[i] = make_pair(a + b, a - b); } sort (sor.begin(), sor.end()); ll l = 0, r = 40000000001; while (l != r){ ll mid = (l + r) / 2; if (calc(mid).size() >=k) r = mid; else l = mid + 1; } mo = calc(l - 1); sort(mo.begin(), mo.end()); for (ll i = 0; i < k; i++){ if (i < mo.size()) cout << mo[i] << '\n'; else cout << l << '\n'; } return 0; }

Compilation message (stderr)

road_construction.cpp: In function 'std::vector<long long int> calc(ll)':
road_construction.cpp:25:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   25 |         while (res.size() < k && it != ck.end() && it -> first <= sor[i].second + r){
      |                ~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:53:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   53 |         if (calc(mid).size() >=k) r = mid;
      |             ~~~~~~~~~~~~~~~~~^~~
road_construction.cpp:61:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if (i < mo.size()) cout << mo[i] << '\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...