Submission #601159

# Submission time Handle Problem Language Result Execution time Memory
601159 2022-07-21T12:13:36 Z lordlorinc Road Construction (JOI21_road_construction) C++17
6 / 100
2438 ms 26104 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll n, k;
vector<pair<ll, ll> > sor;
set<pair<ll, ll> > ck;
vector<ll> mo;

vector<ll> calc(int r){
    ck.clear();
    vector<ll> res;
    int ind = 0;
    for (int i = 0; i < n; i++){
        // cout << sor[i].first << " " << sor[i].second << ": " << endl;
        while (ind < i && sor[i].first - sor[ind].first > r) {
            ck.erase(make_pair(sor[ind].second, sor[ind].first));
            ind++;
        }
        // for (auto x : ck){
        //     cout << x.first << " " << x.second << endl;
        // }
        auto it = ck.lower_bound(make_pair(sor[i].second - r, -4000000001));
        while (res.size() < k && it != ck.end() && it -> first <= sor[i].second + r){
            // cout << it -> first << " " << it -> second << endl;
            ll x1 = (sor[i].first + sor[i].second) / 2, y1 = (sor[i].first - sor[i].second) / 2;
            ll x2 = (it -> first + it -> second) / 2, y2 = (it -> second - it -> first) / 2;
            // cout << x1 << " " << y1 << " " << x2 << " " << y2 << ": " << abs(x1 - x2) + abs(y1 - y2) << endl;
            res.push_back(abs(x1 - x2) + abs(y1 - y2));
            it++;
        }
        ck.insert(make_pair(sor[i].second, sor[i].first));
    }
    return res;
}

int main(){

    cin >> n >> k;
    sor.resize(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        sor[i] = make_pair(a + b, a - b);
    }

    sort (sor.begin(), sor.end());

    ll l = 0, r = 4000000001;
    while (l != r){
        ll mid = (l + r) / 2;
        if (calc(mid).size() >=k) r = mid;
        else l = mid + 1;
    }

    mo = calc(l - 1);

    sort(mo.begin(), mo.end());
    for (int i = 0; i < k; i++){
        if (i < mo.size()) cout << mo[i] << '\n';
        else cout << l << '\n';
    }

    return 0;
}

Compilation message

road_construction.cpp: In function 'std::vector<long long int> calc(int)':
road_construction.cpp:25:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   25 |         while (res.size() < k && it != ck.end() && it -> first <= sor[i].second + r){
      |                ~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:53:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   53 |         if (calc(mid).size() >=k) r = mid;
      |             ~~~~~~~~~~~~~~~~~^~~
road_construction.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if (i < mo.size()) cout << mo[i] << '\n';
      |             ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6880 KB Output is correct
2 Correct 166 ms 6928 KB Output is correct
3 Incorrect 27 ms 3156 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1170 ms 23456 KB Output is correct
2 Correct 1201 ms 24748 KB Output is correct
3 Correct 144 ms 6944 KB Output is correct
4 Correct 1097 ms 24776 KB Output is correct
5 Correct 1245 ms 26000 KB Output is correct
6 Correct 1219 ms 26104 KB Output is correct
7 Correct 1240 ms 25448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2345 ms 17520 KB Output is correct
2 Correct 2438 ms 21064 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2345 ms 17520 KB Output is correct
2 Correct 2438 ms 21064 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6880 KB Output is correct
2 Correct 166 ms 6928 KB Output is correct
3 Incorrect 27 ms 3156 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6880 KB Output is correct
2 Correct 166 ms 6928 KB Output is correct
3 Incorrect 27 ms 3156 KB Output isn't correct
4 Halted 0 ms 0 KB -