// M
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
struct Data {int a, b, c, d;};
int n, k, M[N];;
Data A[N];
mt19937 Rnd(time(0));
inline Data Merge(Data X, Data Y)
{
Data R;
R.a = max(X.a, Y.a);
R.b = max(X.b, Y.b);
R.c = min(X.c, Y.c);
R.d = min(X.d, Y.d);
return R;
}
inline bool OK(Data X)
{
return (X.a <= X.c && X.b <= X.d);
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i ++)
scanf("%d%d%d%d", &A[i].a, &A[i].b, &A[i].c, &A[i].d);
vector < int > Priority;
while (true)
{
// May God help us ...
vector < int > P;
memset(M, 0, sizeof(M));
for (int i : Priority)
M[i] = 1, P.push_back(i);
shuffle(P.begin(), P.end(), Rnd);
for (int i = 1; i <= n; i ++)
if (!M[i]) P.push_back(i);
shuffle(P.begin() + (int)Priority.size(), P.end(), Rnd);
Priority.clear();
Data F[4];
for (int j = 0; j < k; j ++)
F[j].a = F[j].b = 0, F[j].c = F[j].d = 1e9 + 9;
for (int i : P)
{
bool Fail = 1;
for (int j = 0; j < k && Fail; j ++)
if (OK(Merge(A[i], F[j])))
F[j] = Merge(A[i], F[j]), Fail = 0;
if (Fail)
Priority.push_back(i);
}
if (!Priority.size())
{
for (int j = 0; j < k; j ++)
printf("%d %d\n", F[j].a, F[j].b);
return 0;
}
}
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
24 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:26:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%d%d%d%d", &A[i].a, &A[i].b, &A[i].c, &A[i].d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
2 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1152 KB |
Output is correct |
10 |
Correct |
2 ms |
1152 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
4 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
4 ms |
1184 KB |
Output is correct |
10 |
Correct |
12 ms |
1152 KB |
Output is correct |
11 |
Correct |
6 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
12 ms |
1152 KB |
Output is correct |
14 |
Correct |
10 ms |
1152 KB |
Output is correct |
15 |
Correct |
8 ms |
1152 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
6 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
4 ms |
1152 KB |
Output is correct |
21 |
Correct |
6 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
3 ms |
1152 KB |
Output is correct |
27 |
Correct |
3 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1152 KB |
Output is correct |
29 |
Correct |
2 ms |
1152 KB |
Output is correct |
30 |
Correct |
4 ms |
1152 KB |
Output is correct |
31 |
Correct |
4 ms |
1152 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
6 ms |
1152 KB |
Output is correct |
34 |
Correct |
3 ms |
1152 KB |
Output is correct |
35 |
Correct |
4 ms |
1152 KB |
Output is correct |
36 |
Correct |
7 ms |
1152 KB |
Output is correct |
37 |
Correct |
3 ms |
1152 KB |
Output is correct |
38 |
Correct |
2 ms |
1152 KB |
Output is correct |
39 |
Correct |
3 ms |
1152 KB |
Output is correct |
40 |
Correct |
3 ms |
1152 KB |
Output is correct |
41 |
Correct |
5 ms |
1152 KB |
Output is correct |
42 |
Correct |
3 ms |
1152 KB |
Output is correct |
43 |
Correct |
4 ms |
1152 KB |
Output is correct |
44 |
Correct |
4 ms |
1152 KB |
Output is correct |
45 |
Correct |
4 ms |
1152 KB |
Output is correct |
46 |
Correct |
3 ms |
1152 KB |
Output is correct |
47 |
Correct |
3 ms |
1152 KB |
Output is correct |
48 |
Correct |
3 ms |
1152 KB |
Output is correct |
49 |
Correct |
3 ms |
1152 KB |
Output is correct |
50 |
Correct |
4 ms |
1152 KB |
Output is correct |
51 |
Correct |
5 ms |
1152 KB |
Output is correct |
52 |
Correct |
6 ms |
1152 KB |
Output is correct |
53 |
Correct |
3 ms |
1152 KB |
Output is correct |
54 |
Correct |
3 ms |
1152 KB |
Output is correct |
55 |
Correct |
4 ms |
1152 KB |
Output is correct |
56 |
Correct |
2 ms |
1152 KB |
Output is correct |
57 |
Correct |
3 ms |
1152 KB |
Output is correct |
58 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
152 ms |
5488 KB |
Output is correct |
6 |
Correct |
143 ms |
5360 KB |
Output is correct |
7 |
Correct |
149 ms |
5480 KB |
Output is correct |
8 |
Correct |
151 ms |
5488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
159 ms |
6108 KB |
Output is correct |
6 |
Correct |
154 ms |
6108 KB |
Output is correct |
7 |
Correct |
164 ms |
6108 KB |
Output is correct |
8 |
Correct |
161 ms |
5360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
2 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1152 KB |
Output is correct |
10 |
Correct |
2 ms |
1152 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
165 ms |
6108 KB |
Output is correct |
14 |
Correct |
163 ms |
6108 KB |
Output is correct |
15 |
Correct |
203 ms |
6204 KB |
Output is correct |
16 |
Correct |
158 ms |
6108 KB |
Output is correct |
17 |
Correct |
162 ms |
6236 KB |
Output is correct |
18 |
Correct |
153 ms |
6108 KB |
Output is correct |
19 |
Correct |
410 ms |
6220 KB |
Output is correct |
20 |
Correct |
161 ms |
6236 KB |
Output is correct |
21 |
Correct |
181 ms |
6204 KB |
Output is correct |
22 |
Correct |
174 ms |
6136 KB |
Output is correct |
23 |
Correct |
188 ms |
6476 KB |
Output is correct |
24 |
Correct |
160 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
4 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
4 ms |
1184 KB |
Output is correct |
10 |
Correct |
12 ms |
1152 KB |
Output is correct |
11 |
Correct |
6 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
12 ms |
1152 KB |
Output is correct |
14 |
Correct |
10 ms |
1152 KB |
Output is correct |
15 |
Correct |
8 ms |
1152 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
6 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
4 ms |
1152 KB |
Output is correct |
21 |
Correct |
6 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
3 ms |
1152 KB |
Output is correct |
27 |
Correct |
3 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1152 KB |
Output is correct |
29 |
Correct |
2 ms |
1152 KB |
Output is correct |
30 |
Correct |
4 ms |
1152 KB |
Output is correct |
31 |
Correct |
4 ms |
1152 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
6 ms |
1152 KB |
Output is correct |
34 |
Correct |
3 ms |
1152 KB |
Output is correct |
35 |
Correct |
4 ms |
1152 KB |
Output is correct |
36 |
Correct |
7 ms |
1152 KB |
Output is correct |
37 |
Correct |
3 ms |
1152 KB |
Output is correct |
38 |
Correct |
2 ms |
1152 KB |
Output is correct |
39 |
Correct |
3 ms |
1152 KB |
Output is correct |
40 |
Correct |
3 ms |
1152 KB |
Output is correct |
41 |
Correct |
5 ms |
1152 KB |
Output is correct |
42 |
Correct |
3 ms |
1152 KB |
Output is correct |
43 |
Correct |
4 ms |
1152 KB |
Output is correct |
44 |
Correct |
4 ms |
1152 KB |
Output is correct |
45 |
Correct |
4 ms |
1152 KB |
Output is correct |
46 |
Correct |
3 ms |
1152 KB |
Output is correct |
47 |
Correct |
3 ms |
1152 KB |
Output is correct |
48 |
Correct |
3 ms |
1152 KB |
Output is correct |
49 |
Correct |
3 ms |
1152 KB |
Output is correct |
50 |
Correct |
4 ms |
1152 KB |
Output is correct |
51 |
Correct |
5 ms |
1152 KB |
Output is correct |
52 |
Correct |
6 ms |
1152 KB |
Output is correct |
53 |
Correct |
3 ms |
1152 KB |
Output is correct |
54 |
Correct |
3 ms |
1152 KB |
Output is correct |
55 |
Correct |
4 ms |
1152 KB |
Output is correct |
56 |
Correct |
2 ms |
1152 KB |
Output is correct |
57 |
Correct |
3 ms |
1152 KB |
Output is correct |
58 |
Correct |
3 ms |
1152 KB |
Output is correct |
59 |
Correct |
216 ms |
6060 KB |
Output is correct |
60 |
Correct |
275 ms |
6120 KB |
Output is correct |
61 |
Correct |
161 ms |
6108 KB |
Output is correct |
62 |
Correct |
161 ms |
6108 KB |
Output is correct |
63 |
Correct |
402 ms |
6088 KB |
Output is correct |
64 |
Correct |
186 ms |
6048 KB |
Output is correct |
65 |
Correct |
260 ms |
6204 KB |
Output is correct |
66 |
Correct |
751 ms |
6212 KB |
Output is correct |
67 |
Correct |
388 ms |
6192 KB |
Output is correct |
68 |
Correct |
169 ms |
6108 KB |
Output is correct |
69 |
Correct |
171 ms |
6240 KB |
Output is correct |
70 |
Correct |
200 ms |
6320 KB |
Output is correct |
71 |
Correct |
330 ms |
6204 KB |
Output is correct |
72 |
Correct |
285 ms |
6160 KB |
Output is correct |
73 |
Correct |
433 ms |
6620 KB |
Output is correct |
74 |
Correct |
158 ms |
6108 KB |
Output is correct |
75 |
Correct |
1031 ms |
6312 KB |
Output is correct |
76 |
Correct |
190 ms |
6160 KB |
Output is correct |
77 |
Correct |
582 ms |
6456 KB |
Output is correct |
78 |
Correct |
422 ms |
6264 KB |
Output is correct |
79 |
Correct |
711 ms |
6308 KB |
Output is correct |
80 |
Correct |
724 ms |
6108 KB |
Output is correct |
81 |
Correct |
686 ms |
6108 KB |
Output is correct |
82 |
Correct |
302 ms |
6596 KB |
Output is correct |
83 |
Correct |
474 ms |
6368 KB |
Output is correct |
84 |
Correct |
1710 ms |
6348 KB |
Output is correct |
85 |
Correct |
672 ms |
6568 KB |
Output is correct |
86 |
Correct |
309 ms |
6268 KB |
Output is correct |
87 |
Correct |
172 ms |
6108 KB |
Output is correct |
88 |
Correct |
285 ms |
6360 KB |
Output is correct |
89 |
Correct |
678 ms |
6584 KB |
Output is correct |
90 |
Correct |
246 ms |
6236 KB |
Output is correct |
91 |
Correct |
509 ms |
6284 KB |
Output is correct |
92 |
Correct |
303 ms |
6476 KB |
Output is correct |
93 |
Correct |
510 ms |
6272 KB |
Output is correct |
94 |
Correct |
1154 ms |
6352 KB |
Output is correct |
95 |
Correct |
188 ms |
6160 KB |
Output is correct |
96 |
Correct |
156 ms |
5980 KB |
Output is correct |
97 |
Correct |
452 ms |
6332 KB |
Output is correct |
98 |
Correct |
211 ms |
6200 KB |
Output is correct |
99 |
Correct |
197 ms |
6108 KB |
Output is correct |
100 |
Correct |
219 ms |
6236 KB |
Output is correct |
101 |
Correct |
299 ms |
6192 KB |
Output is correct |
102 |
Correct |
169 ms |
6236 KB |
Output is correct |
103 |
Correct |
366 ms |
6256 KB |
Output is correct |
104 |
Correct |
1328 ms |
6312 KB |
Output is correct |
105 |
Correct |
180 ms |
6236 KB |
Output is correct |
106 |
Correct |
176 ms |
6108 KB |
Output is correct |
107 |
Correct |
231 ms |
6108 KB |
Output is correct |
108 |
Correct |
215 ms |
6240 KB |
Output is correct |
109 |
Correct |
765 ms |
6600 KB |
Output is correct |
110 |
Correct |
174 ms |
6108 KB |
Output is correct |
111 |
Correct |
613 ms |
6332 KB |
Output is correct |
112 |
Correct |
397 ms |
6348 KB |
Output is correct |
113 |
Correct |
216 ms |
6220 KB |
Output is correct |
114 |
Correct |
151 ms |
5452 KB |
Output is correct |
115 |
Correct |
189 ms |
6168 KB |
Output is correct |
116 |
Correct |
281 ms |
6184 KB |
Output is correct |
117 |
Execution timed out |
3093 ms |
6220 KB |
Time limit exceeded |
118 |
Halted |
0 ms |
0 KB |
- |