This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
int n, m, D;
vector<int> p, q;
vector<int> r, s;
vector<bool> xxx(10005, false), yyy(5005, false);
bool can(int i) {
return (i>=0 && i<2*D+5);
}
void build(vector<int> &yy, set<int> qq) {
for (auto u=qq.begin(); u!=qq.end(); u++) {
auto v=++u;
--u;
if (v==qq.end()) {
yy[D-(*u-*qq.begin()+1)]++;
} else {
yy[*v-*u-1]++;
}
}
}
int subtask5() {
//vector<pair<int, int>> x;
vector<vector<int>> x(2*D+5);
set<int> y;
for (int i=0; i<5005; i++) {
int u=yyy[i];
if (u) y.insert(i);
}
vector<int> yy(2*D+5, 0);
build(yy, y);
int emply=2*D+4;;
while (emply>0 && yy[emply]<=0) emply--;
int ans=D*D;
for (int i=0; i<m; i++) x[r[i]].push_back(s[i]), x[r[i]+D].push_back(s[i]);
for (auto &u: x) sort(u.begin(), u.end());
for (int a=0; a<D; a++) {
auto lsty=y;
auto lstyy=yy;
auto lstemply=emply;
int szy=D-emply;
int empl=a+D-1;
for (;; empl--) {
ans=min(ans, (empl-a+1)*szy);
if (xxx[empl]) break;
for (auto value: x[empl]) {
auto tempy=y.lower_bound(value);
if (tempy==y.end() || *tempy!=value) {
if (tempy==y.end()) {
auto prec=y.end(), next=y.begin();
prec--;
int act=D-(*prec-*next+1);
if (can(act)) yy[act]--;
if (can(D-(value-*next+1))) yy[D-(value-*next+1)]++;
if (can(value-*prec-1)) yy[value-*prec-1]++;
} else if (tempy==y.begin()) {
auto prec=y.begin(), next=y.end();
next--;
int act=D-(*next-*prec+1);
if (can(act)) yy[act]--;
if (can(D-(*next-value+1))) yy[D-(*next-value+1)]++;
if (can(value-*prec-1)) yy[value-*prec-1]++;
} else {
auto next=tempy, prec=--tempy;
int act=*next-*prec-1;
if (can(act)) yy[act]--;
if (can(*next-value-1)) yy[*next-value-1]++;
if (can(value-*prec-1)) yy[value-*prec-1]++;
}
y.insert(value);
}
}
while (emply>0 && yy[emply]<=0) emply--;
szy=D-emply;
}
y=lsty;
yy=lstyy;
emply=lstemply;
}
return ans;
}
int solve() {
cin >> n >> m >> D;
p.resize(n);
q.resize(n);
for (int i=0; i<n; i++) {
cin >> p[i] >> q[i];
xxx[p[i]]=true;
yyy[q[i]]=true;
xxx[p[i]+D]=true;
}
vector<pair<int, int>> temp;
for (int i=0; i<m; i++) {
int a, b; cin >> a >> b;
if (xxx[a] || yyy[b]) continue;
temp.push_back({a, b});
}
sort(temp.begin(), temp.end());
m=sz(temp);
r.clear(), s.clear();
for (auto u: temp) r.push_back(u.first), s.push_back(u.second);
return subtask5();
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << solve() << endl;
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... |