#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();
}
}
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 |
2 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 |
460 KB |
Output is correct |
2 |
Correct |
12 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
28 ms |
588 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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Execution timed out |
3094 ms |
580 KB |
Time limit exceeded |
9 |
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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 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 |
588 KB |
Output is correct |
8 |
Execution timed out |
3094 ms |
588 KB |
Time limit exceeded |
9 |
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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
99 ms |
6724 KB |
Output is correct |
6 |
Correct |
95 ms |
6888 KB |
Output is correct |
7 |
Correct |
107 ms |
6768 KB |
Output is correct |
8 |
Correct |
95 ms |
6768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
12 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
28 ms |
588 KB |
Output is correct |
5 |
Correct |
108 ms |
15152 KB |
Output is correct |
6 |
Execution timed out |
3072 ms |
17836 KB |
Time limit exceeded |
7 |
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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Execution timed out |
3094 ms |
580 KB |
Time limit exceeded |
9 |
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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 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 |
588 KB |
Output is correct |
8 |
Execution timed out |
3094 ms |
588 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |