Submission #896203

# Submission time Handle Problem Language Result Execution time Memory
896203 2024-01-01T02:26:01 Z NeroZein Road Construction (JOI21_road_construction) C++17
100 / 100
1229 ms 11784 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    a[i] = make_pair(x + y, y - x); // rotate 45 degress
  }
  sort(a.begin(), a.end());
  long long lo = 0, hi = 4e9;
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    int p = 0, cnt = 0;
    multiset<long long> se; 
    for (int i = 0; i < n && cnt < k; ++i) {
      auto [x, y] = a[i];
      while (p < i && (long long) x - a[p].first > mid) {
        se.erase(se.find(a[p].second));
        p++;
      }
      auto it = se.lower_bound((long long) y - mid);
      while (it != se.end()) {
        int yy = *it;
        if ((long long) yy - y > mid) {
          break;
        } else {
          cnt++;
          it++; 
        }
      }
      se.insert(y);
    }
    if (cnt >= k) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  vector<long long> ans;
  multiset<pair<long long, int>> se; 
  for (int i = 0, p = 0; i < n; ++i) {
    auto [x, y] = a[i];
    while (p < i && (long long) x - a[p].first >= hi) {
      se.erase(se.find({a[p].second, a[p].first}));
      p++;
    }
    pair<long long, int> key = {(long long) y - hi, INT_MAX};
    auto it = se.lower_bound(key);
    while (it != se.end()) {
      auto [yy, xx] = *it;
      if ((long long) yy - y >= hi) {
        break;
      } else {
        ans.push_back(max(llabs((long long) y - yy), (long long) x - xx));
        it++;
      }
    }
    se.emplace(y, x);
  }
  sort(ans.begin(), ans.end());
  while ((int) ans.size() < k) {
    ans.push_back(hi);
  }
  for (int i = 0; i < k; ++i) {
    cout << ans[i] << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 70 ms 4956 KB Output is correct
2 Correct 86 ms 4996 KB Output is correct
3 Correct 64 ms 5236 KB Output is correct
4 Correct 61 ms 5072 KB Output is correct
5 Correct 64 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 8640 KB Output is correct
2 Correct 257 ms 8552 KB Output is correct
3 Correct 58 ms 4904 KB Output is correct
4 Correct 214 ms 8680 KB Output is correct
5 Correct 198 ms 8540 KB Output is correct
6 Correct 196 ms 8664 KB Output is correct
7 Correct 173 ms 7996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 2392 KB Output is correct
2 Correct 215 ms 2396 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 120 ms 2396 KB Output is correct
5 Correct 236 ms 2404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 2392 KB Output is correct
2 Correct 215 ms 2396 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 120 ms 2396 KB Output is correct
5 Correct 236 ms 2404 KB Output is correct
6 Correct 306 ms 2396 KB Output is correct
7 Correct 276 ms 2392 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 221 ms 2396 KB Output is correct
11 Correct 89 ms 2400 KB Output is correct
12 Correct 241 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 4956 KB Output is correct
2 Correct 86 ms 4996 KB Output is correct
3 Correct 64 ms 5236 KB Output is correct
4 Correct 61 ms 5072 KB Output is correct
5 Correct 64 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 577 ms 5320 KB Output is correct
8 Correct 578 ms 5440 KB Output is correct
9 Correct 61 ms 5076 KB Output is correct
10 Correct 325 ms 4508 KB Output is correct
11 Correct 198 ms 4456 KB Output is correct
12 Correct 205 ms 5320 KB Output is correct
13 Correct 274 ms 3800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 4956 KB Output is correct
2 Correct 86 ms 4996 KB Output is correct
3 Correct 64 ms 5236 KB Output is correct
4 Correct 61 ms 5072 KB Output is correct
5 Correct 64 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 256 ms 8640 KB Output is correct
8 Correct 257 ms 8552 KB Output is correct
9 Correct 58 ms 4904 KB Output is correct
10 Correct 214 ms 8680 KB Output is correct
11 Correct 198 ms 8540 KB Output is correct
12 Correct 196 ms 8664 KB Output is correct
13 Correct 173 ms 7996 KB Output is correct
14 Correct 179 ms 2392 KB Output is correct
15 Correct 215 ms 2396 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 120 ms 2396 KB Output is correct
18 Correct 236 ms 2404 KB Output is correct
19 Correct 306 ms 2396 KB Output is correct
20 Correct 276 ms 2392 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 221 ms 2396 KB Output is correct
24 Correct 89 ms 2400 KB Output is correct
25 Correct 241 ms 2412 KB Output is correct
26 Correct 577 ms 5320 KB Output is correct
27 Correct 578 ms 5440 KB Output is correct
28 Correct 61 ms 5076 KB Output is correct
29 Correct 325 ms 4508 KB Output is correct
30 Correct 198 ms 4456 KB Output is correct
31 Correct 205 ms 5320 KB Output is correct
32 Correct 274 ms 3800 KB Output is correct
33 Correct 1229 ms 11544 KB Output is correct
34 Correct 1199 ms 11736 KB Output is correct
35 Correct 832 ms 10852 KB Output is correct
36 Correct 386 ms 11760 KB Output is correct
37 Correct 399 ms 11784 KB Output is correct
38 Correct 411 ms 10332 KB Output is correct