이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, d;
cin >> n >> m >> d;
vector<int> p(n), q(n);
for (int i = 0; i < n; ++i) {
cin >> p[i] >> q[i];
}
vector<int> r(m), s(m);
for (int i = 0; i < m; ++i) {
cin >> r[i] >> s[i];
}
int ans = d * d;
if (m <= 8) {
vector<int> p_nw, q_nw;
for (int i = 0; i < n; ++i) {
p_nw.push_back(p[i]);
p_nw.push_back(p[i] + d);
q_nw.push_back(q[i]);
q_nw.push_back(q[i] + d);
}
sort(p_nw.begin(), p_nw.end());
sort(q_nw.begin(), q_nw.end());
for (int mask = 0; mask < (1 << m); ++mask) {
int mnx = d, mny = d;
for (int i = 0; i < d; ++i) {
int posx = lower_bound(p_nw.begin(), p_nw.end(), i) - p_nw.begin();
int rx = p_nw[posx + n - 1] + 1;
for (int j = 0; j < m; ++j) {
if (mask & (1 << j)) {
if (i <= r[j]) {
rx = max(rx, r[j] + 1);
} else {
rx = max(rx, r[j] + d + 1);
}
}
}
mnx = min(mnx, rx - i);
int posy = lower_bound(q_nw.begin(), q_nw.end(), i) - q_nw.begin();
int ry = q_nw[posy + n - 1] + 1;
for (int j = 0; j < m; ++j) {
if (!(mask & (1 << j))) {
if (i <= s[j]) {
ry = max(ry, s[j] + 1);
} else {
ry = max(ry, s[j] + d + 1);
}
}
}
mny = min(mny, ry - i);
}
ans = min(ans, mnx * mny);
}
} else {
for (int lx = 0; lx < d; ++lx) {
for (int ly = 0; ly < d; ++ly) {
int rx = lx + 1, ry = ly + 1;
for (int i = 0; i < n; ++i) {
if (lx <= p[i]) {
rx = max(rx, p[i] + 1);
} else {
rx = max(rx, p[i] + d + 1);
}
if (ly <= q[i]) {
ry = max(ry, q[i] + 1);
} else {
ry = max(ry, q[i] + d + 1);
}
}
vector<int> inds(m);
iota(inds.begin(), inds.end(), 0);
sort(inds.begin(), inds.end(), [&](int i, int j) {
int ri = rx, rj = rx;
if (lx <= r[i]) {
ri = max(ri, r[i] + 1);
} else {
ri = max(ri, r[i] + d + 1);
}
if (lx <= r[j]) {
rj = max(rj, r[j] + 1);
} else {
rj = max(rj, r[j] + d + 1);
}
return ri < rj;
});
vector<int> rys(m + 1);
rys[m] = ry;
for (int i = m - 1; i >= 0; --i) {
int vl = 0;
if (ly <= s[inds[i]]) {
vl = s[inds[i]] + 1;
} else {
vl = s[inds[i]] + d + 1;
}
rys[i] = max(rys[i + 1], vl);
}
for (int i = 0; i < m; ++i) {
ans = min(ans, (rx - lx) * (rys[i] - ly));
if (lx <= r[inds[i]]) {
rx = max(rx, r[inds[i]] + 1);
} else {
rx = max(rx, r[inds[i]] + d + 1);
}
}
ans = min(ans, (rx - lx) * (rys[m] - ly));
}
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
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... |