Submission #910834

# Submission time Handle Problem Language Result Execution time Memory
910834 2024-01-18T08:23:49 Z Tuanlinh123 Road Construction (JOI21_road_construction) C++17
100 / 100
1578 ms 13672 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

pll p[250005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, k; cin >> n >> k;
    for (ll i=1; i<=n; i++)
    {
        ll x, y; cin >> x >> y;
        p[i]={x+y, x-y};
    }
    sort(p+1, p+n+1);
    vector <ll> ans;
    auto calc=[&](ll mid, bool trace)
    {
        set <pll> s;
        for (ll i=1, ptr=1, cnt=0; i<=n; i++)
        {
            while (ptr<i && p[ptr].fi<p[i].fi-mid)
                s.erase(mp(p[ptr].se, ptr)), ptr++;
            auto it=s.lower_bound(mp(p[i].se-mid, 0));
            while (it!=s.end() && (*it).fi<=p[i].se+mid)
            {
                if (++cnt>k) return 0;
                if (trace) ans.pb(max(abs(p[i].fi-p[(*it).se].fi), abs(p[i].se-p[(*it).se].se)));
                it++;
            }
            s.insert(mp(p[i].se, i));
        }
        return 1;
    };
    ll lo=0, hi=4e9;
    while (lo<hi)
    {
        ll mid=(lo+hi+1)/2;
        if (calc(mid, 0))
            lo=mid;
        else hi=mid-1;
    }
    calc(lo, 1);
    sort(ans.begin(), ans.end());
    while (ans.size()<k) ans.pb(lo+1);
    for (ll i:ans) cout << i << "\n";
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:53:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   53 |     while (ans.size()<k) ans.pb(lo+1);
      |            ~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 76 ms 5072 KB Output is correct
2 Correct 79 ms 5156 KB Output is correct
3 Correct 74 ms 5052 KB Output is correct
4 Correct 68 ms 5256 KB Output is correct
5 Correct 74 ms 4000 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 7628 KB Output is correct
2 Correct 292 ms 7648 KB Output is correct
3 Correct 62 ms 5096 KB Output is correct
4 Correct 235 ms 7512 KB Output is correct
5 Correct 260 ms 7612 KB Output is correct
6 Correct 249 ms 7824 KB Output is correct
7 Correct 226 ms 6820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 4344 KB Output is correct
2 Correct 249 ms 4180 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 120 ms 7260 KB Output is correct
5 Correct 267 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 4344 KB Output is correct
2 Correct 249 ms 4180 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 120 ms 7260 KB Output is correct
5 Correct 267 ms 9812 KB Output is correct
6 Correct 382 ms 9192 KB Output is correct
7 Correct 371 ms 9516 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 294 ms 9440 KB Output is correct
11 Correct 105 ms 7288 KB Output is correct
12 Correct 301 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 5072 KB Output is correct
2 Correct 79 ms 5156 KB Output is correct
3 Correct 74 ms 5052 KB Output is correct
4 Correct 68 ms 5256 KB Output is correct
5 Correct 74 ms 4000 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 727 ms 8928 KB Output is correct
8 Correct 733 ms 8896 KB Output is correct
9 Correct 68 ms 5268 KB Output is correct
10 Correct 394 ms 7940 KB Output is correct
11 Correct 232 ms 7884 KB Output is correct
12 Correct 294 ms 8968 KB Output is correct
13 Correct 373 ms 7364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 5072 KB Output is correct
2 Correct 79 ms 5156 KB Output is correct
3 Correct 74 ms 5052 KB Output is correct
4 Correct 68 ms 5256 KB Output is correct
5 Correct 74 ms 4000 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 293 ms 7628 KB Output is correct
8 Correct 292 ms 7648 KB Output is correct
9 Correct 62 ms 5096 KB Output is correct
10 Correct 235 ms 7512 KB Output is correct
11 Correct 260 ms 7612 KB Output is correct
12 Correct 249 ms 7824 KB Output is correct
13 Correct 226 ms 6820 KB Output is correct
14 Correct 273 ms 4344 KB Output is correct
15 Correct 249 ms 4180 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 120 ms 7260 KB Output is correct
18 Correct 267 ms 9812 KB Output is correct
19 Correct 382 ms 9192 KB Output is correct
20 Correct 371 ms 9516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 294 ms 9440 KB Output is correct
24 Correct 105 ms 7288 KB Output is correct
25 Correct 301 ms 9552 KB Output is correct
26 Correct 727 ms 8928 KB Output is correct
27 Correct 733 ms 8896 KB Output is correct
28 Correct 68 ms 5268 KB Output is correct
29 Correct 394 ms 7940 KB Output is correct
30 Correct 232 ms 7884 KB Output is correct
31 Correct 294 ms 8968 KB Output is correct
32 Correct 373 ms 7364 KB Output is correct
33 Correct 1492 ms 13536 KB Output is correct
34 Correct 1578 ms 13436 KB Output is correct
35 Correct 1004 ms 12756 KB Output is correct
36 Correct 478 ms 13672 KB Output is correct
37 Correct 459 ms 13644 KB Output is correct
38 Correct 584 ms 12288 KB Output is correct