Submission #782266

# Submission time Handle Problem Language Result Execution time Memory
782266 2023-07-13T16:58:17 Z PoonYaPat Road Construction (JOI21_road_construction) C++14
100 / 100
1490 ms 15360 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

int n,k;
pii a[250005];
vector<ll> ans;

bool check(ll want, int mode) {
    vector<ll> res;
    set<pii> s;

    for (int l=1, r=1; r<=n; ++r) {
        while (a[l].first<a[r].first-want) {
            s.erase(s.find({a[l].second,a[l].first}));
            ++l;
        }

        auto it=s.upper_bound({a[r].second-want,-1e15});
        while (it!=s.end() && (*it).first<=a[r].second+want) {
            res.push_back(max(abs((*it).second-a[r].first),abs((*it).first-a[r].second)));
            if (res.size()==k) return true;
            ++it;
        }

        s.insert(pii(a[r].second,a[r].first));
    }

    if (mode) swap(ans,res);
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k;
    for (int i=1; i<=n; ++i) {
        ll x,y; cin>>x>>y;
        a[i].first=x+y;
        a[i].second=x-y;
    }
    sort(a+1,a+n+1);

    ll l=1, r=4e9;
    while (l<r) {
        ll mid=(l+r)/2;
        if (check(mid,0)) r=mid;
        else l=mid+1;
    }
    check(l-1,1);
    while (ans.size()<k) ans.push_back(l);
    sort(ans.begin(),ans.end());
    for (auto s : ans) cout<<s<<"\n";
}

Compilation message

road_construction.cpp: In function 'bool check(ll, int)':
road_construction.cpp:23:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |             if (res.size()==k) return true;
      |                 ~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:51:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     while (ans.size()<k) ans.push_back(l);
      |            ~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 110 ms 6900 KB Output is correct
2 Correct 111 ms 6944 KB Output is correct
3 Correct 110 ms 7044 KB Output is correct
4 Correct 99 ms 6984 KB Output is correct
5 Correct 104 ms 5820 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 12404 KB Output is correct
2 Correct 381 ms 12496 KB Output is correct
3 Correct 95 ms 6896 KB Output is correct
4 Correct 269 ms 12200 KB Output is correct
5 Correct 253 ms 12408 KB Output is correct
6 Correct 259 ms 12484 KB Output is correct
7 Correct 231 ms 11864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 9212 KB Output is correct
2 Correct 241 ms 9288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 121 ms 7120 KB Output is correct
5 Correct 273 ms 9548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 9212 KB Output is correct
2 Correct 241 ms 9288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 121 ms 7120 KB Output is correct
5 Correct 273 ms 9548 KB Output is correct
6 Correct 342 ms 9400 KB Output is correct
7 Correct 312 ms 9220 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 257 ms 9292 KB Output is correct
11 Correct 109 ms 7144 KB Output is correct
12 Correct 261 ms 9568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 6900 KB Output is correct
2 Correct 111 ms 6944 KB Output is correct
3 Correct 110 ms 7044 KB Output is correct
4 Correct 99 ms 6984 KB Output is correct
5 Correct 104 ms 5820 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 713 ms 9936 KB Output is correct
8 Correct 715 ms 9984 KB Output is correct
9 Correct 104 ms 6936 KB Output is correct
10 Correct 405 ms 9224 KB Output is correct
11 Correct 257 ms 9072 KB Output is correct
12 Correct 281 ms 9844 KB Output is correct
13 Correct 392 ms 8596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 6900 KB Output is correct
2 Correct 111 ms 6944 KB Output is correct
3 Correct 110 ms 7044 KB Output is correct
4 Correct 99 ms 6984 KB Output is correct
5 Correct 104 ms 5820 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 409 ms 12404 KB Output is correct
8 Correct 381 ms 12496 KB Output is correct
9 Correct 95 ms 6896 KB Output is correct
10 Correct 269 ms 12200 KB Output is correct
11 Correct 253 ms 12408 KB Output is correct
12 Correct 259 ms 12484 KB Output is correct
13 Correct 231 ms 11864 KB Output is correct
14 Correct 187 ms 9212 KB Output is correct
15 Correct 241 ms 9288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 121 ms 7120 KB Output is correct
18 Correct 273 ms 9548 KB Output is correct
19 Correct 342 ms 9400 KB Output is correct
20 Correct 312 ms 9220 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 257 ms 9292 KB Output is correct
24 Correct 109 ms 7144 KB Output is correct
25 Correct 261 ms 9568 KB Output is correct
26 Correct 713 ms 9936 KB Output is correct
27 Correct 715 ms 9984 KB Output is correct
28 Correct 104 ms 6936 KB Output is correct
29 Correct 405 ms 9224 KB Output is correct
30 Correct 257 ms 9072 KB Output is correct
31 Correct 281 ms 9844 KB Output is correct
32 Correct 392 ms 8596 KB Output is correct
33 Correct 1484 ms 15268 KB Output is correct
34 Correct 1490 ms 15360 KB Output is correct
35 Correct 991 ms 14528 KB Output is correct
36 Correct 463 ms 15308 KB Output is correct
37 Correct 527 ms 15228 KB Output is correct
38 Correct 562 ms 14040 KB Output is correct