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 <iostream>
#include <vector>
using namespace std;
const int COORD_MAX = 1e9;
struct Coord
{
int xBas = 0, yBas = 0, xHaut = COORD_MAX + 1, yHaut = COORD_MAX + 1;
Coord(int _xBas = 0, int _yBas = 0, int _xHaut = COORD_MAX + 1, int _yHaut = COORD_MAX + 1)
{
xBas = _xBas;
yBas = _yBas;
xHaut = _xHaut;
yHaut = _yHaut;
}
void operator=(Coord &other)
{
xBas = other.xBas;
yBas = other.yBas;
xHaut = other.xHaut;
yHaut = other.yHaut;
}
};
int N, K;
vector<Coord> coordRect;
Coord inter(Coord rect1, Coord rect2)
{
Coord retour;
retour.xBas = max(rect1.xBas, rect2.xBas);
retour.yBas = max(rect1.yBas, rect2.yBas);
retour.xHaut = min(rect1.xHaut, rect2.xHaut);
retour.yHaut = min(rect1.yHaut, rect2.yHaut);
if(retour.xBas > retour.xHaut || retour.yBas > retour.yHaut)
{
retour.xBas = -1;
}
return retour;
}
int main()
{
ios::sync_with_stdio(false);
cin >> N >> K;
int xBasRect = 0, yBasRect = 0, xHautRect = COORD_MAX + 1, yHautRect = COORD_MAX + 1;
for(int i = 0; i < N; i++)
{
int xBas, yBas, xHaut, yHaut;
cin >> xBas >> yBas >> xHaut >> yHaut;
xBasRect = max(xBasRect, xBas);
yBasRect = max(yBasRect, yBas);
xHautRect = min(xHaut, xHautRect);
yHautRect = min(yHaut, yHautRect);
coordRect.push_back({xBas, yBas, xHaut, yHaut});
}
if(K == 1)
{
cout << xBasRect << " " << yBasRect << endl;
return 0;
}
Coord rectangle1;
Coord rectangle2;
for(int i = 0; i < N; i++)
{
for(int j = i + 1; j < N; j++)
{
Coord a = inter(coordRect[i], coordRect[j]);
if(a.xBas == -1)
{
rectangle1 = coordRect[i];
rectangle2 = coordRect[j];
break;
}
}
if(rectangle1.xBas != 0)
{
break;
}
}
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
Coord a = inter(rectangle1, coordRect[i]);
Coord b = inter(rectangle2, coordRect[i]);
if(a.xBas == -1)
{
rectangle2 = b;
}
else
{
rectangle1 = a;
}
}
}
cout << rectangle1.xBas << " " << rectangle1.yBas << endl;
cout << rectangle2.xBas << " " << rectangle2.yBas << endl;
}
# | 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... |