#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 200100
#define K 4
#define M 10
struct rec{
int x1,x2,y1,y2;
friend rec operator^(const rec&x,const rec&y){
return {max(x.x1,y.x1),min(x.x2,y.x2),max(x.y1,y.y1),min(x.y2,y.y2)};
}
int area(){
if(x1>x2||y1>y2){return 0;}
return (x2-x1+1)*(y2-y1+1);
}
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;
rec arr[N],res[K];
rec arr2[N];
vector<int>srt;
int weight[N];
bool vis[N];
signed main(){
cin>>n>>k;
for(int a=0;a<n;++a){
cin>>arr[a].x1>>arr[a].y1>>arr[a].x2>>arr[a].y2;
}
for(int a=0;a<n;++a) {
weight[a]=1;
for (int b = 0; b < M; ++b) {
int r2=rng()%n;
if((arr[a]^arr[r2]).area()==0){
++weight[a];
}
}
}
for(int a=0;a<n;++a){
for(int b=0;b<weight[a];++b) {
srt.push_back(a);
}
}
while(true){
shuffle(srt.begin(),srt.end(),rng);
memset(vis,0,sizeof(vis));
for(int a=0,b=0;a<srt.size()&&b<n;++a){
if(vis[srt[a]]){
continue;
}
arr2[b]=arr[srt[a]];
vis[srt[a]]=true;
++b;
}
for(int b=0;b<k;++b){
res[b]=arr2[b];
}
bool flag=false;
//shrink res
for(int a=k;a<n;++a){
pair<double,int>p={0,-1};
for(int b=0;b<k;++b){
p=max(p,{(1.0*(res[b]^arr2[a]).area())/res[b].area(),b});
}
res[p.second]=res[p.second]^arr2[a];
if(res[p.second].x1>res[p.second].x2||res[p.second].y1>res[p.second].y2){
flag=true;
break;
}
}
if(!flag){
for(int b=0;b<k;++b){
cout<<res[b].x1<<" "<<res[b].y1<<endl;
}
break;
}
}
}
Compilation message
hamburg.cpp: In function 'int main()':
hamburg.cpp:50:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int a=0,b=0;a<srt.size()&&b<n;++a){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
724 KB |
Output is correct |
4 |
Correct |
4 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
724 KB |
Output is correct |
2 |
Correct |
6 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
844 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
796 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
5 ms |
848 KB |
Output is correct |
9 |
Correct |
7 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
7 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
6 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
720 KB |
Output is correct |
7 |
Correct |
9 ms |
740 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
8 ms |
848 KB |
Output is correct |
13 |
Correct |
7 ms |
724 KB |
Output is correct |
14 |
Correct |
10 ms |
848 KB |
Output is correct |
15 |
Correct |
8 ms |
720 KB |
Output is correct |
16 |
Correct |
5 ms |
720 KB |
Output is correct |
17 |
Correct |
7 ms |
852 KB |
Output is correct |
18 |
Correct |
6 ms |
796 KB |
Output is correct |
19 |
Correct |
6 ms |
848 KB |
Output is correct |
20 |
Correct |
5 ms |
848 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
7 ms |
796 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
8 ms |
852 KB |
Output is correct |
25 |
Correct |
7 ms |
848 KB |
Output is correct |
26 |
Correct |
15 ms |
844 KB |
Output is correct |
27 |
Correct |
5 ms |
724 KB |
Output is correct |
28 |
Correct |
11 ms |
724 KB |
Output is correct |
29 |
Correct |
7 ms |
800 KB |
Output is correct |
30 |
Correct |
7 ms |
724 KB |
Output is correct |
31 |
Correct |
8 ms |
796 KB |
Output is correct |
32 |
Correct |
5 ms |
800 KB |
Output is correct |
33 |
Correct |
6 ms |
724 KB |
Output is correct |
34 |
Correct |
7 ms |
800 KB |
Output is correct |
35 |
Correct |
5 ms |
852 KB |
Output is correct |
36 |
Correct |
5 ms |
724 KB |
Output is correct |
37 |
Correct |
10 ms |
868 KB |
Output is correct |
38 |
Correct |
7 ms |
856 KB |
Output is correct |
39 |
Correct |
6 ms |
836 KB |
Output is correct |
40 |
Correct |
6 ms |
724 KB |
Output is correct |
41 |
Correct |
5 ms |
804 KB |
Output is correct |
42 |
Correct |
8 ms |
724 KB |
Output is correct |
43 |
Correct |
5 ms |
792 KB |
Output is correct |
44 |
Correct |
7 ms |
724 KB |
Output is correct |
45 |
Correct |
7 ms |
852 KB |
Output is correct |
46 |
Correct |
6 ms |
724 KB |
Output is correct |
47 |
Correct |
12 ms |
724 KB |
Output is correct |
48 |
Correct |
6 ms |
792 KB |
Output is correct |
49 |
Correct |
5 ms |
852 KB |
Output is correct |
50 |
Correct |
7 ms |
720 KB |
Output is correct |
51 |
Correct |
12 ms |
852 KB |
Output is correct |
52 |
Correct |
6 ms |
724 KB |
Output is correct |
53 |
Correct |
6 ms |
724 KB |
Output is correct |
54 |
Correct |
8 ms |
852 KB |
Output is correct |
55 |
Correct |
7 ms |
852 KB |
Output is correct |
56 |
Correct |
8 ms |
852 KB |
Output is correct |
57 |
Correct |
6 ms |
852 KB |
Output is correct |
58 |
Correct |
8 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
724 KB |
Output is correct |
4 |
Correct |
4 ms |
692 KB |
Output is correct |
5 |
Correct |
398 ms |
17036 KB |
Output is correct |
6 |
Correct |
404 ms |
17028 KB |
Output is correct |
7 |
Correct |
401 ms |
16888 KB |
Output is correct |
8 |
Correct |
373 ms |
16884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
466 ms |
19876 KB |
Output is correct |
6 |
Correct |
427 ms |
17564 KB |
Output is correct |
7 |
Correct |
455 ms |
19160 KB |
Output is correct |
8 |
Correct |
468 ms |
21028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
724 KB |
Output is correct |
2 |
Correct |
6 ms |
724 KB |
Output is correct |
3 |
Correct |
5 ms |
844 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
796 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
5 ms |
848 KB |
Output is correct |
9 |
Correct |
7 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
482 ms |
18896 KB |
Output is correct |
14 |
Correct |
439 ms |
18816 KB |
Output is correct |
15 |
Correct |
430 ms |
18128 KB |
Output is correct |
16 |
Correct |
391 ms |
17460 KB |
Output is correct |
17 |
Correct |
528 ms |
19284 KB |
Output is correct |
18 |
Correct |
466 ms |
17292 KB |
Output is correct |
19 |
Correct |
495 ms |
20204 KB |
Output is correct |
20 |
Correct |
505 ms |
20192 KB |
Output is correct |
21 |
Correct |
498 ms |
20716 KB |
Output is correct |
22 |
Correct |
454 ms |
18676 KB |
Output is correct |
23 |
Correct |
912 ms |
19760 KB |
Output is correct |
24 |
Correct |
464 ms |
20028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Correct |
5 ms |
720 KB |
Output is correct |
3 |
Correct |
7 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
6 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
720 KB |
Output is correct |
7 |
Correct |
9 ms |
740 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
8 ms |
848 KB |
Output is correct |
13 |
Correct |
7 ms |
724 KB |
Output is correct |
14 |
Correct |
10 ms |
848 KB |
Output is correct |
15 |
Correct |
8 ms |
720 KB |
Output is correct |
16 |
Correct |
5 ms |
720 KB |
Output is correct |
17 |
Correct |
7 ms |
852 KB |
Output is correct |
18 |
Correct |
6 ms |
796 KB |
Output is correct |
19 |
Correct |
6 ms |
848 KB |
Output is correct |
20 |
Correct |
5 ms |
848 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
7 ms |
796 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
8 ms |
852 KB |
Output is correct |
25 |
Correct |
7 ms |
848 KB |
Output is correct |
26 |
Correct |
15 ms |
844 KB |
Output is correct |
27 |
Correct |
5 ms |
724 KB |
Output is correct |
28 |
Correct |
11 ms |
724 KB |
Output is correct |
29 |
Correct |
7 ms |
800 KB |
Output is correct |
30 |
Correct |
7 ms |
724 KB |
Output is correct |
31 |
Correct |
8 ms |
796 KB |
Output is correct |
32 |
Correct |
5 ms |
800 KB |
Output is correct |
33 |
Correct |
6 ms |
724 KB |
Output is correct |
34 |
Correct |
7 ms |
800 KB |
Output is correct |
35 |
Correct |
5 ms |
852 KB |
Output is correct |
36 |
Correct |
5 ms |
724 KB |
Output is correct |
37 |
Correct |
10 ms |
868 KB |
Output is correct |
38 |
Correct |
7 ms |
856 KB |
Output is correct |
39 |
Correct |
6 ms |
836 KB |
Output is correct |
40 |
Correct |
6 ms |
724 KB |
Output is correct |
41 |
Correct |
5 ms |
804 KB |
Output is correct |
42 |
Correct |
8 ms |
724 KB |
Output is correct |
43 |
Correct |
5 ms |
792 KB |
Output is correct |
44 |
Correct |
7 ms |
724 KB |
Output is correct |
45 |
Correct |
7 ms |
852 KB |
Output is correct |
46 |
Correct |
6 ms |
724 KB |
Output is correct |
47 |
Correct |
12 ms |
724 KB |
Output is correct |
48 |
Correct |
6 ms |
792 KB |
Output is correct |
49 |
Correct |
5 ms |
852 KB |
Output is correct |
50 |
Correct |
7 ms |
720 KB |
Output is correct |
51 |
Correct |
12 ms |
852 KB |
Output is correct |
52 |
Correct |
6 ms |
724 KB |
Output is correct |
53 |
Correct |
6 ms |
724 KB |
Output is correct |
54 |
Correct |
8 ms |
852 KB |
Output is correct |
55 |
Correct |
7 ms |
852 KB |
Output is correct |
56 |
Correct |
8 ms |
852 KB |
Output is correct |
57 |
Correct |
6 ms |
852 KB |
Output is correct |
58 |
Correct |
8 ms |
852 KB |
Output is correct |
59 |
Correct |
754 ms |
19500 KB |
Output is correct |
60 |
Correct |
438 ms |
18576 KB |
Output is correct |
61 |
Correct |
609 ms |
18676 KB |
Output is correct |
62 |
Correct |
477 ms |
18044 KB |
Output is correct |
63 |
Correct |
490 ms |
18400 KB |
Output is correct |
64 |
Correct |
450 ms |
16652 KB |
Output is correct |
65 |
Correct |
412 ms |
19032 KB |
Output is correct |
66 |
Correct |
1222 ms |
18256 KB |
Output is correct |
67 |
Correct |
700 ms |
20336 KB |
Output is correct |
68 |
Correct |
1187 ms |
19344 KB |
Output is correct |
69 |
Correct |
514 ms |
19940 KB |
Output is correct |
70 |
Correct |
540 ms |
19816 KB |
Output is correct |
71 |
Correct |
1978 ms |
21184 KB |
Output is correct |
72 |
Correct |
836 ms |
19520 KB |
Output is correct |
73 |
Correct |
911 ms |
19916 KB |
Output is correct |
74 |
Correct |
667 ms |
20668 KB |
Output is correct |
75 |
Correct |
436 ms |
17928 KB |
Output is correct |
76 |
Correct |
719 ms |
19652 KB |
Output is correct |
77 |
Correct |
587 ms |
19576 KB |
Output is correct |
78 |
Correct |
462 ms |
19972 KB |
Output is correct |
79 |
Correct |
633 ms |
19756 KB |
Output is correct |
80 |
Correct |
468 ms |
19388 KB |
Output is correct |
81 |
Correct |
555 ms |
19500 KB |
Output is correct |
82 |
Correct |
859 ms |
19108 KB |
Output is correct |
83 |
Correct |
451 ms |
19208 KB |
Output is correct |
84 |
Correct |
444 ms |
18656 KB |
Output is correct |
85 |
Correct |
727 ms |
20908 KB |
Output is correct |
86 |
Correct |
688 ms |
18636 KB |
Output is correct |
87 |
Correct |
592 ms |
20872 KB |
Output is correct |
88 |
Correct |
625 ms |
20644 KB |
Output is correct |
89 |
Correct |
730 ms |
18728 KB |
Output is correct |
90 |
Correct |
742 ms |
20004 KB |
Output is correct |
91 |
Correct |
510 ms |
18864 KB |
Output is correct |
92 |
Correct |
1248 ms |
20912 KB |
Output is correct |
93 |
Correct |
707 ms |
19752 KB |
Output is correct |
94 |
Correct |
1708 ms |
19860 KB |
Output is correct |
95 |
Correct |
614 ms |
20136 KB |
Output is correct |
96 |
Correct |
2100 ms |
19320 KB |
Output is correct |
97 |
Correct |
536 ms |
19604 KB |
Output is correct |
98 |
Correct |
536 ms |
20132 KB |
Output is correct |
99 |
Correct |
430 ms |
18544 KB |
Output is correct |
100 |
Correct |
692 ms |
19692 KB |
Output is correct |
101 |
Correct |
498 ms |
19396 KB |
Output is correct |
102 |
Correct |
1466 ms |
18032 KB |
Output is correct |
103 |
Correct |
463 ms |
20860 KB |
Output is correct |
104 |
Correct |
1307 ms |
18520 KB |
Output is correct |
105 |
Correct |
1510 ms |
20360 KB |
Output is correct |
106 |
Correct |
678 ms |
19916 KB |
Output is correct |
107 |
Correct |
539 ms |
19028 KB |
Output is correct |
108 |
Correct |
536 ms |
19740 KB |
Output is correct |
109 |
Correct |
570 ms |
19948 KB |
Output is correct |
110 |
Correct |
985 ms |
19396 KB |
Output is correct |
111 |
Correct |
1218 ms |
20228 KB |
Output is correct |
112 |
Correct |
1646 ms |
20468 KB |
Output is correct |
113 |
Correct |
591 ms |
21684 KB |
Output is correct |
114 |
Correct |
443 ms |
21628 KB |
Output is correct |
115 |
Correct |
539 ms |
21688 KB |
Output is correct |
116 |
Correct |
616 ms |
21756 KB |
Output is correct |
117 |
Execution timed out |
3072 ms |
24604 KB |
Time limit exceeded |
118 |
Halted |
0 ms |
0 KB |
- |