| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 601166 | lordlorinc | Road Construction (JOI21_road_construction) | C++17 | 3784 ms | 28948 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(ll r){
ck.clear();
vector<ll> res;
ll ind = 0;
for (ll 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 (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
sor[i] = make_pair(a + b, a - b);
}
sort (sor.begin(), sor.end());
ll l = 0, r = 40000000001;
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 (ll i = 0; i < k; i++){
if (i < mo.size()) cout << mo[i] << '\n';
else cout << l << '\n';
}
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
