#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
using namespace std;
int K, C[N_];
struct Rect {
int bx, by, ex, ey;
};
vector<Rect>w;
struct point {
int x, y;
}U[5];
bool Inside(Rect a, point b) {
return a.bx <= b.x&&b.x <= a.ex&&a.by <= b.y&&b.y <= a.ey;
}
void Print(point a) {
printf("%d %d\n", a.x, a.y);
}
void Do(int pv, int n) {
int i;
if (pv) {
for (i = 0; i < n; i++)if (Inside(w[i], U[pv - 1]))C[i]++;
}
if (pv == K) {
for (i = 0; i < n; i++) if (!C[i])break;
if (i >= n) {
for (i = 0; i < K; i++)Print(U[i]);
exit(0);
}
for (i = 0; i < n; i++)if (Inside(w[i], U[pv - 1]))C[i]--;
return;
}
int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = 0; i < n; i++) {
if (C[i])continue;
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
}
if (pv == K - 1) {
if (Ax <= Bx && Ay <= By) {
U[pv] = { Ax,Ay };
Do(pv + 1, n);
}
else {
if (pv) for (i = 1; i <= n; i++)if (Inside(w[i], U[pv - 1]))C[i]--;
return;
}
}
int yy1 = 0, yy2 = 1e9, yy3 = 0, yy4 = 1e9;
int xx1 = 0, xx2 = 1e9, xx3 = 0, xx4 = 1e9;
for (i = 0; i < n; i++) {
if (C[i])continue;
if (w[i].bx <= Bx) {
yy1 = max(yy1, w[i].by);
yy2 = min(yy2, w[i].ey);
}
if (w[i].ex >= Ax) {
yy3 = max(yy3, w[i].by);
yy4 = min(yy4, w[i].ey);
}
if (w[i].by <= By) {
xx1 = max(xx1, w[i].bx);
xx2 = min(xx2, w[i].ex);
}
if (w[i].ey >= Ay) {
xx3 = max(xx3, w[i].bx);
xx4 = min(xx4, w[i].ex);
}
}
U[pv] = { Bx, yy1 };
Do(pv + 1, n);
U[pv] = { Bx, yy2 };
Do(pv + 1, n);
U[pv] = { Ax, yy3 };
Do(pv + 1, n);
U[pv] = { Ax, yy4 };
Do(pv + 1, n);
if (pv) {
for (i = 0; i < n; i++)if (Inside(w[i], U[pv - 1]))C[i]--;
}
}
int main() {
int i, n;
scanf("%d%d", &n, &K);
w.resize(n);
for (i = 0; i < n; i++) {
scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
}
Do(0, n);
std::sort(w.begin(),w.end(), [](auto const& l, auto const& r) {
return l.bx < r.bx;
});
int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = n-1; i >= 0; i--) {
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
if (Ax > Bx || Ay > By)break;
}
int pv = i; Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = n-1; i > pv; i--) {
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
}
U[0] = { Ax,Ay };
for (i = 0; i < n; i++)if (Inside(w[i], U[0]))C[i]++;
Do(1, n);
for (i = 0; i < n; i++)C[i] = 0;
std::sort(w.begin(), w.end(), [](auto const& l, auto const& r) {
return l.ex > r.ex;
});
Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = n - 1; i >= 0; i--) {
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
if (Ax > Bx || Ay > By)break;
}
pv = i; Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = n - 1; i > pv; i--) {
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
}
U[0] = { Ax,Ay };
for (i = 0; i < n; i++)if (Inside(w[i], U[0]))C[i]++;
Do(1, n);
for (i = 0; i < n; i++)C[i] = 0;
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
87 | scanf("%d%d", &n, &K);
| ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
90 | scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
288 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
288 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Incorrect |
6 ms |
384 KB |
Unexpected end of file - int32 expected |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
139 ms |
4264 KB |
Output is correct |
6 |
Correct |
154 ms |
4260 KB |
Output is correct |
7 |
Correct |
145 ms |
4268 KB |
Output is correct |
8 |
Correct |
131 ms |
4256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
288 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
181 ms |
4356 KB |
Output is correct |
6 |
Correct |
166 ms |
4216 KB |
Output is correct |
7 |
Correct |
178 ms |
4256 KB |
Output is correct |
8 |
Correct |
170 ms |
4264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
288 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
177 ms |
4256 KB |
Output is correct |
14 |
Correct |
158 ms |
4264 KB |
Output is correct |
15 |
Correct |
142 ms |
4344 KB |
Output is correct |
16 |
Correct |
140 ms |
4196 KB |
Output is correct |
17 |
Correct |
178 ms |
4216 KB |
Output is correct |
18 |
Correct |
210 ms |
4272 KB |
Output is correct |
19 |
Correct |
172 ms |
4216 KB |
Output is correct |
20 |
Correct |
168 ms |
4216 KB |
Output is correct |
21 |
Correct |
176 ms |
4280 KB |
Output is correct |
22 |
Correct |
228 ms |
4344 KB |
Output is correct |
23 |
Correct |
146 ms |
4344 KB |
Output is correct |
24 |
Correct |
148 ms |
4264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Incorrect |
6 ms |
384 KB |
Unexpected end of file - int32 expected |
21 |
Halted |
0 ms |
0 KB |
- |