#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <random>
#include <algorithm>
#include <chrono>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 200000;
int const inf = 1000000000;
int const sigma = 4;
class Rect{
public:
int x;
int y;
int x2;
int y2;
Rect operator + (Rect a) {
return {max(x, a.x), max(y, a.y), min(x2, a.x2), min(y2, a.y2)};
}
bool valid(){
return (x <= x2) && (y <= y2);
}
ll area(){
return 1LL * (x2 - x + 1) * (y2 - y + 1);
}
} v[1 + nmax];
int main()
{
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<Rect> basic, high;
for(int i = 1;i <= n; i++) {
cin >> v[i].x >> v[i].y >> v[i].x2 >> v[i].y2;
basic.push_back(v[i]);
}
Rect base[1 + sigma];
while(true){
vector<Rect> ord;
ord.insert(ord.end(), high.begin(), high.end());
ord.insert(ord.end(), basic.begin(), basic.end());
high.clear();
basic.clear();
for(int j = 1;j <= k; j++)
base[j] = {1, 1, inf, inf};
for(int i = 0; i < ord.size(); i++){
Rect &curr = ord[i];
bool found = 0;
for(int j = 1;j <= k; j++){
Rect newp = curr + base[j];
if(newp.valid()) {
found = 1;
base[j] = base[j] + curr;
basic.push_back(curr);
break;
}
}
if(found == 0)
high.push_back(curr);
}
if(0 == high.size()){
for(int j = 1;j <= k; j++)
cout << base[j].x << " " << base[j].y << '\n';
return 0;
}
shuffle(basic.begin(), basic.end(), rng);
}
return 0;
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < ord.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 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 |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
9 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
4 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
384 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
4 ms |
384 KB |
Output is correct |
45 |
Correct |
3 ms |
384 KB |
Output is correct |
46 |
Correct |
3 ms |
384 KB |
Output is correct |
47 |
Correct |
2 ms |
384 KB |
Output is correct |
48 |
Correct |
2 ms |
384 KB |
Output is correct |
49 |
Correct |
6 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
384 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
3 ms |
384 KB |
Output is correct |
53 |
Correct |
3 ms |
512 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
4 ms |
512 KB |
Output is correct |
56 |
Correct |
2 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
384 KB |
Output is correct |
58 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
103 ms |
9824 KB |
Output is correct |
6 |
Correct |
108 ms |
9852 KB |
Output is correct |
7 |
Correct |
105 ms |
9908 KB |
Output is correct |
8 |
Correct |
105 ms |
9844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
116 ms |
9848 KB |
Output is correct |
6 |
Correct |
139 ms |
10540 KB |
Output is correct |
7 |
Correct |
131 ms |
11692 KB |
Output is correct |
8 |
Correct |
117 ms |
9912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
137 ms |
9928 KB |
Output is correct |
14 |
Correct |
123 ms |
10792 KB |
Output is correct |
15 |
Correct |
126 ms |
10172 KB |
Output is correct |
16 |
Correct |
125 ms |
10156 KB |
Output is correct |
17 |
Correct |
115 ms |
9896 KB |
Output is correct |
18 |
Correct |
110 ms |
9824 KB |
Output is correct |
19 |
Correct |
155 ms |
11616 KB |
Output is correct |
20 |
Correct |
114 ms |
10720 KB |
Output is correct |
21 |
Correct |
114 ms |
11560 KB |
Output is correct |
22 |
Correct |
137 ms |
11360 KB |
Output is correct |
23 |
Correct |
140 ms |
10660 KB |
Output is correct |
24 |
Correct |
161 ms |
10664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 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 |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
6 ms |
512 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
9 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
4 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
384 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
4 ms |
384 KB |
Output is correct |
45 |
Correct |
3 ms |
384 KB |
Output is correct |
46 |
Correct |
3 ms |
384 KB |
Output is correct |
47 |
Correct |
2 ms |
384 KB |
Output is correct |
48 |
Correct |
2 ms |
384 KB |
Output is correct |
49 |
Correct |
6 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
384 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
3 ms |
384 KB |
Output is correct |
53 |
Correct |
3 ms |
512 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
4 ms |
512 KB |
Output is correct |
56 |
Correct |
2 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
384 KB |
Output is correct |
58 |
Correct |
2 ms |
384 KB |
Output is correct |
59 |
Correct |
383 ms |
10656 KB |
Output is correct |
60 |
Correct |
154 ms |
9952 KB |
Output is correct |
61 |
Correct |
116 ms |
9824 KB |
Output is correct |
62 |
Correct |
174 ms |
9928 KB |
Output is correct |
63 |
Correct |
228 ms |
10540 KB |
Output is correct |
64 |
Correct |
115 ms |
9824 KB |
Output is correct |
65 |
Correct |
258 ms |
11484 KB |
Output is correct |
66 |
Correct |
591 ms |
10664 KB |
Output is correct |
67 |
Correct |
123 ms |
10752 KB |
Output is correct |
68 |
Correct |
348 ms |
11356 KB |
Output is correct |
69 |
Correct |
129 ms |
10668 KB |
Output is correct |
70 |
Correct |
147 ms |
10720 KB |
Output is correct |
71 |
Correct |
153 ms |
11356 KB |
Output is correct |
72 |
Correct |
116 ms |
10704 KB |
Output is correct |
73 |
Correct |
117 ms |
10596 KB |
Output is correct |
74 |
Correct |
156 ms |
11360 KB |
Output is correct |
75 |
Correct |
666 ms |
10696 KB |
Output is correct |
76 |
Correct |
168 ms |
11380 KB |
Output is correct |
77 |
Correct |
941 ms |
11536 KB |
Output is correct |
78 |
Correct |
212 ms |
10792 KB |
Output is correct |
79 |
Correct |
629 ms |
11428 KB |
Output is correct |
80 |
Correct |
118 ms |
10720 KB |
Output is correct |
81 |
Correct |
148 ms |
11360 KB |
Output is correct |
82 |
Correct |
290 ms |
10668 KB |
Output is correct |
83 |
Correct |
523 ms |
11424 KB |
Output is correct |
84 |
Correct |
792 ms |
11560 KB |
Output is correct |
85 |
Correct |
130 ms |
10664 KB |
Output is correct |
86 |
Correct |
170 ms |
11432 KB |
Output is correct |
87 |
Correct |
391 ms |
11424 KB |
Output is correct |
88 |
Correct |
309 ms |
11312 KB |
Output is correct |
89 |
Correct |
1221 ms |
13128 KB |
Output is correct |
90 |
Correct |
203 ms |
11560 KB |
Output is correct |
91 |
Correct |
777 ms |
10796 KB |
Output is correct |
92 |
Correct |
383 ms |
11560 KB |
Output is correct |
93 |
Correct |
113 ms |
10028 KB |
Output is correct |
94 |
Correct |
117 ms |
10664 KB |
Output is correct |
95 |
Correct |
512 ms |
11332 KB |
Output is correct |
96 |
Correct |
325 ms |
12836 KB |
Output is correct |
97 |
Correct |
559 ms |
12844 KB |
Output is correct |
98 |
Correct |
239 ms |
10792 KB |
Output is correct |
99 |
Correct |
494 ms |
11432 KB |
Output is correct |
100 |
Correct |
386 ms |
11448 KB |
Output is correct |
101 |
Correct |
128 ms |
10664 KB |
Output is correct |
102 |
Correct |
1156 ms |
10784 KB |
Output is correct |
103 |
Correct |
121 ms |
11492 KB |
Output is correct |
104 |
Correct |
155 ms |
10592 KB |
Output is correct |
105 |
Correct |
230 ms |
11436 KB |
Output is correct |
106 |
Correct |
176 ms |
11432 KB |
Output is correct |
107 |
Correct |
537 ms |
10672 KB |
Output is correct |
108 |
Correct |
143 ms |
11412 KB |
Output is correct |
109 |
Correct |
510 ms |
11756 KB |
Output is correct |
110 |
Correct |
438 ms |
10764 KB |
Output is correct |
111 |
Correct |
849 ms |
11424 KB |
Output is correct |
112 |
Correct |
203 ms |
10788 KB |
Output is correct |
113 |
Correct |
205 ms |
10660 KB |
Output is correct |
114 |
Correct |
194 ms |
10236 KB |
Output is correct |
115 |
Correct |
117 ms |
10168 KB |
Output is correct |
116 |
Correct |
176 ms |
10208 KB |
Output is correct |
117 |
Execution timed out |
3052 ms |
11500 KB |
Time limit exceeded |
118 |
Halted |
0 ms |
0 KB |
- |