#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const int M = 2 * N + 5;
int l[N], r[N], u[N], d[N], n, k;
bitset<N> used, full;
vector<pair<int, int>> points;
vector<int> X, Y, cl[M], op[M];
void rec();
inline bool check() {
return used.count() == 0;
}
inline bool inter(int i, int x, int y) {
return l[i] <= x && x <= r[i] && d[i] <= y && y <= u[i];
}
inline void add_point(int x, int y) {
vector<int> change;
for (int i = used._Find_first(); i < n; i = used._Find_next(i)) {
if (inter(i, x, y)) {
used[i] = false;
change.push_back(i);
}
}
if (change.empty())
return;
points.emplace_back(x, y);
rec();
for (auto cc: change) used[cc] = true;
points.pop_back();
}
void rec() {
if (check() && (int) points.size() <= k) {
for (int i = 0; i < (int) points.size(); i++)
cout << X[points[i].first] << ' ' << Y[points[i].second] << '\n';
for (int i = points.size(); i < k; i++)
cout << 1 << ' ' << 1 << '\n';
exit(0);
}
if (points.size() >= k)
return;
int minR = 2 * n;
int minU = 2 * n;
int maxD = 0;
int maxL = 0;
for (int i = used._Find_first(); i < n; i = used._Find_next(i)) {
minR = min(minR, r[i]);
maxL = max(maxL, l[i]);
minU = min(minU, u[i]);
maxD = max(maxD, d[i]);
}
if (maxL <= minR) {
add_point(minR, minU);
}
else if (maxD <= minU) {
add_point(minR, minU);
}
else {
add_point(minR, minU);
add_point(minR, maxD);
add_point(maxL, minU);
add_point(maxL, maxD);
if (points.size())
return;
for (int h = minU + 1; h < maxD; h++)
add_point(minR, h);
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
X.reserve(2 * n), Y.reserve(2 * n);
for (int i = 0; i < n; i++) {
cin >> l[i] >> d[i] >> r[i] >> u[i];
X.push_back(l[i]);
X.push_back(r[i]);
Y.push_back(d[i]);
Y.push_back(u[i]);
}
sort(X.begin(), X.end());
X.resize(unique(X.begin(), X.end()) - X.begin());
sort(Y.begin(), Y.end());
Y.resize(unique(Y.begin(), Y.end()) - Y.begin());
for (int i = 0; i < n; i++) {
l[i] = lower_bound(X.begin(), X.end(), l[i]) - X.begin();
r[i] = lower_bound(X.begin(), X.end(), r[i]) - X.begin();
u[i] = lower_bound(Y.begin(), Y.end(), u[i]) - Y.begin();
d[i] = lower_bound(Y.begin(), Y.end(), d[i]) - Y.begin();
}
for (int i = 0; i < n; i++)
used[i] = true;
rec();
cout << "NO I DID NOT FIND ANYTHING\n";
return 0;
}
Compilation message
hamburg.cpp: In function 'void rec()':
hamburg.cpp:48:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
48 | if (points.size() >= k)
| ~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19156 KB |
Output is correct |
2 |
Correct |
13 ms |
19152 KB |
Output is correct |
3 |
Correct |
11 ms |
19196 KB |
Output is correct |
4 |
Correct |
11 ms |
19156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19204 KB |
Output is correct |
2 |
Correct |
11 ms |
19296 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19224 KB |
Output is correct |
2 |
Correct |
13 ms |
19156 KB |
Output is correct |
3 |
Correct |
11 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
11 ms |
19156 KB |
Output is correct |
6 |
Correct |
12 ms |
19156 KB |
Output is correct |
7 |
Correct |
13 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19156 KB |
Output is correct |
9 |
Correct |
16 ms |
19156 KB |
Output is correct |
10 |
Correct |
15 ms |
19148 KB |
Output is correct |
11 |
Correct |
14 ms |
19156 KB |
Output is correct |
12 |
Correct |
15 ms |
19128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19156 KB |
Output is correct |
2 |
Correct |
11 ms |
19144 KB |
Output is correct |
3 |
Correct |
13 ms |
19156 KB |
Output is correct |
4 |
Correct |
11 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19156 KB |
Output is correct |
6 |
Correct |
13 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19208 KB |
Output is correct |
9 |
Correct |
12 ms |
19156 KB |
Output is correct |
10 |
Correct |
13 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
12 ms |
19156 KB |
Output is correct |
13 |
Correct |
19 ms |
19156 KB |
Output is correct |
14 |
Correct |
628 ms |
19276 KB |
Output is correct |
15 |
Correct |
17 ms |
19156 KB |
Output is correct |
16 |
Correct |
14 ms |
19156 KB |
Output is correct |
17 |
Correct |
1208 ms |
19156 KB |
Output is correct |
18 |
Correct |
15 ms |
19156 KB |
Output is correct |
19 |
Correct |
15 ms |
19156 KB |
Output is correct |
20 |
Correct |
2715 ms |
19284 KB |
Output is correct |
21 |
Correct |
19 ms |
19220 KB |
Output is correct |
22 |
Correct |
20 ms |
19228 KB |
Output is correct |
23 |
Correct |
1012 ms |
19204 KB |
Output is correct |
24 |
Correct |
14 ms |
19188 KB |
Output is correct |
25 |
Correct |
13 ms |
19148 KB |
Output is correct |
26 |
Correct |
18 ms |
19336 KB |
Output is correct |
27 |
Correct |
14 ms |
19156 KB |
Output is correct |
28 |
Correct |
13 ms |
19156 KB |
Output is correct |
29 |
Correct |
16 ms |
19156 KB |
Output is correct |
30 |
Correct |
15 ms |
19168 KB |
Output is correct |
31 |
Correct |
495 ms |
19204 KB |
Output is correct |
32 |
Correct |
543 ms |
19208 KB |
Output is correct |
33 |
Correct |
767 ms |
19200 KB |
Output is correct |
34 |
Correct |
280 ms |
19156 KB |
Output is correct |
35 |
Correct |
1097 ms |
19340 KB |
Output is correct |
36 |
Correct |
1551 ms |
19208 KB |
Output is correct |
37 |
Correct |
904 ms |
19324 KB |
Output is correct |
38 |
Correct |
1840 ms |
19316 KB |
Output is correct |
39 |
Correct |
2089 ms |
19204 KB |
Output is correct |
40 |
Correct |
1245 ms |
19212 KB |
Output is correct |
41 |
Correct |
110 ms |
19212 KB |
Output is correct |
42 |
Correct |
1272 ms |
19276 KB |
Output is correct |
43 |
Correct |
1254 ms |
19204 KB |
Output is correct |
44 |
Correct |
931 ms |
19204 KB |
Output is correct |
45 |
Correct |
14 ms |
19156 KB |
Output is correct |
46 |
Correct |
1147 ms |
19204 KB |
Output is correct |
47 |
Correct |
2111 ms |
19204 KB |
Output is correct |
48 |
Correct |
2918 ms |
19196 KB |
Output is correct |
49 |
Correct |
827 ms |
19284 KB |
Output is correct |
50 |
Correct |
734 ms |
19284 KB |
Output is correct |
51 |
Correct |
1966 ms |
19284 KB |
Output is correct |
52 |
Correct |
1294 ms |
19280 KB |
Output is correct |
53 |
Correct |
822 ms |
19284 KB |
Output is correct |
54 |
Correct |
943 ms |
19300 KB |
Output is correct |
55 |
Correct |
1521 ms |
19292 KB |
Output is correct |
56 |
Correct |
1473 ms |
19260 KB |
Output is correct |
57 |
Correct |
1369 ms |
19284 KB |
Output is correct |
58 |
Correct |
1452 ms |
19296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19156 KB |
Output is correct |
2 |
Correct |
13 ms |
19152 KB |
Output is correct |
3 |
Correct |
11 ms |
19196 KB |
Output is correct |
4 |
Correct |
11 ms |
19156 KB |
Output is correct |
5 |
Correct |
301 ms |
26828 KB |
Output is correct |
6 |
Correct |
292 ms |
26916 KB |
Output is correct |
7 |
Correct |
287 ms |
26956 KB |
Output is correct |
8 |
Correct |
280 ms |
26960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19204 KB |
Output is correct |
2 |
Correct |
11 ms |
19296 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
296 ms |
26988 KB |
Output is correct |
6 |
Correct |
300 ms |
27268 KB |
Output is correct |
7 |
Correct |
289 ms |
27048 KB |
Output is correct |
8 |
Correct |
307 ms |
27052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19224 KB |
Output is correct |
2 |
Correct |
13 ms |
19156 KB |
Output is correct |
3 |
Correct |
11 ms |
19156 KB |
Output is correct |
4 |
Correct |
12 ms |
19156 KB |
Output is correct |
5 |
Correct |
11 ms |
19156 KB |
Output is correct |
6 |
Correct |
12 ms |
19156 KB |
Output is correct |
7 |
Correct |
13 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19156 KB |
Output is correct |
9 |
Correct |
16 ms |
19156 KB |
Output is correct |
10 |
Correct |
15 ms |
19148 KB |
Output is correct |
11 |
Correct |
14 ms |
19156 KB |
Output is correct |
12 |
Correct |
15 ms |
19128 KB |
Output is correct |
13 |
Correct |
302 ms |
26912 KB |
Output is correct |
14 |
Correct |
302 ms |
26612 KB |
Output is correct |
15 |
Correct |
310 ms |
26920 KB |
Output is correct |
16 |
Correct |
292 ms |
26908 KB |
Output is correct |
17 |
Correct |
308 ms |
26808 KB |
Output is correct |
18 |
Correct |
291 ms |
26920 KB |
Output is correct |
19 |
Correct |
294 ms |
26784 KB |
Output is correct |
20 |
Correct |
301 ms |
26840 KB |
Output is correct |
21 |
Correct |
420 ms |
27064 KB |
Output is correct |
22 |
Correct |
347 ms |
26876 KB |
Output is correct |
23 |
Correct |
329 ms |
26936 KB |
Output is correct |
24 |
Correct |
338 ms |
27000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19156 KB |
Output is correct |
2 |
Correct |
11 ms |
19144 KB |
Output is correct |
3 |
Correct |
13 ms |
19156 KB |
Output is correct |
4 |
Correct |
11 ms |
19156 KB |
Output is correct |
5 |
Correct |
12 ms |
19156 KB |
Output is correct |
6 |
Correct |
13 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19156 KB |
Output is correct |
8 |
Correct |
12 ms |
19208 KB |
Output is correct |
9 |
Correct |
12 ms |
19156 KB |
Output is correct |
10 |
Correct |
13 ms |
19156 KB |
Output is correct |
11 |
Correct |
12 ms |
19156 KB |
Output is correct |
12 |
Correct |
12 ms |
19156 KB |
Output is correct |
13 |
Correct |
19 ms |
19156 KB |
Output is correct |
14 |
Correct |
628 ms |
19276 KB |
Output is correct |
15 |
Correct |
17 ms |
19156 KB |
Output is correct |
16 |
Correct |
14 ms |
19156 KB |
Output is correct |
17 |
Correct |
1208 ms |
19156 KB |
Output is correct |
18 |
Correct |
15 ms |
19156 KB |
Output is correct |
19 |
Correct |
15 ms |
19156 KB |
Output is correct |
20 |
Correct |
2715 ms |
19284 KB |
Output is correct |
21 |
Correct |
19 ms |
19220 KB |
Output is correct |
22 |
Correct |
20 ms |
19228 KB |
Output is correct |
23 |
Correct |
1012 ms |
19204 KB |
Output is correct |
24 |
Correct |
14 ms |
19188 KB |
Output is correct |
25 |
Correct |
13 ms |
19148 KB |
Output is correct |
26 |
Correct |
18 ms |
19336 KB |
Output is correct |
27 |
Correct |
14 ms |
19156 KB |
Output is correct |
28 |
Correct |
13 ms |
19156 KB |
Output is correct |
29 |
Correct |
16 ms |
19156 KB |
Output is correct |
30 |
Correct |
15 ms |
19168 KB |
Output is correct |
31 |
Correct |
495 ms |
19204 KB |
Output is correct |
32 |
Correct |
543 ms |
19208 KB |
Output is correct |
33 |
Correct |
767 ms |
19200 KB |
Output is correct |
34 |
Correct |
280 ms |
19156 KB |
Output is correct |
35 |
Correct |
1097 ms |
19340 KB |
Output is correct |
36 |
Correct |
1551 ms |
19208 KB |
Output is correct |
37 |
Correct |
904 ms |
19324 KB |
Output is correct |
38 |
Correct |
1840 ms |
19316 KB |
Output is correct |
39 |
Correct |
2089 ms |
19204 KB |
Output is correct |
40 |
Correct |
1245 ms |
19212 KB |
Output is correct |
41 |
Correct |
110 ms |
19212 KB |
Output is correct |
42 |
Correct |
1272 ms |
19276 KB |
Output is correct |
43 |
Correct |
1254 ms |
19204 KB |
Output is correct |
44 |
Correct |
931 ms |
19204 KB |
Output is correct |
45 |
Correct |
14 ms |
19156 KB |
Output is correct |
46 |
Correct |
1147 ms |
19204 KB |
Output is correct |
47 |
Correct |
2111 ms |
19204 KB |
Output is correct |
48 |
Correct |
2918 ms |
19196 KB |
Output is correct |
49 |
Correct |
827 ms |
19284 KB |
Output is correct |
50 |
Correct |
734 ms |
19284 KB |
Output is correct |
51 |
Correct |
1966 ms |
19284 KB |
Output is correct |
52 |
Correct |
1294 ms |
19280 KB |
Output is correct |
53 |
Correct |
822 ms |
19284 KB |
Output is correct |
54 |
Correct |
943 ms |
19300 KB |
Output is correct |
55 |
Correct |
1521 ms |
19292 KB |
Output is correct |
56 |
Correct |
1473 ms |
19260 KB |
Output is correct |
57 |
Correct |
1369 ms |
19284 KB |
Output is correct |
58 |
Correct |
1452 ms |
19296 KB |
Output is correct |
59 |
Correct |
303 ms |
34132 KB |
Output is correct |
60 |
Correct |
344 ms |
34144 KB |
Output is correct |
61 |
Correct |
316 ms |
34140 KB |
Output is correct |
62 |
Correct |
296 ms |
34132 KB |
Output is correct |
63 |
Correct |
308 ms |
34160 KB |
Output is correct |
64 |
Correct |
304 ms |
34272 KB |
Output is correct |
65 |
Correct |
302 ms |
34128 KB |
Output is correct |
66 |
Correct |
317 ms |
34284 KB |
Output is correct |
67 |
Correct |
375 ms |
34340 KB |
Output is correct |
68 |
Correct |
346 ms |
34156 KB |
Output is correct |
69 |
Correct |
327 ms |
34376 KB |
Output is correct |
70 |
Correct |
337 ms |
34112 KB |
Output is correct |
71 |
Correct |
710 ms |
34308 KB |
Output is correct |
72 |
Execution timed out |
3016 ms |
33992 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |