Submission #722578

# Submission time Handle Problem Language Result Execution time Memory
722578 2023-04-12T11:31:19 Z piOOE Road Construction (JOI21_road_construction) C++17
100 / 100
2162 ms 13496 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<array<ll, 2>> a(n);

    for (auto &[x, y] : a) {
        cin >> x >> y;
        ll sx = x, sy = y;
        x = sx + sy, y = sx - sy;
    }

    sort(a.begin(), a.end());

    vector<ll> res;

    auto solve = [&](ll dist)-> bool {
        res.clear();

        set<pair<ll, int>> st;

        int pnt = 0;

        for (int i = 0; i < n; ++i) {
            auto [x, y] = a[i];

            while (pnt < i && x - a[pnt][0] > dist) {
                st.erase({a[pnt][1], pnt++});
            }

            auto it = st.lower_bound({y - dist, -1});

            while (it != st.end() && it->first <= y + dist) {
                int j = it->second;

                res.push_back(max(a[i][0] - a[j][0], abs(a[i][1] - a[j][1])));

                if (res.size() == k) {
                    return true;
                }

                ++it;
            }

            st.emplace(y, i);
        }

        return false;
    };


    ll ans = 0;

    for (ll x = 1LL << 31; x >= 1; x >>= 1) {
        if (!solve(ans + x)) {
            ans += x;
        }
    }


    solve(ans);

    while (res.size() < k) {
        res.push_back(ans + 1);
    }

    sort(res.begin(), res.end());

    for (int i = 0; i < k; ++i) {
        cout << res[i] << '\n';
    }

    return 0;
}

Compilation message

road_construction.cpp: In lambda function:
road_construction.cpp:36:41: warning: operation on 'pnt' may be undefined [-Wsequence-point]
   36 |                 st.erase({a[pnt][1], pnt++});
      |                                      ~~~^~
road_construction.cpp:46:32: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |                 if (res.size() == k) {
      |                     ~~~~~~~~~~~^~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:71:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |     while (res.size() < k) {
      |            ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 132 ms 5016 KB Output is correct
2 Correct 126 ms 5008 KB Output is correct
3 Correct 117 ms 5012 KB Output is correct
4 Correct 119 ms 5124 KB Output is correct
5 Correct 112 ms 3868 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 10520 KB Output is correct
2 Correct 395 ms 10496 KB Output is correct
3 Correct 98 ms 4864 KB Output is correct
4 Correct 283 ms 10264 KB Output is correct
5 Correct 273 ms 10428 KB Output is correct
6 Correct 318 ms 10516 KB Output is correct
7 Correct 301 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 9208 KB Output is correct
2 Correct 332 ms 9216 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 139 ms 7036 KB Output is correct
5 Correct 507 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 9208 KB Output is correct
2 Correct 332 ms 9216 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 139 ms 7036 KB Output is correct
5 Correct 507 ms 9592 KB Output is correct
6 Correct 470 ms 9212 KB Output is correct
7 Correct 460 ms 9224 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 366 ms 9208 KB Output is correct
11 Correct 142 ms 7168 KB Output is correct
12 Correct 540 ms 9476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 5016 KB Output is correct
2 Correct 126 ms 5008 KB Output is correct
3 Correct 117 ms 5012 KB Output is correct
4 Correct 119 ms 5124 KB Output is correct
5 Correct 112 ms 3868 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 1004 ms 7944 KB Output is correct
8 Correct 962 ms 7984 KB Output is correct
9 Correct 128 ms 5124 KB Output is correct
10 Correct 594 ms 7244 KB Output is correct
11 Correct 359 ms 7172 KB Output is correct
12 Correct 397 ms 8044 KB Output is correct
13 Correct 369 ms 6616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 5016 KB Output is correct
2 Correct 126 ms 5008 KB Output is correct
3 Correct 117 ms 5012 KB Output is correct
4 Correct 119 ms 5124 KB Output is correct
5 Correct 112 ms 3868 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 366 ms 10520 KB Output is correct
8 Correct 395 ms 10496 KB Output is correct
9 Correct 98 ms 4864 KB Output is correct
10 Correct 283 ms 10264 KB Output is correct
11 Correct 273 ms 10428 KB Output is correct
12 Correct 318 ms 10516 KB Output is correct
13 Correct 301 ms 9940 KB Output is correct
14 Correct 222 ms 9208 KB Output is correct
15 Correct 332 ms 9216 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 139 ms 7036 KB Output is correct
18 Correct 507 ms 9592 KB Output is correct
19 Correct 470 ms 9212 KB Output is correct
20 Correct 460 ms 9224 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 366 ms 9208 KB Output is correct
24 Correct 142 ms 7168 KB Output is correct
25 Correct 540 ms 9476 KB Output is correct
26 Correct 1004 ms 7944 KB Output is correct
27 Correct 962 ms 7984 KB Output is correct
28 Correct 128 ms 5124 KB Output is correct
29 Correct 594 ms 7244 KB Output is correct
30 Correct 359 ms 7172 KB Output is correct
31 Correct 397 ms 8044 KB Output is correct
32 Correct 369 ms 6616 KB Output is correct
33 Correct 2067 ms 13344 KB Output is correct
34 Correct 2162 ms 13336 KB Output is correct
35 Correct 1391 ms 12568 KB Output is correct
36 Correct 738 ms 13460 KB Output is correct
37 Correct 766 ms 13496 KB Output is correct
38 Correct 846 ms 12052 KB Output is correct