#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define K 4
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long xxl[N], xxr[N], yyl[N], yyr[N], xx[K], yy[K]; int n, k;
int pierced(int i, int h_) {
int h;
for (h = 0; h < h_; h++)
if (xxl[i] <= xx[h] && xx[h] <= xxr[i] && yyl[i] <= yy[h] && yy[h] <= yyr[i])
return 1;
return 0;
}
void solve(int h_) {
int h, i;
long long xl, xr, yl, yr;
xl = INF, xr = -1, yl = INF, yr = -1;
for (i = 0; i < n; i++)
if (!pierced(i, h_))
xl = min(xl, xxr[i]), xr = max(xr, xxl[i]), yl = min(yl, yyr[i]), yr = max(yr, yyl[i]);
if (xl == INF) {
for (h = h_; h < k; h++)
xx[h] = 1, yy[h] = 1;
for (h = 0; h < k; h++)
printf("%lld %lld\n", xx[h], yy[h]);
exit(0);
} else if (h_ < k) {
xx[h_] = xl, yy[h_] = yl, solve(h_ + 1);
xx[h_] = xl, yy[h_] = yr, solve(h_ + 1);
xx[h_] = xr, yy[h_] = yl, solve(h_ + 1);
xx[h_] = xr, yy[h_] = yr, solve(h_ + 1);
}
}
long long ll[N], rr[N]; int ii0[N], ii1[N], ii2[N], n0, n1, n2; long long xl, xr, yl, yr, z1, z2, z3, z4;
long long idx(long long x, long long y) {
if (y == yl)
return x - xl;
if (x == xr)
return z1 + y - yl;
if (y == yr)
return z2 + xr - x;
if (x == xl)
return z3 + yr - y;
return -1;
}
void get_min_max(int h_, long long *xl_, long long *xr_, long long *yl_, long long *yr_) {
int h, i, i_, pierced;
*xl_ = INF, *xr_ = -1, *yl_ = INF, *yr_ = -1;
for (i = 0; i < n0; i++) {
i_ = ii0[i], pierced = 0;
for (h = 0; h < h_; h++) {
long long z = idx(xx[h], yy[h]);
if (ll[i_] <= z && z <= rr[i_] || ll[i_] <= z4 + z && z4 + z <= rr[i_]) {
pierced = 1;
break;
}
}
if (!pierced)
*xl_ = min(*xl_, xxr[i_]), *xr_ = max(*xr_, xxl[i_]), *yl_ = min(*yl_, yyr[i_]), *yr_ = max(*yr_, yyl[i_]);
}
for (i = 0; i < n1; i++) {
i_ = ii1[i], pierced = 0;
for (h = 0; h < h_; h++)
if (ll[i_] <= xx[h] && xx[h] <= rr[i_]) {
pierced = 1;
break;
}
if (!pierced)
*xl_ = min(*xl_, xxr[i_]), *xr_ = max(*xr_, xxl[i_]), *yl_ = min(*yl_, yyr[i_]), *yr_ = max(*yr_, yyl[i_]);
}
for (i = 0; i < n2; i++) {
i_ = ii2[i], pierced = 0;
for (h = 0; h < h_; h++)
if (ll[i_] <= yy[h] && yy[h] <= rr[i_]) {
pierced = 1;
break;
}
if (!pierced)
*xl_ = min(*xl_, xxr[i_]), *xr_ = max(*xr_, xxl[i_]), *yl_ = min(*yl_, yyr[i_]), *yr_ = max(*yr_, yyl[i_]);
}
}
void solve_(int h_) {
int h, i;
long long xl_, yl_, xr_, yr_;
if (h_ > 0 && idx(xx[h_ - 1], yy[h_ - 1]) == -1)
return;
get_min_max(h_, &xl_, &xr_, &yl_, &yr_);
if (xl_ == INF) {
for (h = h_; h < k; h++)
xx[h] = 1, yy[h] = 1;
for (h = 0; h < k; h++)
printf("%lld %lld\n", xx[h], yy[h]);
exit(0);
} else if (h_ == 0) {
xx[h_] = xl_;
for (i = 0; i < n; i++)
yy[h_] = yyl[i], solve_(h_ + 1);
} else if (h_ < k) {
xx[h_] = xl_, yy[h_] = yl_, solve_(h_ + 1);
xx[h_] = xl_, yy[h_] = yr_, solve_(h_ + 1);
xx[h_] = xr_, yy[h_] = yl_, solve_(h_ + 1);
xx[h_] = xr_, yy[h_] = yr_, solve_(h_ + 1);
}
}
int main() {
int i;
long long l, r;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++)
scanf("%lld%lld%lld%lld", &xxl[i], &yyl[i], &xxr[i], &yyr[i]);
solve(0);
xl = INF, xr = -1, yl = INF, yr = -1;
for (i = 0; i < n; i++)
xl = min(xl, xxr[i]), xr = max(xr, xxl[i]), yl = min(yl, yyr[i]), yr = max(yr, yyl[i]);
assert(k == 4 && xl < xr && yl < yr);
z1 = xr - xl, z2 = z1 + yr - yl, z3 = z2 + xr - xl, z4 = z3 + yr - yl;
for (i = 0; i < n; i++)
xxl[i] = max(xxl[i], xl), xxr[i] = min(xxr[i], xr), yyl[i] = max(yyl[i], yl), yyr[i] = min(yyr[i], yr);
for (i = 0; i < n; i++)
if (xl < xxl[i] && xxr[i] < xr && yyl[i] == yl && yyr[i] == yr)
ll[i] = xxl[i], rr[i] = xxr[i], ii1[n1++] = i;
else if (yl < yyl[i] && yyr[i] < yr && xxl[i] == xl && xxr[i] == xr)
ll[i] = yyl[i], rr[i] = yyr[i], ii2[n2++] = i;
else {
l = INF, r = -1;
if (yyl[i] == yl)
l = min(l, xxl[i] - xl), r = max(r, xxr[i] - xl);
if (xxr[i] == xr)
l = min(l, z1 + yyl[i] - yl), r = max(r, z1 + yyr[i] - yl);
if (xxl[i] == xl && yyl[i] == yl)
l += z4, r += z4;
if (yyr[i] == yr)
l = min(l, z2 + xr - xxr[i]), r = max(r, z2 + xr - xxl[i]);
if (xxl[i] == xl)
l = min(l, z3 + yr - yyr[i]), r = max(r, z3 + yr - yyl[i]);
if (l >= z4)
l -= z4, r -= z4;
ll[i] = l, rr[i] = r, ii0[n0++] = i;
}
solve_(0);
return 0;
}
Compilation message
hamburg.c: In function 'get_min_max':
hamburg.c:68:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
68 | if (ll[i_] <= z && z <= rr[i_] || ll[i_] <= z4 + z && z4 + z <= rr[i_]) {
| ~~~~~~~~~~~~^~~~~~~~~~~~~~
hamburg.c: In function 'main':
hamburg.c:127:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
hamburg.c:129:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | scanf("%lld%lld%lld%lld", &xxl[i], &yyl[i], &xxr[i], &yyr[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
380 KB |
Output is correct |
14 |
Correct |
737 ms |
420 KB |
Output is correct |
15 |
Correct |
9 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
340 KB |
Output is correct |
17 |
Correct |
665 ms |
424 KB |
Output is correct |
18 |
Correct |
6 ms |
380 KB |
Output is correct |
19 |
Correct |
8 ms |
340 KB |
Output is correct |
20 |
Correct |
1505 ms |
420 KB |
Output is correct |
21 |
Correct |
9 ms |
340 KB |
Output is correct |
22 |
Correct |
7 ms |
340 KB |
Output is correct |
23 |
Correct |
138 ms |
420 KB |
Output is correct |
24 |
Correct |
8 ms |
340 KB |
Output is correct |
25 |
Correct |
4 ms |
340 KB |
Output is correct |
26 |
Correct |
4 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
4 ms |
356 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
588 ms |
416 KB |
Output is correct |
32 |
Correct |
38 ms |
340 KB |
Output is correct |
33 |
Correct |
63 ms |
416 KB |
Output is correct |
34 |
Correct |
44 ms |
436 KB |
Output is correct |
35 |
Correct |
324 ms |
416 KB |
Output is correct |
36 |
Correct |
645 ms |
420 KB |
Output is correct |
37 |
Correct |
2943 ms |
464 KB |
Output is correct |
38 |
Correct |
395 ms |
340 KB |
Output is correct |
39 |
Correct |
992 ms |
416 KB |
Output is correct |
40 |
Correct |
1462 ms |
420 KB |
Output is correct |
41 |
Correct |
1471 ms |
420 KB |
Output is correct |
42 |
Correct |
748 ms |
420 KB |
Output is correct |
43 |
Correct |
251 ms |
340 KB |
Output is correct |
44 |
Correct |
1381 ms |
460 KB |
Output is correct |
45 |
Correct |
6 ms |
340 KB |
Output is correct |
46 |
Correct |
1720 ms |
420 KB |
Output is correct |
47 |
Correct |
418 ms |
432 KB |
Output is correct |
48 |
Correct |
214 ms |
420 KB |
Output is correct |
49 |
Correct |
816 ms |
420 KB |
Output is correct |
50 |
Correct |
322 ms |
420 KB |
Output is correct |
51 |
Correct |
2268 ms |
432 KB |
Output is correct |
52 |
Correct |
1106 ms |
424 KB |
Output is correct |
53 |
Correct |
515 ms |
420 KB |
Output is correct |
54 |
Correct |
331 ms |
420 KB |
Output is correct |
55 |
Correct |
243 ms |
420 KB |
Output is correct |
56 |
Correct |
802 ms |
340 KB |
Output is correct |
57 |
Correct |
459 ms |
412 KB |
Output is correct |
58 |
Correct |
120 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
79 ms |
6472 KB |
Output is correct |
6 |
Correct |
91 ms |
6476 KB |
Output is correct |
7 |
Correct |
80 ms |
6476 KB |
Output is correct |
8 |
Correct |
85 ms |
6624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
81 ms |
6532 KB |
Output is correct |
6 |
Correct |
88 ms |
6532 KB |
Output is correct |
7 |
Correct |
81 ms |
6476 KB |
Output is correct |
8 |
Correct |
93 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
83 ms |
6528 KB |
Output is correct |
14 |
Correct |
84 ms |
6496 KB |
Output is correct |
15 |
Correct |
81 ms |
6512 KB |
Output is correct |
16 |
Correct |
82 ms |
6524 KB |
Output is correct |
17 |
Correct |
84 ms |
6456 KB |
Output is correct |
18 |
Correct |
81 ms |
6476 KB |
Output is correct |
19 |
Correct |
85 ms |
6472 KB |
Output is correct |
20 |
Correct |
96 ms |
6476 KB |
Output is correct |
21 |
Correct |
244 ms |
6448 KB |
Output is correct |
22 |
Correct |
166 ms |
6476 KB |
Output is correct |
23 |
Correct |
133 ms |
6524 KB |
Output is correct |
24 |
Correct |
150 ms |
6604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
380 KB |
Output is correct |
14 |
Correct |
737 ms |
420 KB |
Output is correct |
15 |
Correct |
9 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
340 KB |
Output is correct |
17 |
Correct |
665 ms |
424 KB |
Output is correct |
18 |
Correct |
6 ms |
380 KB |
Output is correct |
19 |
Correct |
8 ms |
340 KB |
Output is correct |
20 |
Correct |
1505 ms |
420 KB |
Output is correct |
21 |
Correct |
9 ms |
340 KB |
Output is correct |
22 |
Correct |
7 ms |
340 KB |
Output is correct |
23 |
Correct |
138 ms |
420 KB |
Output is correct |
24 |
Correct |
8 ms |
340 KB |
Output is correct |
25 |
Correct |
4 ms |
340 KB |
Output is correct |
26 |
Correct |
4 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
4 ms |
356 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
588 ms |
416 KB |
Output is correct |
32 |
Correct |
38 ms |
340 KB |
Output is correct |
33 |
Correct |
63 ms |
416 KB |
Output is correct |
34 |
Correct |
44 ms |
436 KB |
Output is correct |
35 |
Correct |
324 ms |
416 KB |
Output is correct |
36 |
Correct |
645 ms |
420 KB |
Output is correct |
37 |
Correct |
2943 ms |
464 KB |
Output is correct |
38 |
Correct |
395 ms |
340 KB |
Output is correct |
39 |
Correct |
992 ms |
416 KB |
Output is correct |
40 |
Correct |
1462 ms |
420 KB |
Output is correct |
41 |
Correct |
1471 ms |
420 KB |
Output is correct |
42 |
Correct |
748 ms |
420 KB |
Output is correct |
43 |
Correct |
251 ms |
340 KB |
Output is correct |
44 |
Correct |
1381 ms |
460 KB |
Output is correct |
45 |
Correct |
6 ms |
340 KB |
Output is correct |
46 |
Correct |
1720 ms |
420 KB |
Output is correct |
47 |
Correct |
418 ms |
432 KB |
Output is correct |
48 |
Correct |
214 ms |
420 KB |
Output is correct |
49 |
Correct |
816 ms |
420 KB |
Output is correct |
50 |
Correct |
322 ms |
420 KB |
Output is correct |
51 |
Correct |
2268 ms |
432 KB |
Output is correct |
52 |
Correct |
1106 ms |
424 KB |
Output is correct |
53 |
Correct |
515 ms |
420 KB |
Output is correct |
54 |
Correct |
331 ms |
420 KB |
Output is correct |
55 |
Correct |
243 ms |
420 KB |
Output is correct |
56 |
Correct |
802 ms |
340 KB |
Output is correct |
57 |
Correct |
459 ms |
412 KB |
Output is correct |
58 |
Correct |
120 ms |
340 KB |
Output is correct |
59 |
Correct |
90 ms |
6492 KB |
Output is correct |
60 |
Correct |
88 ms |
6528 KB |
Output is correct |
61 |
Correct |
86 ms |
6484 KB |
Output is correct |
62 |
Correct |
84 ms |
6472 KB |
Output is correct |
63 |
Correct |
84 ms |
6420 KB |
Output is correct |
64 |
Correct |
83 ms |
6476 KB |
Output is correct |
65 |
Correct |
88 ms |
6456 KB |
Output is correct |
66 |
Correct |
99 ms |
6476 KB |
Output is correct |
67 |
Correct |
263 ms |
6476 KB |
Output is correct |
68 |
Correct |
218 ms |
6492 KB |
Output is correct |
69 |
Correct |
142 ms |
6528 KB |
Output is correct |
70 |
Correct |
168 ms |
6516 KB |
Output is correct |
71 |
Correct |
1028 ms |
6596 KB |
Output is correct |
72 |
Execution timed out |
3078 ms |
10372 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |