#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <vector> #include <map> #include <string> #include <algorithm> #include <cassert> struct XCoord { int index; bool left; int val; XCoord(int i, bool left, int val) : index(i), left(left), val(val) {} bool operator< (const XCoord& xc) const { return val < xc.val; } }; struct YCoord { int index; bool bottom; int val; YCoord(int i, bool bottom, int val) : index(i), bottom(bottom), val(val) {} bool operator< (const YCoord& yc) const { return val < yc.val; } }; void adjust_sigx(std::string& sig, const XCoord& xc) { if (xc.index < 0) { return; } const char bef = sig.at(xc.index); char aft = 0; if (xc.left) { if (bef == 'O') { aft = 'V'; } else if (bef == 'H') { aft = 'I'; } } else { if (bef == 'I') { aft = 'H'; } else if (bef == 'V') { aft = 'O'; } } assert(aft != 0); sig.at(xc.index) = aft; } void adjust_sigy(std::string& sig, const YCoord& yc) { if (yc.index < 0) { return; } const char bef = sig.at(yc.index); char aft = 0; if (yc.bottom) { if (bef == 'O') { aft = 'H'; } else if (bef == 'V') { aft = 'I'; } } else { if (bef == 'I') { aft = 'V'; } else if (bef == 'H') { aft = 'O'; } } assert(aft != 0); sig.at(yc.index) = aft; } int main() { int rects, width, height; scanf("%d %d %d", &rects, &width, &height); std::vector<XCoord> xcoords = std::vector<XCoord>(); std::vector<YCoord> ycoords = std::vector<YCoord>(); xcoords.reserve(rects); ycoords.reserve(rects); for (int i = 0; i < rects; i++) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xcoords.push_back(XCoord(i, true, std::min(x1, x2))); xcoords.push_back(XCoord(i, false, std::max(x1, x2))); ycoords.push_back(YCoord(i, true, std::min(y1, y2))); ycoords.push_back(YCoord(i, false, std::max(y1, y2))); } xcoords.push_back(XCoord(-1, false, width)); ycoords.push_back(YCoord(-1, false, height)); std::sort(xcoords.begin(), xcoords.end()); std::sort(ycoords.begin(), ycoords.end()); std::string sig = std::string(rects, 'O'); std::map<std::string, int64_t> areas = std::map<std::string, int64_t>(); int prev_y = 0; for (const YCoord& yc : ycoords) { if (yc.val != prev_y) { int cur_y = yc.val; int prev_x = 0; for (const XCoord& xc : xcoords) { if (xc.val != prev_x) { int cur_x = xc.val; int64_t area = int64_t(cur_x - prev_x) * int64_t(cur_y - prev_y); if (areas.find(sig) == areas.end()) { areas.insert(std::pair<std::string, int64_t>(sig, 0)); } areas.at(sig) += area; prev_x = cur_x; } adjust_sigx(sig, xc); } prev_y = cur_y; } adjust_sigy(sig, yc); } int64_t max_area = 0; for (const std::pair<std::string, int64_t> pair : areas) { if (pair.second > max_area) { max_area = pair.second; } } printf("%lld", max_area); 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 | #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <vector> #include <map> #include <string> #include <algorithm> #include <cassert> struct XCoord { int index; bool left; int val; XCoord(int i, bool left, int val) : index(i), left(left), val(val) {} bool operator< (const XCoord& xc) const { return val < xc.val; } }; struct YCoord { int index; bool bottom; int val; YCoord(int i, bool bottom, int val) : index(i), bottom(bottom), val(val) {} bool operator< (const YCoord& yc) const { return val < yc.val; } }; void adjust_sigx(std::string& sig, const XCoord& xc) { if (xc.index < 0) { return; } const char bef = sig.at(xc.index); char aft = 0; if (xc.left) { if (bef == 'O') { aft = 'V'; } else if (bef == 'H') { aft = 'I'; } } else { if (bef == 'I') { aft = 'H'; } else if (bef == 'V') { aft = 'O'; } } assert(aft != 0); sig.at(xc.index) = aft; } void adjust_sigy(std::string& sig, const YCoord& yc) { if (yc.index < 0) { return; } const char bef = sig.at(yc.index); char aft = 0; if (yc.bottom) { if (bef == 'O') { aft = 'H'; } else if (bef == 'V') { aft = 'I'; } } else { if (bef == 'I') { aft = 'V'; } else if (bef == 'H') { aft = 'O'; } } assert(aft != 0); sig.at(yc.index) = aft; } int main() { int rects, width, height; scanf("%d %d %d", &rects, &width, &height); std::vector<XCoord> xcoords = std::vector<XCoord>(); std::vector<YCoord> ycoords = std::vector<YCoord>(); xcoords.reserve(rects); ycoords.reserve(rects); for (int i = 0; i < rects; i++) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xcoords.push_back(XCoord(i, true, std::min(x1, x2))); xcoords.push_back(XCoord(i, false, std::max(x1, x2))); ycoords.push_back(YCoord(i, true, std::min(y1, y2))); ycoords.push_back(YCoord(i, false, std::max(y1, y2))); } xcoords.push_back(XCoord(-1, false, width)); ycoords.push_back(YCoord(-1, false, height)); std::sort(xcoords.begin(), xcoords.end()); std::sort(ycoords.begin(), ycoords.end()); std::string sig = std::string(rects, 'O'); std::map<std::string, int64_t> areas = std::map<std::string, int64_t>(); int prev_y = 0; for (const YCoord& yc : ycoords) { if (yc.val != prev_y) { int cur_y = yc.val; int prev_x = 0; for (const XCoord& xc : xcoords) { if (xc.val != prev_x) { int cur_x = xc.val; int64_t area = int64_t(cur_x - prev_x) * int64_t(cur_y - prev_y); if (areas.find(sig) == areas.end()) { areas.insert(std::pair<std::string, int64_t>(sig, 0)); } areas.at(sig) += area; prev_x = cur_x; } adjust_sigx(sig, xc); } prev_y = cur_y; } adjust_sigy(sig, yc); } int64_t max_area = 0; for (const std::pair<std::string, int64_t> pair : areas) { if (pair.second > max_area) { max_area = pair.second; } } printf("%lld", max_area); return 0; } |