# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1169680 | SmuggingSpun | Road Construction (JOI21_road_construction) | C++20 | 88 ms | 7616 KiB |
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
const int lim = 25e4 + 5;
const ll INF = 5e9;
int n, k;
ll x[lim], y[lim];
namespace sub1{
void solve(){
vector<ll>a;
for(int i = 1; i < n; i++){
for(int j = i + 1; j <= n; j++){
a.emplace_back(abs(x[i] - x[j]) + abs(y[i] - y[j]));
}
}
sort(a.begin(), a.end());
for(int i = 0; i < k; i++){
cout << a[i] << "\n";
}
}
}
namespace sub2{
void solve(){
sort(x + 1, x + n + 1);
ll low = 1, high = INF, d = 0;
while(low <= high){
ll mid = (low + high) >> 1LL;
int cnt = 0;
for(int i = 1, j = 1; i <= n; i++){
while(x[i] - x[j] > mid){
j++;
}
if((cnt += i - j) >= k){
break;
}
}
if(cnt >= k){
high = (d = mid) - 1;
}
else{
low = mid + 1;
}
}
vector<ll>ans;
for(int i = 1; i <= n; i++){
for(int j = i - 1; j > 0 && x[i] - x[j] < d; j--){
ans.emplace_back(x[i] - x[j]);
}
}
sort(ans.begin(), ans.end());
for(ll& x : ans){
cout << x << "\n";
}
for(int i = ans.size(); i < k; i++){
cout << d << "\n";
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
}
if(n <= 1000){
sub1::solve();
}
else if(count(y + 1, y + n + 1, 0) == n){
sub2::solve();
}
}
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... |