Submission #995530

# Submission time Handle Problem Language Result Execution time Memory
995530 2024-06-09T09:30:34 Z vladilius Road Construction (JOI21_road_construction) C++17
100 / 100
1628 ms 26224 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
const ll inf = 1e9;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, k; cin>>n>>k;
    vector<pii> p(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>p[i].ff>>p[i].ss;
    }
    sort(p.begin() + 1, p.end());
    vector<ll> dist;
    auto get = [&](ll r, bool ind){
        multiset<pii> st;
        int j = 1;
        for (int i = 1; i <= n; i++){
            if (ind && dist.size() >= k) break;
            while (j < i && (p[i].ff - p[j].ff) > r){
                st.erase(st.find({p[j].ss, p[j].ff}));
                j++;
            }
            auto it = st.lower_bound({p[i].ss - r, -inf});
            ll R = p[i].ss + r;
            while (it != st.end() && (*it).ff <= R){
                ll d = abs(p[i].ff - (*it).ss) + abs(p[i].ss - (*it).ff);
                if (d <= r){
                    dist.pb(d);
                }
                it++;
            }
            st.insert({p[i].ss, p[i].ff});
        }
    };
    
    ll l = 0, r = 4LL * inf;
    while (l + 1 < r){
        ll m = (l + r) / 2;
        get(m, 1);
        if (dist.size() < k){
            l = m + 1;
        }
        else {
            r = m;
        }
        dist.clear();
    }
    get(r, 0);
    assert(dist.size() >= k);
    sort(dist.begin(), dist.end());
    for (int i = 0; i < k; i++){
        cout<<dist[i]<<"\n";
    }
}

Compilation message

road_construction.cpp: In lambda function:
road_construction.cpp:27:36: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (ind && dist.size() >= k) break;
      |                        ~~~~~~~~~~~~^~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:49:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if (dist.size() < k){
      |             ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from road_construction.cpp:1:
road_construction.cpp:58:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |     assert(dist.size() >= k);
      |            ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 121 ms 5072 KB Output is correct
2 Correct 124 ms 5072 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 81 ms 5076 KB Output is correct
5 Correct 79 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 10564 KB Output is correct
2 Correct 225 ms 10708 KB Output is correct
3 Correct 70 ms 5072 KB Output is correct
4 Correct 199 ms 11728 KB Output is correct
5 Correct 177 ms 12424 KB Output is correct
6 Correct 169 ms 12648 KB Output is correct
7 Correct 161 ms 11656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 8536 KB Output is correct
2 Correct 229 ms 8616 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 97 ms 9060 KB Output is correct
5 Correct 224 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 8536 KB Output is correct
2 Correct 229 ms 8616 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 97 ms 9060 KB Output is correct
5 Correct 224 ms 12756 KB Output is correct
6 Correct 314 ms 8276 KB Output is correct
7 Correct 281 ms 8236 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 217 ms 8340 KB Output is correct
11 Correct 81 ms 9024 KB Output is correct
12 Correct 231 ms 12816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 5072 KB Output is correct
2 Correct 124 ms 5072 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 81 ms 5076 KB Output is correct
5 Correct 79 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 816 ms 8148 KB Output is correct
8 Correct 783 ms 8012 KB Output is correct
9 Correct 73 ms 5068 KB Output is correct
10 Correct 384 ms 7488 KB Output is correct
11 Correct 246 ms 7124 KB Output is correct
12 Correct 239 ms 9200 KB Output is correct
13 Correct 218 ms 8376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 5072 KB Output is correct
2 Correct 124 ms 5072 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 81 ms 5076 KB Output is correct
5 Correct 79 ms 4048 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 229 ms 10564 KB Output is correct
8 Correct 225 ms 10708 KB Output is correct
9 Correct 70 ms 5072 KB Output is correct
10 Correct 199 ms 11728 KB Output is correct
11 Correct 177 ms 12424 KB Output is correct
12 Correct 169 ms 12648 KB Output is correct
13 Correct 161 ms 11656 KB Output is correct
14 Correct 145 ms 8536 KB Output is correct
15 Correct 229 ms 8616 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 97 ms 9060 KB Output is correct
18 Correct 224 ms 12756 KB Output is correct
19 Correct 314 ms 8276 KB Output is correct
20 Correct 281 ms 8236 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 217 ms 8340 KB Output is correct
24 Correct 81 ms 9024 KB Output is correct
25 Correct 231 ms 12816 KB Output is correct
26 Correct 816 ms 8148 KB Output is correct
27 Correct 783 ms 8012 KB Output is correct
28 Correct 73 ms 5068 KB Output is correct
29 Correct 384 ms 7488 KB Output is correct
30 Correct 246 ms 7124 KB Output is correct
31 Correct 239 ms 9200 KB Output is correct
32 Correct 218 ms 8376 KB Output is correct
33 Correct 1581 ms 13448 KB Output is correct
34 Correct 1628 ms 13524 KB Output is correct
35 Correct 830 ms 12756 KB Output is correct
36 Correct 417 ms 19436 KB Output is correct
37 Correct 451 ms 19388 KB Output is correct
38 Correct 428 ms 26224 KB Output is correct