Submission #969336

#TimeUsernameProblemLanguageResultExecution timeMemory
969336abczzRoad Construction (JOI21_road_construction)C++14
32 / 100
3748 ms27220 KiB
#include <iostream> #include <vector> #include <array> #include <algorithm> #include <map> #define ll long long using namespace std; ll n, k, f; vector <ll> V; map <pair<ll, ll>, ll> mp; array <ll, 2> A[250000]; void solve(ll mid) { V.clear(); mp.clear(); f = 0; for (int i=0; i<n; ++i) { auto it = mp.lower_bound({A[i][0]-A[i][1]-mid, 0}); while (it != mp.end()) { if (it->first.first > A[i][0]-A[i][1]+mid) break; auto nx = next(it); if (it->first.second + mid < A[i][0]+A[i][1]) mp.erase(it); else { auto x = (it->first.first+it->first.second)/2; V.push_back(abs(A[i][0]-x)+abs(A[i][1]-it->first.second+x)); if (V.size() > k) break; } it = nx; } ++mp[{A[i][0]-A[i][1], A[i][0]+A[i][1]}]; } } int main() { cin.tie(0); ios::sync_with_stdio(0); cin >> n >> k; for (int i=0; i<n; ++i) { cin >> A[i][0] >> A[i][1]; } sort(A, A+n, [](auto a, auto b) { return a[0]+a[1] < b[0]+b[1]; }); ll l = 0, r = (ll)4e9, mid; while (l < r) { mid = (l+r)/2; solve(mid); if (V.size() < k) l = mid+1; else r = mid; } solve(l); sort(V.begin(), V.end()); for (int i=0; i<k; ++i) { cout << V[i] << '\n'; } }

Compilation message (stderr)

road_construction.cpp: In function 'void solve(long long int)':
road_construction.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |         if (V.size() > k) break;
      |             ~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |     if (V.size() < k) l = mid+1;
      |         ~~~~~~~~~^~~
#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...