#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
struct Rect {
int l, d, r, u;
bool operator()(int x, int y) {
return l <= x && x <= r && d <= y && y <= u;
}
};
vector<Rect> filter(vector<Rect> rects, int x, int y) {
vector<Rect> res;
for (auto r : rects) {
if (!r(x, y)) {
res.push_back(r);
}
}
return res;
}
void out(int k, vector<pair<int, int>> points) {
for (int i = 0; i < k; ++i) {
auto [x, y] = points[min(i, (int)points.size() - 1)];
cout << x << " " << y << "\n";
}
exit(0);
}
void rec(vector<Rect> rects, int k, vector<pair<int, int>> points) {
for (auto [x, y] : points) {
rects = filter(rects, x, y);
}
if (rects.empty()) {
out(k, points);
}
if ((int)points.size() == k) {
return;
}
int maxl = 1, minr = INF, maxd = 1, minu = INF;
for (auto r : rects) {
maxl = max(maxl, r.l);
minr = min(minr, r.r);
maxd = max(maxd, r.d);
minu = min(minu, r.u);
}
if (maxd <= minu) {
sort(rects.begin(), rects.end(), [&](Rect r1, Rect r2) {
return r1.r < r2.r;
});
for (auto r : rects) {
bool ok = false;
for (auto [x, y] : points) {
ok |= r(x, y);
}
if (!ok) {
if ((int)points.size() == k) {
return;
}
points.push_back({r.r, maxd});
}
}
out(k, points);
}
if (k == 1) {
return;
}
if (maxl <= minr) {
sort(rects.begin(), rects.end(), [&](Rect r1, Rect r2) {
return r1.u < r2.u;
});
for (auto r : rects) {
bool ok = false;
for (auto [x, y] : points) {
ok |= r(x, y);
}
if (!ok) {
if ((int)points.size() == k) {
return;
}
points.push_back({maxl, r.u});
}
}
out(k, points);
}
for (int x : {maxl, minr}) {
for (int y : {maxd, minu}) {
points.push_back({x, y});
rec(rects, k, points);
points.pop_back();
}
}
if (k == 4 && points.empty()) {
for (auto r : rects) {
points.push_back({maxl, r.d});
rec(rects, k, points);
points.pop_back();
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<Rect> rects(n);
for (auto &r : rects) {
cin >> r.l >> r.d >> r.r >> r.u;
}
vector<pair<int, int>> points;
rec(rects, k, points);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
580 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
8 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
588 KB |
Output is correct |
11 |
Correct |
8 ms |
668 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
743 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
588 KB |
Output is correct |
17 |
Correct |
1631 ms |
808 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
1159 ms |
828 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
588 KB |
Output is correct |
23 |
Correct |
315 ms |
704 KB |
Output is correct |
24 |
Correct |
5 ms |
688 KB |
Output is correct |
25 |
Correct |
6 ms |
696 KB |
Output is correct |
26 |
Correct |
7 ms |
684 KB |
Output is correct |
27 |
Correct |
6 ms |
696 KB |
Output is correct |
28 |
Correct |
5 ms |
576 KB |
Output is correct |
29 |
Correct |
5 ms |
696 KB |
Output is correct |
30 |
Correct |
4 ms |
588 KB |
Output is correct |
31 |
Correct |
807 ms |
668 KB |
Output is correct |
32 |
Correct |
75 ms |
672 KB |
Output is correct |
33 |
Correct |
1095 ms |
716 KB |
Output is correct |
34 |
Correct |
168 ms |
824 KB |
Output is correct |
35 |
Execution timed out |
3023 ms |
792 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
88 ms |
6504 KB |
Output is correct |
6 |
Correct |
87 ms |
6520 KB |
Output is correct |
7 |
Correct |
85 ms |
6596 KB |
Output is correct |
8 |
Correct |
86 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
92 ms |
14960 KB |
Output is correct |
6 |
Correct |
96 ms |
17404 KB |
Output is correct |
7 |
Correct |
93 ms |
15168 KB |
Output is correct |
8 |
Correct |
115 ms |
22472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
580 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
94 ms |
6796 KB |
Output is correct |
14 |
Correct |
87 ms |
6824 KB |
Output is correct |
15 |
Correct |
107 ms |
6760 KB |
Output is correct |
16 |
Correct |
87 ms |
6704 KB |
Output is correct |
17 |
Correct |
91 ms |
6824 KB |
Output is correct |
18 |
Correct |
89 ms |
6724 KB |
Output is correct |
19 |
Correct |
88 ms |
19172 KB |
Output is correct |
20 |
Correct |
349 ms |
27852 KB |
Output is correct |
21 |
Correct |
99 ms |
19336 KB |
Output is correct |
22 |
Correct |
173 ms |
26212 KB |
Output is correct |
23 |
Correct |
225 ms |
25780 KB |
Output is correct |
24 |
Correct |
193 ms |
25064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
8 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
588 KB |
Output is correct |
11 |
Correct |
8 ms |
668 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
743 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
588 KB |
Output is correct |
17 |
Correct |
1631 ms |
808 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
1159 ms |
828 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
588 KB |
Output is correct |
23 |
Correct |
315 ms |
704 KB |
Output is correct |
24 |
Correct |
5 ms |
688 KB |
Output is correct |
25 |
Correct |
6 ms |
696 KB |
Output is correct |
26 |
Correct |
7 ms |
684 KB |
Output is correct |
27 |
Correct |
6 ms |
696 KB |
Output is correct |
28 |
Correct |
5 ms |
576 KB |
Output is correct |
29 |
Correct |
5 ms |
696 KB |
Output is correct |
30 |
Correct |
4 ms |
588 KB |
Output is correct |
31 |
Correct |
807 ms |
668 KB |
Output is correct |
32 |
Correct |
75 ms |
672 KB |
Output is correct |
33 |
Correct |
1095 ms |
716 KB |
Output is correct |
34 |
Correct |
168 ms |
824 KB |
Output is correct |
35 |
Execution timed out |
3023 ms |
792 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |