#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define freopen(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
const int N = 250000 + 5;
const int M = 1e3 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e17;
int n, k, x[N], y[N], id[N], cc;
vector<pair<int, int>> v;
int dist(int i, int j){
return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}
int convert(int i, int j){
if(i < j) swap(i, j);
return i * (n + 1) + j;
}
multiset<int> st;
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
v.pb({x[i], y[i]});
}
sort(all(v));
cc = 500000000 / n;
for(int i = 1; i <= n; i++){
x[i] = v[i - 1].F;
y[i] = v[i - 1].S;
for(int j = max(1ll, i - cc); j < i; j++){
if(st.size() < k){
st.insert(dist(i, j));
}else{
auto to = st.end();
to--;
if(*to > dist(i, j)){
st.erase(to);
st.insert(dist(i, j));
}
}
}
}
while(k--){
cout << *(st.begin()) << '\n';
st.erase(st.begin());
}
//N * log() * const
}
main() {
fast
int tt = 1;
// cin >> tt;
while(tt--){
solve();
}
}
Compilation message
road_construction.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("O3")
|
road_construction.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
4 | #pragma GCC optimization("unroll-loops")
|
road_construction.cpp:5: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
5 | #pragma comment(linker, "/stack:200000000")
|
road_construction.cpp: In function 'void solve()':
road_construction.cpp:51:26: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
51 | if(st.size() < k){
| ~~~~~~~~~~^~~
road_construction.cpp: At global scope:
road_construction.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
72 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
14652 KB |
Output is correct |
2 |
Correct |
292 ms |
14668 KB |
Output is correct |
3 |
Correct |
133 ms |
14660 KB |
Output is correct |
4 |
Correct |
165 ms |
14760 KB |
Output is correct |
5 |
Correct |
196 ms |
13516 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2549 ms |
23436 KB |
Output is correct |
2 |
Correct |
2446 ms |
22932 KB |
Output is correct |
3 |
Correct |
136 ms |
14584 KB |
Output is correct |
4 |
Correct |
2221 ms |
22672 KB |
Output is correct |
5 |
Correct |
1965 ms |
23992 KB |
Output is correct |
6 |
Correct |
1982 ms |
24080 KB |
Output is correct |
7 |
Correct |
2005 ms |
23428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1363 ms |
12632 KB |
Output is correct |
2 |
Correct |
1376 ms |
13316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1339 ms |
11136 KB |
Output is correct |
5 |
Correct |
1438 ms |
13236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1363 ms |
12632 KB |
Output is correct |
2 |
Correct |
1376 ms |
13316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1339 ms |
11136 KB |
Output is correct |
5 |
Correct |
1438 ms |
13236 KB |
Output is correct |
6 |
Correct |
1396 ms |
12764 KB |
Output is correct |
7 |
Correct |
1364 ms |
13484 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1375 ms |
13088 KB |
Output is correct |
11 |
Correct |
1350 ms |
11192 KB |
Output is correct |
12 |
Correct |
1381 ms |
13116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
14652 KB |
Output is correct |
2 |
Correct |
292 ms |
14668 KB |
Output is correct |
3 |
Correct |
133 ms |
14660 KB |
Output is correct |
4 |
Correct |
165 ms |
14760 KB |
Output is correct |
5 |
Correct |
196 ms |
13516 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2508 ms |
19264 KB |
Output is correct |
8 |
Correct |
2587 ms |
19188 KB |
Output is correct |
9 |
Correct |
115 ms |
14676 KB |
Output is correct |
10 |
Correct |
2566 ms |
18528 KB |
Output is correct |
11 |
Correct |
2907 ms |
18308 KB |
Output is correct |
12 |
Correct |
1608 ms |
19220 KB |
Output is correct |
13 |
Correct |
1910 ms |
17724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
14652 KB |
Output is correct |
2 |
Correct |
292 ms |
14668 KB |
Output is correct |
3 |
Correct |
133 ms |
14660 KB |
Output is correct |
4 |
Correct |
165 ms |
14760 KB |
Output is correct |
5 |
Correct |
196 ms |
13516 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2549 ms |
23436 KB |
Output is correct |
8 |
Correct |
2446 ms |
22932 KB |
Output is correct |
9 |
Correct |
136 ms |
14584 KB |
Output is correct |
10 |
Correct |
2221 ms |
22672 KB |
Output is correct |
11 |
Correct |
1965 ms |
23992 KB |
Output is correct |
12 |
Correct |
1982 ms |
24080 KB |
Output is correct |
13 |
Correct |
2005 ms |
23428 KB |
Output is correct |
14 |
Correct |
1363 ms |
12632 KB |
Output is correct |
15 |
Correct |
1376 ms |
13316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1339 ms |
11136 KB |
Output is correct |
18 |
Correct |
1438 ms |
13236 KB |
Output is correct |
19 |
Correct |
1396 ms |
12764 KB |
Output is correct |
20 |
Correct |
1364 ms |
13484 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1375 ms |
13088 KB |
Output is correct |
24 |
Correct |
1350 ms |
11192 KB |
Output is correct |
25 |
Correct |
1381 ms |
13116 KB |
Output is correct |
26 |
Correct |
2508 ms |
19264 KB |
Output is correct |
27 |
Correct |
2587 ms |
19188 KB |
Output is correct |
28 |
Correct |
115 ms |
14676 KB |
Output is correct |
29 |
Correct |
2566 ms |
18528 KB |
Output is correct |
30 |
Correct |
2907 ms |
18308 KB |
Output is correct |
31 |
Correct |
1608 ms |
19220 KB |
Output is correct |
32 |
Correct |
1910 ms |
17724 KB |
Output is correct |
33 |
Correct |
2765 ms |
26948 KB |
Output is correct |
34 |
Correct |
2926 ms |
26888 KB |
Output is correct |
35 |
Correct |
2849 ms |
26124 KB |
Output is correct |
36 |
Correct |
1665 ms |
26968 KB |
Output is correct |
37 |
Correct |
1660 ms |
26892 KB |
Output is correct |
38 |
Correct |
2047 ms |
25620 KB |
Output is correct |