#include <iostream> #include <vector> using namespace std; typedef long long int lint; int X, Y; class Rect { public: lint x1, y1, x2, y2; Rect(lint _x1, lint _y1, lint _x2, lint _y2) : x1(min(_x1, _x2)), y1(min(_y1, _y2)), x2(max(_x1, _x2)), y2(max(_y1, _y2)) { } lint surface() const { return (x2 - x1) * (y2 - y1); } bool isDegenerated() const { return x2 <= x1 || y2 <= y1; } Rect intersect(const Rect& other) const { lint x = max(x1, other.x1); lint X = min(x2, other.x2); lint y = max(y1, other.y1); lint Y = min(y2, other.y2); if (x < X && y < Y) { return Rect(x, y, X, Y); } else { return Rect(0, 0, 0, 0); } } }; class DisjointRects { public: vector<Rect> rects; DisjointRects()=default; DisjointRects(const DisjointRects&)=delete; DisjointRects(DisjointRects&& temp) : rects(move(temp.rects)) { } DisjointRects& operator=(const DisjointRects&)=delete; void addRect(Rect r) { if (!r.isDegenerated()) { rects.push_back(r); } } bool empty() const { return rects.empty(); } lint surface() const { lint sum = 0; for (const Rect& r: rects) { sum += r.surface(); } return sum; } DisjointRects intersect(const DisjointRects& other) const { DisjointRects res; for (const Rect& r: other.rects) { for (const Rect& q: rects) { res.addRect(r.intersect(q)); } } return res; } }; class Possiblites { public: vector<DisjointRects> possibilites; Possiblites()=default; Possiblites(const Possiblites&) = delete; Possiblites(Possiblites&& temp) : possibilites(move(temp.possibilites)) { } Possiblites& operator=(const Possiblites&) = delete; Possiblites& operator=(Possiblites&& temp) { this->possibilites = move(temp.possibilites); return *this; } void addPossibility(DisjointRects&& poss) { if (poss.empty()) { return; } if (poss.rects.size() == 1 && poss.surface() == 1) { return; } possibilites.push_back(move(poss)); } bool empty() { return possibilites.empty(); } lint worst() const { lint m = X*Y; for (const DisjointRects& poss: possibilites) { lint s = poss.surface(); if (s < m) { m = s; } } return m; } lint best() const { lint M = 0; for (const DisjointRects& poss: possibilites) { lint s = poss.surface(); if (s > M) { M = s; } } return M; } Possiblites addTerritory(lint x1, lint y1, lint x2, lint y2) const { const vector<DisjointRects>& terrInters = createTerritoryInterpretations(x1, y1, x2, y2); Possiblites res; for (const DisjointRects& terrInter: terrInters) { for (const DisjointRects& poss: possibilites) { res.addPossibility(terrInter.intersect(poss)); } } return res; } vector<DisjointRects> createTerritoryInterpretations(lint x1, lint y1, lint x2, lint y2) const { vector<DisjointRects> terrInters; Rect b(x1, y1, x2, y2); DisjointRects inter1; inter1.addRect(Rect(0, 0, b.x1, b.y1)); inter1.addRect(Rect(b.x2, b.y1, X, 0)); inter1.addRect(Rect(b.x2, b.y2, X, Y)); inter1.addRect(Rect(0, Y, b.x1, b.y2)); terrInters.push_back(move(inter1)); DisjointRects inter2; inter2.addRect(Rect(b.x1, 0, b.x2, b.y1)); inter2.addRect(Rect(b.x1, b.y2, b.x2, Y)); terrInters.push_back(move(inter2)); DisjointRects inter3; inter3.addRect(Rect(0, b.y1, b.x1, b.y2)); inter3.addRect(Rect(b.x2, b.y1, X, b.y2)); terrInters.push_back(move(inter3)); DisjointRects inter4; inter4.addRect(Rect(b.x1, b.y1, b.x2, b.y2)); terrInters.push_back(move(inter4)); return terrInters; } static Possiblites wholePlanet() { Possiblites possibilites; DisjointRects rects; rects.addRect(Rect(0, 0, X, Y)); possibilites.addPossibility(move(rects)); return possibilites; } }; int main() { ios_base::sync_with_stdio(false); int n; cin >> n >> X >> Y; Possiblites possibilities = Possiblites::wholePlanet(); while (n--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; possibilities = possibilities.addTerritory(x1, y1, x2, y2); if (possibilities.empty()) { break; } //cout << possibilities.possibilites.size() << endl; //cout << possibilities.worst() << " " << possibilities.best() << endl; } if (possibilities.empty()) { cout << 1 << endl; } else { cout << possibilities.best() << endl; } 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | #include <iostream> #include <vector> using namespace std; typedef long long int lint; int X, Y; class Rect { public: lint x1, y1, x2, y2; Rect(lint _x1, lint _y1, lint _x2, lint _y2) : x1(min(_x1, _x2)), y1(min(_y1, _y2)), x2(max(_x1, _x2)), y2(max(_y1, _y2)) { } lint surface() const { return (x2 - x1) * (y2 - y1); } bool isDegenerated() const { return x2 <= x1 || y2 <= y1; } Rect intersect(const Rect& other) const { lint x = max(x1, other.x1); lint X = min(x2, other.x2); lint y = max(y1, other.y1); lint Y = min(y2, other.y2); if (x < X && y < Y) { return Rect(x, y, X, Y); } else { return Rect(0, 0, 0, 0); } } }; class DisjointRects { public: vector<Rect> rects; DisjointRects()=default; DisjointRects(const DisjointRects&)=delete; DisjointRects(DisjointRects&& temp) : rects(move(temp.rects)) { } DisjointRects& operator=(const DisjointRects&)=delete; void addRect(Rect r) { if (!r.isDegenerated()) { rects.push_back(r); } } bool empty() const { return rects.empty(); } lint surface() const { lint sum = 0; for (const Rect& r: rects) { sum += r.surface(); } return sum; } DisjointRects intersect(const DisjointRects& other) const { DisjointRects res; for (const Rect& r: other.rects) { for (const Rect& q: rects) { res.addRect(r.intersect(q)); } } return res; } }; class Possiblites { public: vector<DisjointRects> possibilites; Possiblites()=default; Possiblites(const Possiblites&) = delete; Possiblites(Possiblites&& temp) : possibilites(move(temp.possibilites)) { } Possiblites& operator=(const Possiblites&) = delete; Possiblites& operator=(Possiblites&& temp) { this->possibilites = move(temp.possibilites); return *this; } void addPossibility(DisjointRects&& poss) { if (poss.empty()) { return; } if (poss.rects.size() == 1 && poss.surface() == 1) { return; } possibilites.push_back(move(poss)); } bool empty() { return possibilites.empty(); } lint worst() const { lint m = X*Y; for (const DisjointRects& poss: possibilites) { lint s = poss.surface(); if (s < m) { m = s; } } return m; } lint best() const { lint M = 0; for (const DisjointRects& poss: possibilites) { lint s = poss.surface(); if (s > M) { M = s; } } return M; } Possiblites addTerritory(lint x1, lint y1, lint x2, lint y2) const { const vector<DisjointRects>& terrInters = createTerritoryInterpretations(x1, y1, x2, y2); Possiblites res; for (const DisjointRects& terrInter: terrInters) { for (const DisjointRects& poss: possibilites) { res.addPossibility(terrInter.intersect(poss)); } } return res; } vector<DisjointRects> createTerritoryInterpretations(lint x1, lint y1, lint x2, lint y2) const { vector<DisjointRects> terrInters; Rect b(x1, y1, x2, y2); DisjointRects inter1; inter1.addRect(Rect(0, 0, b.x1, b.y1)); inter1.addRect(Rect(b.x2, b.y1, X, 0)); inter1.addRect(Rect(b.x2, b.y2, X, Y)); inter1.addRect(Rect(0, Y, b.x1, b.y2)); terrInters.push_back(move(inter1)); DisjointRects inter2; inter2.addRect(Rect(b.x1, 0, b.x2, b.y1)); inter2.addRect(Rect(b.x1, b.y2, b.x2, Y)); terrInters.push_back(move(inter2)); DisjointRects inter3; inter3.addRect(Rect(0, b.y1, b.x1, b.y2)); inter3.addRect(Rect(b.x2, b.y1, X, b.y2)); terrInters.push_back(move(inter3)); DisjointRects inter4; inter4.addRect(Rect(b.x1, b.y1, b.x2, b.y2)); terrInters.push_back(move(inter4)); return terrInters; } static Possiblites wholePlanet() { Possiblites possibilites; DisjointRects rects; rects.addRect(Rect(0, 0, X, Y)); possibilites.addPossibility(move(rects)); return possibilites; } }; int main() { ios_base::sync_with_stdio(false); int n; cin >> n >> X >> Y; Possiblites possibilities = Possiblites::wholePlanet(); while (n--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; possibilities = possibilities.addTerritory(x1, y1, x2, y2); if (possibilities.empty()) { break; } //cout << possibilities.possibilites.size() << endl; //cout << possibilities.worst() << " " << possibilities.best() << endl; } if (possibilities.empty()) { cout << 1 << endl; } else { cout << possibilities.best() << endl; } return 0; } |