#include <bits/stdc++.h>
#define MAXN 200007
using namespace std;
int n,k;
struct rect{int xl,xh,yl,yh;};
rect intersect(rect a,rect b) {rect r={max(a.xl,b.xl),min(a.xh,b.xh),max(a.yl,b.yl),min(a.yh,b.yh)}; return r;}
bool valid(rect a) {return a.xh>=a.xl && a.yh>=a.yl;}
rect p[MAXN],res;
pair<int,int> px[MAXN],py[MAXN];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline vector<rect> check(vector<rect> pot)
{
vector<rect> t;
for(int i=0;i<n;i++)
{
bool ziv=false;
for(int j=0;j<pot.size();j++) if(valid(intersect(p[i],pot[j])))
{
pot[j]=intersect(pot[j],p[i]);
ziv=true;
break;
}
if(!ziv) return t;
}
return pot;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&p[i].xl,&p[i].yl,&p[i].xh,&p[i].yh);
if(!i) res=intersect(p[0],p[0]);
else res=intersect(res,p[i]);
}
if(k==1) {printf("%d %d",res.xl,res.yl); return 0;}
if(k>1 && valid(res))
{
printf("%d %d\n",res.xl,res.yl);
for(int i=1;i<k;i++) printf("1 1\n");
return 0;
}
for(int i=0;i<n;i++) px[i]={p[i].xl,p[i].xh};
for(int i=0;i<n;i++) py[i]={p[i].yl,p[i].yh};
sort(px,px+n);
sort(py,py+n);
vector<int> xn,yn;
int mnx=1000000007,mndx,mny=1000000007,mndy;
for(int i=0;i<n;i++)
{
if(mnx>=px[i].second)
{
mnx=px[i].second;
mndx=i;
}
if(px[i].first>mnx)
{
xn.push_back(mndx);
mnx=px[i].second;
mndx=i;
}
}
xn.push_back(mndx);
for(int i=0;i<n;i++)
{
if(mny>=py[i].second)
{
mny=py[i].second;
mndy=i;
}
if(py[i].first>mny)
{
yn.push_back(mndy);
mny=py[i].second;
mndy=i;
}
}
yn.push_back(mndy);
while(xn.size()>yn.size()) yn.push_back(yn[0]);
while(yn.size()>xn.size()) xn.push_back(xn[0]);
int t=xn.size();
sort(xn.begin(),xn.end());
sort(yn.begin(),yn.end());
while(true)
{
do
{
vector<rect> prv;
for(int i=0;i<t;i++) prv.push_back({px[xn[i]].first,px[xn[i]].second,py[yn[i]].first,py[yn[i]].second});
vector<rect> sol=check(prv);
if(sol.size()!=0)
{
for(int i=0;i<t;i++) printf("%d %d\n",sol[i].xl,sol[i].yl);
for(int i=t;i<k;i++) printf("1 1\n");
return 0;
}
} while(next_permutation(yn.begin(),yn.end()));
shuffle(p,p+n,rng);
}
}
Compilation message
hamburg.cpp: In function 'std::vector<rect> check(std::vector<rect>)':
hamburg.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rect>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int j=0;j<pot.size();j++) if(valid(intersect(p[i],pot[j])))
| ~^~~~~~~~~~~
hamburg.cpp: In function 'int main()':
hamburg.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
29 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
hamburg.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
32 | scanf("%d%d%d%d",&p[i].xl,&p[i].yl,&p[i].xh,&p[i].yh);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 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 |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 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 |
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 |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Execution timed out |
3089 ms |
384 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
140 ms |
3448 KB |
Output is correct |
6 |
Correct |
147 ms |
3448 KB |
Output is correct |
7 |
Correct |
141 ms |
3456 KB |
Output is correct |
8 |
Correct |
170 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
203 ms |
6520 KB |
Output is correct |
6 |
Execution timed out |
3078 ms |
6552 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 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 |
178 ms |
6520 KB |
Output is correct |
14 |
Correct |
179 ms |
6520 KB |
Output is correct |
15 |
Correct |
187 ms |
6520 KB |
Output is correct |
16 |
Correct |
184 ms |
6556 KB |
Output is correct |
17 |
Correct |
234 ms |
6624 KB |
Output is correct |
18 |
Correct |
192 ms |
6524 KB |
Output is correct |
19 |
Correct |
211 ms |
6520 KB |
Output is correct |
20 |
Correct |
737 ms |
6624 KB |
Output is correct |
21 |
Correct |
220 ms |
6648 KB |
Output is correct |
22 |
Correct |
339 ms |
6528 KB |
Output is correct |
23 |
Correct |
296 ms |
6624 KB |
Output is correct |
24 |
Correct |
196 ms |
6552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Execution timed out |
3089 ms |
384 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |