Submission #896200

# Submission time Handle Problem Language Result Execution time Memory
896200 2024-01-01T02:19:34 Z NeroZein Road Construction (JOI21_road_construction) C++17
0 / 100
10000 ms 7652 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());
  int lo = 0, hi = 2e9;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    int p = 0, cnt = 0;
    multiset<int> se; 
    for (int i = 0; i < n && cnt < k; ++i) {
      auto [x, y] = a[i];
      while (p < i && x - a[p].first > mid) {
        se.erase(se.find(a[p].second));
        p++;
      }
      auto it = se.lower_bound(y - mid);
      while (it != se.end()) {
        int yy = *it;
        if (yy - y > mid) {
          break;
        } else {
          cnt++;
          it++; 
        }
      }
      se.insert(y);
    }
    if (cnt >= k) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  vector<int> ans;
  multiset<pair<int, int>> se; 
  for (int i = 0, p = 0; i < n; ++i) {
    auto [x, y] = a[i];
    while (p < i && x - a[p].first >= hi) {
      se.erase(se.find({a[p].second, a[p].first}));
      p++;
    }
    pair<int, int> key = {y - hi, INT_MAX};
    auto it = se.lower_bound(key);
    while (it != se.end()) {
      auto [yy, xx] = *it;
      if (yy - y >= hi) {
        break;
      } else {
        ans.push_back(max(abs(y - yy), 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 Execution timed out 10021 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 268 ms 7652 KB Output is correct
2 Correct 257 ms 7624 KB Output is correct
3 Execution timed out 10059 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10021 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10021 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -