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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct rect {
ll l, r, b, t;
};
ll w, h, b, n;
vector<rect> p;
vector<ll> bL;
bool poss(ll goal) {
for (auto &l : bL) {
ll r = l + goal - 1;
if (r > w) break;
vector<pair<ll, ll>> ranges = {{1, h}};
ll numBig = ((h-1) >= (r-l));
for (auto &rect : p) {
if (rect.r < l || rect.l > r) continue;
for (int i = ranges.size()-1; i >= 0; i--) {
bool big = (ranges[i].second-ranges[i].first) >= (r-l);
if (!big) continue;
if (rect.t >= ranges[i].second) {
ranges[i].second = min(ranges[i].second, rect.b-1);
if ((ranges[i].second-ranges[i].first) < (r-l)) numBig--;
}
else if (rect.b <= ranges[i].first) {
ranges[i].first = max(ranges[i].first, rect.t+1);
if ((ranges[i].second-ranges[i].first) < (r-l)) numBig--;
}
else if (rect.t < ranges[i].second && rect.b > ranges[i].first) {
numBig++;
ranges.push_back({ranges[i].first, min(ranges[i].second, rect.b-1)});
ranges[i].first = max(ranges[i].first, rect.t+1);
if ((ranges.back().second-ranges.back().first) < (r-l)) numBig--;
if ((ranges[i].second-ranges[i].first) < (r-l)) numBig--;
}
}
if (numBig <= 0) break;
}
if (numBig > 0) return true;
}
return false;
}
int main() {
cin >> w >> h >> b >> n;
p = vector<rect>(n);
bL = {1};
for (auto &e : p) {
ll l, b, r, t, c;
cin >> l >> b >> r >> t >> c;
e = {l, r, b, t};
bL.push_back(r+1);
}
sort(bL.begin(), bL.end());
ll left = 0, right = min(w, h);
while (left < right) {
ll mid = (left+right+1) / 2;
if (poss(mid)) {
left = mid;
}
else {
right = mid-1;
}
}
cout << left;
}
# | 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... |
# | 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... |