This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<algorithm>
#define N_ 201000
using namespace std;
int n, K;
struct Rect {
int bx, by, ex, ey;
}w[N_];
struct point{
int x,y;
};
bool Inside(Rect a, point b) {
return a.bx <= b.x&&b.x <= a.ex&&a.by <= b.y&&b.y <= a.ey;
}
void Print(point a) {
printf("%d %d\n", a.x, a.y);
}
void Go(int ax, int ay, int bx, int by) {
int i;
point A = { ax,ay }, B = { bx,by };
int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = 1; i <= n; i++) {
if (!Inside(w[i], A) && !Inside(w[i], B)) {
if (K == 2)return;
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
}
}
if (K == 2) {
Print(A);
Print(B);
exit(0);
}
if (K == 3 && Ax <= Bx && Ay <= By) {
point C = { Ax,Ay };
Print(A); Print(B); Print(C);
exit(0);
}
}
int main() {
int i;
scanf("%d%d", &n, &K);
int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
for (i = 1; i <= n; i++) {
scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
Ax = max(Ax, w[i].bx);
Ay = max(Ay, w[i].by);
Bx = min(Bx, w[i].ex);
By = min(By, w[i].ey);
}
if (K == 1) {
printf("%d %d\n", Ax, Ay);
return 0;
}
if (K <= 3) {
Go(Ax, Ay, Bx, By);
Go(Ax, By, Bx, Ay);
return 0;
}
}
Compilation message (stderr)
hamburg.cpp: In function 'int main()':
hamburg.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d%d", &n, &K);
| ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |