Submission #1033003

# Submission time Handle Problem Language Result Execution time Memory
1033003 2024-07-24T11:52:44 Z adaawf Road Construction (JOI21_road_construction) C++17
100 / 100
1716 ms 19548 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
long long int n, k;
struct POINT {
    long long int x, y;
} a[250005];
bool cmp(POINT aa, POINT bb) {
    return aa.x < bb.x;
}
vector<long long int> v;
bool check(long long int x, int flag) {
    long long int c = 0;
    set<pair<long long int, long long int>> s;
    int j = 1;
    for (int i = 1; i <= n; i++) {
        while (a[j].x < a[i].x - x) {
            s.erase(s.find({a[j].y, a[j].x}));
            j++;
        }
        for (auto it = s.lower_bound({a[i].y - x, -1e18}); it != s.upper_bound({a[i].y + x, 1e18}); it++) {
            if (flag == 0) c++;
            else v.push_back(max(abs(a[i].x - (*it).second), abs(a[i].y - (*it).first)));
            if (c == k) return true;
        }
        s.insert({a[i].y, a[i].x});
    }
    return false;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        long long int x, y;
        cin >> x >> y;
        a[i].x = x + y;
        a[i].y = x - y;
    }
    sort(a + 1, a + n + 1, cmp);
    long long int l = 1, r = 4e9, res;
    while (l <= r) {
        long long int mid = (l + r) / 2;
        if (check(mid, 0)) {
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    check(res, 1);
    sort(v.begin(), v.end());
    for (int i = 0; i < k; i++) cout << v[i] << '\n';
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:52:10: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     check(res, 1);
      |     ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 176 ms 5068 KB Output is correct
2 Correct 174 ms 5060 KB Output is correct
3 Correct 160 ms 5256 KB Output is correct
4 Correct 187 ms 5076 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 10596 KB Output is correct
2 Correct 268 ms 10724 KB Output is correct
3 Correct 174 ms 4988 KB Output is correct
4 Correct 302 ms 11664 KB Output is correct
5 Correct 253 ms 12508 KB Output is correct
6 Correct 237 ms 12512 KB Output is correct
7 Correct 221 ms 11732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 9556 KB Output is correct
2 Correct 190 ms 9376 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 119 ms 9220 KB Output is correct
5 Correct 509 ms 13924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 9556 KB Output is correct
2 Correct 190 ms 9376 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 119 ms 9220 KB Output is correct
5 Correct 509 ms 13924 KB Output is correct
6 Correct 306 ms 9296 KB Output is correct
7 Correct 243 ms 9296 KB Output is correct
8 Correct 0 ms 464 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 217 ms 9268 KB Output is correct
11 Correct 133 ms 9272 KB Output is correct
12 Correct 583 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 5068 KB Output is correct
2 Correct 174 ms 5060 KB Output is correct
3 Correct 160 ms 5256 KB Output is correct
4 Correct 187 ms 5076 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 982 ms 8052 KB Output is correct
8 Correct 889 ms 8124 KB Output is correct
9 Correct 169 ms 5268 KB Output is correct
10 Correct 416 ms 7264 KB Output is correct
11 Correct 306 ms 7612 KB Output is correct
12 Correct 614 ms 9400 KB Output is correct
13 Correct 741 ms 8640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 5068 KB Output is correct
2 Correct 174 ms 5060 KB Output is correct
3 Correct 160 ms 5256 KB Output is correct
4 Correct 187 ms 5076 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 276 ms 10596 KB Output is correct
8 Correct 268 ms 10724 KB Output is correct
9 Correct 174 ms 4988 KB Output is correct
10 Correct 302 ms 11664 KB Output is correct
11 Correct 253 ms 12508 KB Output is correct
12 Correct 237 ms 12512 KB Output is correct
13 Correct 221 ms 11732 KB Output is correct
14 Correct 183 ms 9556 KB Output is correct
15 Correct 190 ms 9376 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 119 ms 9220 KB Output is correct
18 Correct 509 ms 13924 KB Output is correct
19 Correct 306 ms 9296 KB Output is correct
20 Correct 243 ms 9296 KB Output is correct
21 Correct 0 ms 464 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 217 ms 9268 KB Output is correct
24 Correct 133 ms 9272 KB Output is correct
25 Correct 583 ms 9704 KB Output is correct
26 Correct 982 ms 8052 KB Output is correct
27 Correct 889 ms 8124 KB Output is correct
28 Correct 169 ms 5268 KB Output is correct
29 Correct 416 ms 7264 KB Output is correct
30 Correct 306 ms 7612 KB Output is correct
31 Correct 614 ms 9400 KB Output is correct
32 Correct 741 ms 8640 KB Output is correct
33 Correct 1668 ms 13440 KB Output is correct
34 Correct 1716 ms 13416 KB Output is correct
35 Correct 907 ms 12772 KB Output is correct
36 Correct 1089 ms 19548 KB Output is correct
37 Correct 1056 ms 19468 KB Output is correct
38 Correct 1041 ms 13932 KB Output is correct