이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//被嗆
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#pragma GCC optimize("Ofast")
#define fs first
#define sc second
int n, m, d;
struct special_set {
set<int> sts;
multiset<int> mst;
int cnt[10010] = {0};
int query () {
if (mst.empty ()) return 1;
int z = *mst.rbegin();
z = max(z, *sts.begin() + d - *sts.rbegin());
return d - z + 1;
}
void add (int x) {
if (x >= d) return;
cnt[x]++;
if (cnt[x] != 1) return;
auto zz = sts.insert(x);
auto it = zz.first;
if (next(it) != sts.end() and it != sts.begin()) mst.erase(mst.find(*next(it) - *prev(it)));
if (next(it) != sts.end()) mst.insert(*next(it) - x);
if (it != sts.begin()) mst.insert(x - *prev(it));
}
void del (int x) {
if (x >= d) return;
cnt[x]--;
auto it = sts.find(x);
if (cnt[x] != 0) return;
if (next(it) != sts.end() and it != sts.begin()) mst.insert(*next(it) - *prev(it));
if (next(it) != sts.end()) mst.erase(mst.find(*next(it) - x));
if (it != sts.begin()) mst.erase(mst.find(x - *prev(it)));
sts.erase(it);
}
}stx, sty;
pii a[5010], b[10010];
int ans = INT_MAX;
int main () {
ios_base :: sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> d;
for (int i = 0; i < n; i++) {
cin >> a[i].fs >> a[i].sc;
stx.add(a[i].fs);
stx.add(a[i].fs + d);
sty.add(a[i].sc);
sty.add(a[i].sc + d);
}
for (int i = 0; i < m; i++) {
cin >> b[i].fs >> b[i].sc;
sty.add(b[i].sc);
sty.add(b[i].sc + d);
}
ans = min(ans, stx.query() * sty.query());
// for (int x : sty.mst) cout << x << ' ';
// cout << '\n';
// for (int x : sty.sts) cout << x << ' ';
// cout << '\n';
sort(b, b + m);
for (int i = 0; i < m; i++) b[i + m] = b[i];
for (int i = 0; i < m; i++) {
// cout << "!" << ' ' << stx.query() << ' ' << sty.query() << '\n';
for (int j = 0; j < m; j++) {
stx.add(b[i + j].fs);
stx.add(b[i + j].fs + d);
sty.del(b[i + j].sc);
sty.del(b[i + j].sc + d);
// cout << i << ' ' << j << ' ' << stx.query() << ' ' << sty.query() << ' ' << stx.query() * sty.query() << '\n';
ans = min(ans, stx.query() * sty.query());
}
for (int j = 0; j < m; j++) {
stx.del(b[i + j].fs);
stx.del(b[i + j].fs + d);
sty.add(b[i + j].sc);
sty.add(b[i + j].sc + d);
}
}
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... |