이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
auto Compute = [&](int l, int r) {
if (r >= (int) xs.size()) {
return 123456789;
}
set<int> fType;
set<int> sType;
for (int i = l; i <= r; i++) {
if (xs[i][1] < n) {
fType.insert(xs[i][1]);
} else {
sType.insert(xs[i][1]);
}
}
if ((int) fType.size() < n) {
return 123456789;
}
int hori = xs[r][0] - xs[l][0];
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 i = 0; i < (int) xs.size(); i++) {
int low = i, high = (int) xs.size() - 1;
while (high - low >= 5) {
int mid = low + (high - low) / 2;
if (Compute(i, mid) >= Compute(i, mid + 1)) {
low = mid;
} else {
high = mid + 1;
}
}
for (int it = low + 1; it <= high; it++) {
if (Compute(i, low) > Compute(i, it)) {
low = it;
}
}
ans = min(ans, Compute(i, low));
}
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... |