이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<vector<int>> locA(2 * d), locB(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);
locA[a[i][1]].push_back(i);
locA[a[i][1] + 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);
locB[b[i][1]].push_back(i + n);
locB[b[i][1] + 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++) {
vector<bool> fType(n);
vector<bool> sType(n + m);
int cur = 0;
auto Compute = [&](int hori) {
vector<int> ys;
int cnt = 0;
for (int j = 0; j < n; j++) {
ys.push_back(a[j][1]);
ys.push_back(a[j][1] + d);
++cnt;
}
for (int j = 0; j < m; j++) {
if (!sType[j + n]) {
++cnt;
ys.push_back(b[j][1]);
ys.push_back(b[j][1] + d);
}
}
sort(ys.begin(), ys.end());
ys.erase(unique(ys.begin(), ys.end()), ys.end());
vector<int> st_cnt(n + m);
int counter = 0;
int vert = 12345;
int high = 0;
for (int id = 0; id < (int) ys.size(); id++) {
while (high < (int) ys.size()) {
for (auto v : locA[ys[high]]) {
st_cnt[v] += 1;
if (st_cnt[v] == 1) {
++counter;
}
}
for (auto v : locB[ys[high]]) {
st_cnt[v] += 1;
if (st_cnt[v] == 1) {
++counter;
}
}
if (counter == cnt) {
vert = min(vert, ys[high] - ys[id]);
high++;
break;
}
++high;
}
for (auto v : locA[ys[id]]) {
st_cnt[v] -= 1;
if (st_cnt[v] == 0) {
--counter;
}
}
for (auto v : locB[ys[id]]) {
st_cnt[v] -= 1;
if (st_cnt[v] == 0) {
--counter;
}
}
}
int area = (hori + 1) * (vert + 1);
return area;
};
for (int j = i; j < (int) xs.size(); j++) {
for (auto v : atA[xs[j]]) {
cur += (!fType[v]);
fType[v] = true;
}
for (auto v : atB[xs[j]]) {
sType[v] = true;
}
if (cur == 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... |