Submission #1037563

# Submission time Handle Problem Language Result Execution time Memory
1037563 2024-07-29T04:16:35 Z juicy Road Construction (JOI21_road_construction) C++17
100 / 100
1475 ms 8532 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 25e4 + 5;

int n, k, top;
long long res[N];
array<long long, 2> pt[N];

bool check(long long d) {
  top = 0;
  set<array<long long, 2>> st;
  for (int i = 1, j = 1; i <= n; ++i) {
    while (pt[i][0] - pt[j][0] > d) {
      st.erase({pt[j][1], pt[j][0]});
      ++j;
    }
    for (auto it = st.lower_bound({pt[i][1] - d, pt[i][0] - d}); it != st.end() && (*it)[0] <= pt[i][1] + d; ++it) {
      res[++top] = max(abs(pt[i][1] - (*it)[0]), pt[i][0] - (*it)[1]);
      if (top == k) {
        return 1;
      }
    }
    st.insert({pt[i][1], pt[i][0]});
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    int x, y; cin >> x >> y;
    pt[i] = {x + y, x - y};
  } 
  sort(pt + 1, pt + n + 1);
  long long L = 1, R = 4e9, p = R;
  while (L <= R) {
    long long md = (L + R) / 2;
    if (check(md)) {
      p = md;
      R = md - 1;
    } else {
      L = md + 1;
    }
  }
  check(p - 1);
  sort(res + 1, res + top + 1);
  while (top < k) {
    res[++top] = p;
  }
  for (int i = 1; i <= k; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 78 ms 6708 KB Output is correct
2 Correct 76 ms 6736 KB Output is correct
3 Correct 69 ms 6700 KB Output is correct
4 Correct 81 ms 6700 KB Output is correct
5 Correct 74 ms 5456 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 7508 KB Output is correct
2 Correct 260 ms 7368 KB Output is correct
3 Correct 64 ms 6460 KB Output is correct
4 Correct 211 ms 7276 KB Output is correct
5 Correct 219 ms 7504 KB Output is correct
6 Correct 205 ms 7504 KB Output is correct
7 Correct 189 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 4472 KB Output is correct
2 Correct 238 ms 4464 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 127 ms 4700 KB Output is correct
5 Correct 287 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 4472 KB Output is correct
2 Correct 238 ms 4464 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 127 ms 4700 KB Output is correct
5 Correct 287 ms 4692 KB Output is correct
6 Correct 330 ms 4712 KB Output is correct
7 Correct 310 ms 4700 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 253 ms 4736 KB Output is correct
11 Correct 104 ms 4944 KB Output is correct
12 Correct 386 ms 4724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 6708 KB Output is correct
2 Correct 76 ms 6736 KB Output is correct
3 Correct 69 ms 6700 KB Output is correct
4 Correct 81 ms 6700 KB Output is correct
5 Correct 74 ms 5456 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 698 ms 8144 KB Output is correct
8 Correct 739 ms 8276 KB Output is correct
9 Correct 68 ms 6740 KB Output is correct
10 Correct 347 ms 7820 KB Output is correct
11 Correct 216 ms 7508 KB Output is correct
12 Correct 262 ms 8272 KB Output is correct
13 Correct 314 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 6708 KB Output is correct
2 Correct 76 ms 6736 KB Output is correct
3 Correct 69 ms 6700 KB Output is correct
4 Correct 81 ms 6700 KB Output is correct
5 Correct 74 ms 5456 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 260 ms 7508 KB Output is correct
8 Correct 260 ms 7368 KB Output is correct
9 Correct 64 ms 6460 KB Output is correct
10 Correct 211 ms 7276 KB Output is correct
11 Correct 219 ms 7504 KB Output is correct
12 Correct 205 ms 7504 KB Output is correct
13 Correct 189 ms 6740 KB Output is correct
14 Correct 197 ms 4472 KB Output is correct
15 Correct 238 ms 4464 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 127 ms 4700 KB Output is correct
18 Correct 287 ms 4692 KB Output is correct
19 Correct 330 ms 4712 KB Output is correct
20 Correct 310 ms 4700 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 253 ms 4736 KB Output is correct
24 Correct 104 ms 4944 KB Output is correct
25 Correct 386 ms 4724 KB Output is correct
26 Correct 698 ms 8144 KB Output is correct
27 Correct 739 ms 8276 KB Output is correct
28 Correct 68 ms 6740 KB Output is correct
29 Correct 347 ms 7820 KB Output is correct
30 Correct 216 ms 7508 KB Output is correct
31 Correct 262 ms 8272 KB Output is correct
32 Correct 314 ms 7000 KB Output is correct
33 Correct 1475 ms 8144 KB Output is correct
34 Correct 1474 ms 8316 KB Output is correct
35 Correct 912 ms 7376 KB Output is correct
36 Correct 476 ms 8296 KB Output is correct
37 Correct 417 ms 8532 KB Output is correct
38 Correct 480 ms 6768 KB Output is correct