Submission #589732

# Submission time Handle Problem Language Result Execution time Memory
589732 2022-07-05T08:12:50 Z Error42 Road Construction (JOI21_road_construction) C++17
100 / 100
9101 ms 46616 KB
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <set>
#include <map>

using namespace std;

using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;

    map<ll, set<ll>> points;

    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        points[x].insert(y);
    }

    ll worst_dist = (ll)INT_MAX * 5ll;
    priority_queue<ll> best_dists;

    for (auto cur_it_x = points.begin(); cur_it_x != points.end(); ++cur_it_x) {
        auto cur_x = cur_it_x->first;
        const auto& cur_ys = cur_it_x->second;

        for (const auto& cur_y : cur_ys) {

            for (auto cmp_it_x = cur_it_x; cmp_it_x != points.end(); ++cmp_it_x) {
                const auto cmp_x = cmp_it_x->first;

                if (cmp_x > cur_x + worst_dist)
                    break;

                auto dist_x = abs(cur_x - cmp_x);

                for (auto cmp_it_y = cmp_it_x->second.lower_bound(cur_y - worst_dist); cmp_it_y != cmp_it_x->second.end(); ++cmp_it_y) {
                    const auto cmp_y = *cmp_it_y;

                    if (cmp_y - cur_y + dist_x > worst_dist)
                        break;

                    if (cmp_x == cur_x && cmp_y == cur_y)
                        break;

                    auto dist = dist_x + abs(cur_y - cmp_y);

                    best_dists.push(dist);

                    if (best_dists.size() > k) {
                        best_dists.pop();
                        worst_dist = best_dists.top();
                    }
                }
            }

        }
    }

    vector<ll> ans;

    while (!best_dists.empty()) {
        ans.push_back(best_dists.top());
        best_dists.pop();
    }

    reverse(ans.begin(), ans.end());

    for (auto x : ans)
        cout << x << "\n";
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:54:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |                     if (best_dists.size() > k) {
      |                         ~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 102 ms 6968 KB Output is correct
2 Correct 119 ms 7136 KB Output is correct
3 Correct 76 ms 7004 KB Output is correct
4 Correct 62 ms 7056 KB Output is correct
5 Correct 118 ms 5960 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1127 ms 43808 KB Output is correct
2 Correct 1081 ms 43704 KB Output is correct
3 Correct 56 ms 6900 KB Output is correct
4 Correct 1071 ms 43748 KB Output is correct
5 Correct 974 ms 43744 KB Output is correct
6 Correct 962 ms 43836 KB Output is correct
7 Correct 999 ms 43704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 40484 KB Output is correct
2 Correct 501 ms 40584 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 399 ms 38416 KB Output is correct
5 Correct 402 ms 17384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 40484 KB Output is correct
2 Correct 501 ms 40584 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 399 ms 38416 KB Output is correct
5 Correct 402 ms 17384 KB Output is correct
6 Correct 510 ms 40488 KB Output is correct
7 Correct 467 ms 40580 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 478 ms 37992 KB Output is correct
11 Correct 416 ms 38444 KB Output is correct
12 Correct 385 ms 17388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 6968 KB Output is correct
2 Correct 119 ms 7136 KB Output is correct
3 Correct 76 ms 7004 KB Output is correct
4 Correct 62 ms 7056 KB Output is correct
5 Correct 118 ms 5960 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3642 ms 22472 KB Output is correct
8 Correct 3521 ms 22416 KB Output is correct
9 Correct 60 ms 7020 KB Output is correct
10 Correct 2545 ms 19868 KB Output is correct
11 Correct 2741 ms 18960 KB Output is correct
12 Correct 651 ms 13140 KB Output is correct
13 Correct 629 ms 12180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 6968 KB Output is correct
2 Correct 119 ms 7136 KB Output is correct
3 Correct 76 ms 7004 KB Output is correct
4 Correct 62 ms 7056 KB Output is correct
5 Correct 118 ms 5960 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 1127 ms 43808 KB Output is correct
8 Correct 1081 ms 43704 KB Output is correct
9 Correct 56 ms 6900 KB Output is correct
10 Correct 1071 ms 43748 KB Output is correct
11 Correct 974 ms 43744 KB Output is correct
12 Correct 962 ms 43836 KB Output is correct
13 Correct 999 ms 43704 KB Output is correct
14 Correct 455 ms 40484 KB Output is correct
15 Correct 501 ms 40584 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 399 ms 38416 KB Output is correct
18 Correct 402 ms 17384 KB Output is correct
19 Correct 510 ms 40488 KB Output is correct
20 Correct 467 ms 40580 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 478 ms 37992 KB Output is correct
24 Correct 416 ms 38444 KB Output is correct
25 Correct 385 ms 17388 KB Output is correct
26 Correct 3642 ms 22472 KB Output is correct
27 Correct 3521 ms 22416 KB Output is correct
28 Correct 60 ms 7020 KB Output is correct
29 Correct 2545 ms 19868 KB Output is correct
30 Correct 2741 ms 18960 KB Output is correct
31 Correct 651 ms 13140 KB Output is correct
32 Correct 629 ms 12180 KB Output is correct
33 Correct 9101 ms 46616 KB Output is correct
34 Correct 8572 ms 46516 KB Output is correct
35 Correct 5924 ms 37852 KB Output is correct
36 Correct 1072 ms 23312 KB Output is correct
37 Correct 1100 ms 23144 KB Output is correct
38 Correct 1077 ms 22440 KB Output is correct