#include <algorithm> #include <iostream> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; struct Plot { PII left_corner; PII right_corner; }; vector<vector<Plot>> make_next_territory(int x1, int y1, int x2, int y2, int X, int Y) { int minX = min(x1, x2); int maxX = max(x1, x2); int minY = min(y1, y2); int maxY = max(y1, y2); vector<Plot> plots1; vector<Plot> plots2; vector<Plot> plots3; vector<Plot> plots4; Plot plot = { make_pair(minX, minY), make_pair(maxX, maxY) }; plots1.push_back(plot); if (minX > 0) { plot = { make_pair(0, minY), make_pair(minX, maxY) }; plots2.push_back(plot); } plot = { make_pair(maxX, minY), make_pair(X, maxY) }; plots2.push_back(plot); if (minY > 0) { plot = { make_pair(minX, 0), make_pair(maxX, minY) }; plots3.push_back(plot); } plot = { make_pair(minX, maxY), make_pair(maxX, Y) }; plots3.push_back(plot); if (minX > 0) { plot = { make_pair(0, maxY), make_pair(minX, Y) }; plots4.push_back(plot); } if (minY > 0) { plot = { make_pair(maxX, 0), make_pair(X, minY) }; plots4.push_back(plot); } if (minX > 0 && minY > 0) { plot = { make_pair(0, 0), make_pair(minX, minY) }; plots4.push_back(plot); } plot = { make_pair(maxX, maxY), make_pair(X, Y) }; plots4.push_back(plot); vector<vector<Plot>> next_territory{ plots1, plots2, plots3, plots4 }; return next_territory; } vector<vector<Plot>> make_new_territories(vector<vector<Plot>> territories, vector<vector<Plot>> next_territory) { vector<vector<Plot>> new_territories; for (int t1 = 0; t1 < territories.size(); ++t1) { for (int t2 = 0; t2 < next_territory.size(); ++t2) { vector<Plot> new_plots; for (int p1 = 0; p1 < territories[t1].size(); ++p1) { for (int p2 = 0; p2 < next_territory[t2].size(); ++p2) { int x1 = max(territories[t1][p1].left_corner.first, next_territory[t2][p2].left_corner.first); int y1 = max(territories[t1][p1].left_corner.second, next_territory[t2][p2].left_corner.second); int x2 = min(territories[t1][p1].right_corner.first, next_territory[t2][p2].right_corner.first); int y2 = min(territories[t1][p1].right_corner.second, next_territory[t2][p2].right_corner.second); if (x1 < x2 && y1 < y2) { Plot plot = { make_pair(x1, y1), make_pair(x2, y2) }; new_plots.push_back(plot); } } } if (new_plots.size() > 0) new_territories.push_back(new_plots); } } return new_territories; } int main() { int n, X, Y, x1, y1, x2, y2; cin >> n >> X >> Y; vector<vector<Plot>> territories(1, vector<Plot>(1)); territories[0][0].left_corner = make_pair(0, 0); territories[0][0].right_corner = make_pair(X, Y); for (int i = 0; i < n; ++i) { cin >> x1 >> y1 >> x2 >> y2; vector<vector<Plot>> next_territory = make_next_territory(x1, y1, x2, y2, X, Y); territories = make_new_territories(territories, next_territory); } LL res = 0; for (int t = 0; t < territories.size(); ++t) { LL tmp = 0; for (int p = 0; p < territories[t].size(); ++p) { tmp += 1LL * (territories[t][p].right_corner.first - territories[t][p].left_corner.first)* (territories[t][p].right_corner.second - territories[t][p].left_corner.second); } res = max(res, tmp); } cout << res; 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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; struct Plot { PII left_corner; PII right_corner; }; vector<vector<Plot>> make_next_territory(int x1, int y1, int x2, int y2, int X, int Y) { int minX = min(x1, x2); int maxX = max(x1, x2); int minY = min(y1, y2); int maxY = max(y1, y2); vector<Plot> plots1; vector<Plot> plots2; vector<Plot> plots3; vector<Plot> plots4; Plot plot = { make_pair(minX, minY), make_pair(maxX, maxY) }; plots1.push_back(plot); if (minX > 0) { plot = { make_pair(0, minY), make_pair(minX, maxY) }; plots2.push_back(plot); } plot = { make_pair(maxX, minY), make_pair(X, maxY) }; plots2.push_back(plot); if (minY > 0) { plot = { make_pair(minX, 0), make_pair(maxX, minY) }; plots3.push_back(plot); } plot = { make_pair(minX, maxY), make_pair(maxX, Y) }; plots3.push_back(plot); if (minX > 0) { plot = { make_pair(0, maxY), make_pair(minX, Y) }; plots4.push_back(plot); } if (minY > 0) { plot = { make_pair(maxX, 0), make_pair(X, minY) }; plots4.push_back(plot); } if (minX > 0 && minY > 0) { plot = { make_pair(0, 0), make_pair(minX, minY) }; plots4.push_back(plot); } plot = { make_pair(maxX, maxY), make_pair(X, Y) }; plots4.push_back(plot); vector<vector<Plot>> next_territory{ plots1, plots2, plots3, plots4 }; return next_territory; } vector<vector<Plot>> make_new_territories(vector<vector<Plot>> territories, vector<vector<Plot>> next_territory) { vector<vector<Plot>> new_territories; for (int t1 = 0; t1 < territories.size(); ++t1) { for (int t2 = 0; t2 < next_territory.size(); ++t2) { vector<Plot> new_plots; for (int p1 = 0; p1 < territories[t1].size(); ++p1) { for (int p2 = 0; p2 < next_territory[t2].size(); ++p2) { int x1 = max(territories[t1][p1].left_corner.first, next_territory[t2][p2].left_corner.first); int y1 = max(territories[t1][p1].left_corner.second, next_territory[t2][p2].left_corner.second); int x2 = min(territories[t1][p1].right_corner.first, next_territory[t2][p2].right_corner.first); int y2 = min(territories[t1][p1].right_corner.second, next_territory[t2][p2].right_corner.second); if (x1 < x2 && y1 < y2) { Plot plot = { make_pair(x1, y1), make_pair(x2, y2) }; new_plots.push_back(plot); } } } if (new_plots.size() > 0) new_territories.push_back(new_plots); } } return new_territories; } int main() { int n, X, Y, x1, y1, x2, y2; cin >> n >> X >> Y; vector<vector<Plot>> territories(1, vector<Plot>(1)); territories[0][0].left_corner = make_pair(0, 0); territories[0][0].right_corner = make_pair(X, Y); for (int i = 0; i < n; ++i) { cin >> x1 >> y1 >> x2 >> y2; vector<vector<Plot>> next_territory = make_next_territory(x1, y1, x2, y2, X, Y); territories = make_new_territories(territories, next_territory); } LL res = 0; for (int t = 0; t < territories.size(); ++t) { LL tmp = 0; for (int p = 0; p < territories[t].size(); ++p) { tmp += 1LL * (territories[t][p].right_corner.first - territories[t][p].left_corner.first)* (territories[t][p].right_corner.second - territories[t][p].left_corner.second); } res = max(res, tmp); } cout << res; return 0; } |