이 제출은 이전 버전의 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<vector<int>> atA(2 * d), atB(2 * 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<int> xs;
for (int i = 0; i < n; i++) {
xs.push_back(a[i][0]);
xs.push_back(a[i][0] + d);
atA[a[i][0]].push_back(i);
atA[a[i][0] + d].push_back(i);
}
for (int i = 0; i < m; i++) {
xs.push_back(b[i][0]);
xs.push_back(b[i][0] + d);
atB[b[i][0]].push_back(i + n);
atB[b[i][0] + d].push_back(i + n);
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), 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++) {
for (auto v : atA[xs[j]]) {
fType.insert(v);
}
for (auto v : atB[xs[j]]) {
sType.insert(v);
}
if ((int) fType.size() == n) {
ans = min(ans, Compute(xs[j] - xs[i]));
}
}
}
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... |