Submission #601130

# Submission time Handle Problem Language Result Execution time Memory
601130 2022-07-21T11:48:04 Z lordlorinc Road Construction (JOI21_road_construction) C++17
0 / 100
533 ms 11336 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++){
        while (ind < i && sor[i].first - sor[ind].first >= 3) {
            ck.erase(make_pair(sor[ind].second, sor[ind].first));
            ind++;
        }
        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){
            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 -> first - it -> second) / 2;
            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;
        // cout << l << " " << mid << " " << r << endl;
        if (calc(mid).size() >=k) r = mid;
        else l = mid + 1;
    }

    mo = calc(l);
    for (int i = 0; i < k; i++){
        cout << mo[i] << '\n';
    }

    return 0;
}

Compilation message

road_construction.cpp: In function 'std::vector<long long int> calc(int)':
road_construction.cpp:21: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]
   21 |         while (res.size() < k && it != ck.end() && it -> first <= sor[i].second + r){
      |                ~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48: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]
   48 |         if (calc(mid).size() >=k) r = mid;
      |             ~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 370 ms 11336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 533 ms 9176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 533 ms 9176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -