#include <vector>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int n, X, Y, x1, x2, y1, y2, wynx, wyny, a, b;
vector<pair<int, pair<int,int> > >tab1, tab2;
int main()
{
scanf("%d %d %d", &n, &X, &Y);
for(int i=0; i<n; i++)
{
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
if(x1>x2)
{
a=x1;
x1=x2;
x2=a;
}
tab1.push_back(make_pair(x2,make_pair (x1,x1)));
if(y1>y2)
{
a=y1;
y1=y2;
y2=a;
}
tab2.push_back(make_pair(y2,make_pair (y1,y1)));
}
sort(tab1.begin(), tab1.end());
sort(tab2.begin(), tab2.end());
for(int i=1; i<tab1.size(); i++)
{
if(tab1[i].second.first>tab1[i-1].second.first)
tab1[i].second.first=tab1[i-1].second.first;
}
for(int i=tab1.size()-2; i>=0; i--)
{
if(tab1[i].second.second<tab1[i+1].second.second)
tab1[i].second.second=tab1[i+1].second.second;
}
for(int i=1; i<tab2.size(); i++)
{
if(tab2[i].second.first>tab2[i-1].second.first)
tab2[i].second.first=tab2[i-1].second.first;
}
for(int i=tab2.size()-2; i>=0; i--)
{
if(tab2[i].second.second<tab2[i+1].second.second)
tab2[i].second.second=tab2[i+1].second.second;
}
a=X-tab1[tab1.size()-1].first;
if(a<0)
a=0;
a=a+tab1[tab1.size()-1].second.first;
b=tab1[0].first-tab1[0].second.second;
wynx=a;
if(wynx<b)
wynx=b;
for(int i=1; i<tab1.size(); i++)
{
a=tab1[i-1].second.first-tab1[i].second.second;
if(a<0)
a=0;
a=a+tab1[i].first-tab1[i-1].first;
if(a>wynx)
wynx=a;
}
a=Y-tab2[tab2.size()-1].first;
if(a<0)
a=0;
a=a+tab2[tab1.size()-1].second.first;
b=tab2[0].first-tab2[0].second.second;
wyny=a;
if(wyny<b)
wyny=b;
for(int i=1; i<tab2.size(); i++)
{
a=tab2[i-1].second.first-tab2[i].second.second;
if(a<0)
a=0;
a=a+tab2[i].first-tab2[i-1].first;
if(a>wyny)
wyny=a;
}
long long int wynik=wynx;
wynik=wynik*wyny;
printf("%lld", wynik);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <vector> #include <cstdio> #include <algorithm> #include <iostream> using namespace std; int n, X, Y, x1, x2, y1, y2, wynx, wyny, a, b; vector<pair<int, pair<int,int> > >tab1, tab2; int main() { scanf("%d %d %d", &n, &X, &Y); for(int i=0; i<n; i++) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); if(x1>x2) { a=x1; x1=x2; x2=a; } tab1.push_back(make_pair(x2,make_pair (x1,x1))); if(y1>y2) { a=y1; y1=y2; y2=a; } tab2.push_back(make_pair(y2,make_pair (y1,y1))); } sort(tab1.begin(), tab1.end()); sort(tab2.begin(), tab2.end()); for(int i=1; i<tab1.size(); i++) { if(tab1[i].second.first>tab1[i-1].second.first) tab1[i].second.first=tab1[i-1].second.first; } for(int i=tab1.size()-2; i>=0; i--) { if(tab1[i].second.second<tab1[i+1].second.second) tab1[i].second.second=tab1[i+1].second.second; } for(int i=1; i<tab2.size(); i++) { if(tab2[i].second.first>tab2[i-1].second.first) tab2[i].second.first=tab2[i-1].second.first; } for(int i=tab2.size()-2; i>=0; i--) { if(tab2[i].second.second<tab2[i+1].second.second) tab2[i].second.second=tab2[i+1].second.second; } a=X-tab1[tab1.size()-1].first; if(a<0) a=0; a=a+tab1[tab1.size()-1].second.first; b=tab1[0].first-tab1[0].second.second; wynx=a; if(wynx<b) wynx=b; for(int i=1; i<tab1.size(); i++) { a=tab1[i-1].second.first-tab1[i].second.second; if(a<0) a=0; a=a+tab1[i].first-tab1[i-1].first; if(a>wynx) wynx=a; } a=Y-tab2[tab2.size()-1].first; if(a<0) a=0; a=a+tab2[tab1.size()-1].second.first; b=tab2[0].first-tab2[0].second.second; wyny=a; if(wyny<b) wyny=b; for(int i=1; i<tab2.size(); i++) { a=tab2[i-1].second.first-tab2[i].second.second; if(a<0) a=0; a=a+tab2[i].first-tab2[i-1].first; if(a>wyny) wyny=a; } long long int wynik=wynx; wynik=wynik*wyny; printf("%lld", wynik); return 0; } |
English