This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, d;
cin >> n >> m >> d;
vector<array<int, 2>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
n = (int) a.size();
vector<array<int, 2>> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i][0] >> b[i][1];
}
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
m = (int) b.size();
vector<array<int, 2>> xs;
for (int i = 0; i < n; i++) {
xs.push_back({a[i][0], i});
xs.push_back({a[i][0] + d, i});
}
for (int i = 0; i < m; i++) {
xs.push_back({b[i][0], i + n});
xs.push_back({b[i][0] + d, i + n});
}
sort(xs.begin(), xs.end());
int ans = 123456789;
for (int i = 0; i < (int) xs.size(); i++) {
set<int> fType;
set<int> sType;
auto Compute = [&](int hori) {
vector<array<int, 2>> ys;
int cnt = 0;
for (int j = 0; j < n; j++) {
ys.push_back({a[j][1], j});
ys.push_back({a[j][1] + d, j});
++cnt;
}
for (int j = 0; j < m; j++) {
if (!sType.count(j + n)) {
++cnt;
ys.push_back({b[j][1], j + n});
ys.push_back({b[j][1] + d, j + n});
}
}
sort(ys.begin(), ys.end());
int vert = 12345;
set<int> st;
map<int, int> st_cnt;
int high = 0;
for (int id = 0; id < (int) ys.size(); id++) {
while (high < (int) ys.size()) {
st.insert(ys[high][1]);
st_cnt[ys[high][1]]++;
if ((int) st.size() == cnt) {
vert = min(vert, ys[high][0] - ys[id][0]);
high++;
break;
}
++high;
}
st_cnt[ys[id][1]]--;
if (st_cnt[ys[id][1]] == 0) {
st.erase(ys[id][1]);
}
}
int area = (hori + 1) * (vert + 1);
return area;
};
for (int j = i; j < (int) xs.size(); j++) {
if (xs[j][1] < n) {
fType.insert(xs[j][1]);
} else {
sType.insert(xs[j][1]);
}
if ((int) fType.size() == n) {
ans = min(ans, Compute(xs[j][0] - xs[i][0]));
}
}
}
cout << ans << '\n';
return 0;
}
# | 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... |