Submission #1033003

#TimeUsernameProblemLanguageResultExecution timeMemory
1033003adaawfRoad Construction (JOI21_road_construction)C++17
100 / 100
1716 ms19548 KiB
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; long long int n, k; struct POINT { long long int x, y; } a[250005]; bool cmp(POINT aa, POINT bb) { return aa.x < bb.x; } vector<long long int> v; bool check(long long int x, int flag) { long long int c = 0; set<pair<long long int, long long int>> s; int j = 1; for (int i = 1; i <= n; i++) { while (a[j].x < a[i].x - x) { s.erase(s.find({a[j].y, a[j].x})); j++; } for (auto it = s.lower_bound({a[i].y - x, -1e18}); it != s.upper_bound({a[i].y + x, 1e18}); it++) { if (flag == 0) c++; else v.push_back(max(abs(a[i].x - (*it).second), abs(a[i].y - (*it).first))); if (c == k) return true; } s.insert({a[i].y, a[i].x}); } return false; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { long long int x, y; cin >> x >> y; a[i].x = x + y; a[i].y = x - y; } sort(a + 1, a + n + 1, cmp); long long int l = 1, r = 4e9, res; while (l <= r) { long long int mid = (l + r) / 2; if (check(mid, 0)) { res = mid; r = mid - 1; } else l = mid + 1; } check(res, 1); sort(v.begin(), v.end()); for (int i = 0; i < k; i++) cout << v[i] << '\n'; }

Compilation message (stderr)

road_construction.cpp: In function 'int main()':
road_construction.cpp:52:10: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     check(res, 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...