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 pii pair<int, int>
int n, m, d;
vector<pii> vecn;
vector<pii> vecm;
set<int> h_important;
set<int> w_important;
signed main(){
cin>>n>>m>>d;
for(int i = 0; i<n; i++){
pii v;
cin>>v.second>>v.first;
vecn.push_back(v);
h_important.insert(v.first);
w_important.insert(v.second);
}
for(int i = 0; i<m; i++){
pii v;
cin>>v.second>>v.first;
vecm.push_back(v);
h_important.insert(v.first);
w_important.insert(v.second);
}
sort(vecn.begin(), vecn.end());
deque<int> vn;
for(auto e: vecn){
vn.push_back(e.first);
}
int res= 1e18;
sort(vecm.begin(), vecm.end());
deque<pii> vm;
for(auto e: vecm){
vm.push_back(e);
}
for(auto i: h_important){
deque<int> hn;
auto cmp = [&](pii&a, pii& b){
return a.second<b.second;
};
sort(vecn.begin(), vecn.end(), cmp);
for(auto e: vecn){
hn.push_back(e.second);
}
for(auto j: w_important){
//cout<<i<<" "<<j<<endl;
int cvm =vm.size()-1;
int h = max(vn.back(), vm[cvm].first);
int w= hn.back();
res= min(res, (h-i+1)*(w-j+1));
while(cvm>0){
pii last=vm[cvm];
if(j>last.second){
last.second+=d;
}
cvm--;
w= max(w, last.second);
h= vn.back();
if(cvm>0){
h =max(h, vm[cvm].first);
}
res= min(res, (h-i+1)*(w-j+1));
}
/*cout<<"vn"<<endl;
for(auto e: vn){
cout<<e<<" ";
}
cout<<endl;
cout<<"hn"<<endl;
for(auto e: hn){
cout<<e<<" ";
}
cout<<endl;*/
while(hn.size()>0 && hn.front()==j){
int cur= hn.front();
hn.pop_front();
hn.push_back(cur+d);
}
}
while(vn.size()>0 && vn.front()==i){
int cur= vn.front();
vn.pop_front();
vn.push_back(cur+d);
}
while(vm.size()>0 && vm.front().first==i){
pii cur= vm.front();
vm.pop_front();
vm.push_back({cur.first+d, cur.second});
}
}
cout<<res<<endl;
}
# | 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... |