#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1'000'000'000;
struct Point {
int x, y;
};
ostream &operator<<(ostream &stream, const Point &p) {
stream << p.x << " " << p.y;
return stream;
}
struct Segment {
int l, r;
Segment() {}
Segment(int l, int r) : l(l), r(r) {}
};
const Segment SEG_ALL = {1, INF};
void self_intersect(Segment &a, const Segment &b) {
a.l = max(a.l, b.l);
a.r = min(a.r, b.r);
}
Segment intersect(Segment a, const Segment &b) {
self_intersect(a, b);
return a;
}
bool inside(int x, const Segment &s) {
return x >= s.l && x <= s.r;
}
struct Rectangle {
Segment x, y;
Rectangle() {}
Rectangle(const Segment &x, const Segment &y) : x(x), y(y) {}
};
const Rectangle RECT_ALL = {SEG_ALL, SEG_ALL};
istream &operator>>(istream &stream, Rectangle &r) {
stream >> r.x.l >> r.y.l >> r.x.r >> r.y.r;
return stream;
}
void self_intersect(Rectangle &a, const Rectangle &b) {
self_intersect(a.x, b.x);
self_intersect(a.y, b.y);
}
Rectangle intersect(Rectangle a, const Rectangle &b) {
self_intersect(a, b);
return a;
}
bool inside(const Point &p, const Rectangle &r) {
return inside(p.x, r.x) && inside(p.y, r.y);
}
int k;
void solve(const vector<Rectangle> &rectangles, const vector<Point> &points) {
if ((int)points.size() == k) {
if (rectangles.empty()) {
for (int i = 0; i < k; ++i) {
cout << points[i] << "\n";
}
exit(0);
}
return;
}
Rectangle intersection = RECT_ALL;
for (const auto &rect : rectangles) {
self_intersect(intersection, rect);
}
for (int x : {intersection.x.l, intersection.x.r}) {
for (int y : {intersection.y.l, intersection.y.r}) {
Point p = {x, y};
auto new_points = points;
new_points.push_back(p);
vector<Rectangle> new_rectangles;
for (const auto &rect : rectangles) {
if (!inside(p, rect)) {
new_rectangles.push_back(rect);
}
}
solve(new_rectangles, new_points);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n >> k;
vector<Rectangle> rectangles(n);
for (auto &rect : rectangles) {
cin >> rect;
}
solve(rectangles, vector<Point>{});
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
392 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
456 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
408 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Incorrect |
3 ms |
588 KB |
Unexpected end of file - int32 expected |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
81 ms |
3664 KB |
Output is correct |
6 |
Correct |
72 ms |
3652 KB |
Output is correct |
7 |
Correct |
78 ms |
3644 KB |
Output is correct |
8 |
Correct |
83 ms |
3760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
392 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
91 ms |
5804 KB |
Output is correct |
6 |
Correct |
81 ms |
8508 KB |
Output is correct |
7 |
Correct |
97 ms |
6008 KB |
Output is correct |
8 |
Correct |
86 ms |
12216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
456 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
96 ms |
7116 KB |
Output is correct |
14 |
Correct |
97 ms |
6588 KB |
Output is correct |
15 |
Correct |
87 ms |
7484 KB |
Output is correct |
16 |
Correct |
76 ms |
5996 KB |
Output is correct |
17 |
Correct |
82 ms |
6112 KB |
Output is correct |
18 |
Correct |
85 ms |
5128 KB |
Output is correct |
19 |
Correct |
85 ms |
8036 KB |
Output is correct |
20 |
Correct |
179 ms |
15252 KB |
Output is correct |
21 |
Correct |
123 ms |
9036 KB |
Output is correct |
22 |
Correct |
103 ms |
15032 KB |
Output is correct |
23 |
Correct |
137 ms |
14900 KB |
Output is correct |
24 |
Correct |
121 ms |
14344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
408 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Incorrect |
3 ms |
588 KB |
Unexpected end of file - int32 expected |
15 |
Halted |
0 ms |
0 KB |
- |