#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define int long long
#define ll long long
#define vi vector<long long>
#define pb push_back
#define sz(s) (int)s.size()
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define pp pair<int,int>
#define FF first
#define SS second
#define endl "\n"
#define ld long double
const int N = 1e6 + 2, N3 = 1e3 + 6, inf = 1e18 + 7, LOG = 20;
map<char, int> md{{'N', 0}, {'E', 1}, {'S', 2}, {'W', 3}};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
string stepDir = "RDLU";
int n, k, x[N], y[N];
multiset <int> st;
vector <pp> v;
bool check(int z) {
int cnt = 0;
for (int i = 0; i < sz(v); i++) {
for (int j = i + 1; j < sz(v); j++) {
// if (cnt >= k) return 1;
if (abs(v[i].FF - v[j].FF) > z) break;
if (abs(v[i].FF - v[j].FF) + abs(v[i].SS - v[j].SS) <= z) {
cnt++;
// cout << abs(v[i].FF - v[j].FF) + abs(y[i] - y[j]) << " " << x[j] << " " << y[j] << " " << cnt << "\n";
}
}
// cout << cnt << " ";
}
return cnt >= k;
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
v.pb({x[i], y[i]});
}
sort(all(v));
int l = 0, r = inf, best = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
best = mid;
r = mid - 1;
}
else l = mid + 1;
}
vi ans;
for (int i = 0; i < sz(v); i++) {
for (int j = i + 1; j < sz(v); j++) {
if (abs(v[i].FF - v[j].FF) > best) break;
if (abs(v[i].FF - v[j].FF) + abs(v[i].SS - v[j].SS) <= best) {
ans.pb(abs(v[i].FF - v[j].FF) + abs(v[i].SS - v[j].SS));
}
}
}
sort(all(ans));
for (int i = 0; i < k; i++) {
cout << ans[i] << "\n";
}
return 0;
}
Compilation message
road_construction.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
3 | #pragma comment(linker, "/stack:200000000")
|
road_construction.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
5060 KB |
Output is correct |
2 |
Correct |
92 ms |
4960 KB |
Output is correct |
3 |
Correct |
79 ms |
5028 KB |
Output is correct |
4 |
Correct |
68 ms |
5076 KB |
Output is correct |
5 |
Correct |
78 ms |
3832 KB |
Output is correct |
6 |
Correct |
32 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10038 ms |
8216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10006 ms |
8248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10006 ms |
8248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
5060 KB |
Output is correct |
2 |
Correct |
92 ms |
4960 KB |
Output is correct |
3 |
Correct |
79 ms |
5028 KB |
Output is correct |
4 |
Correct |
68 ms |
5076 KB |
Output is correct |
5 |
Correct |
78 ms |
3832 KB |
Output is correct |
6 |
Correct |
32 ms |
388 KB |
Output is correct |
7 |
Execution timed out |
10031 ms |
3596 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
5060 KB |
Output is correct |
2 |
Correct |
92 ms |
4960 KB |
Output is correct |
3 |
Correct |
79 ms |
5028 KB |
Output is correct |
4 |
Correct |
68 ms |
5076 KB |
Output is correct |
5 |
Correct |
78 ms |
3832 KB |
Output is correct |
6 |
Correct |
32 ms |
388 KB |
Output is correct |
7 |
Execution timed out |
10038 ms |
8216 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |