# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158741 | vanic | SIR (COI15_sir) | C++14 | 223 ms | 20064 KiB |
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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=3e5+5;
pair < ll, ll > l[maxn];
pair < ll, ll > svi[maxn];
vector < pair < ll, ll > > bitne;
vector < pair < ll, ll > > ost;
ll hull(pair < ll, ll > a, pair < ll, ll > b, pair < ll, ll > c){
return a.first*(b.second-c.second)+b.first*(c.second-a.second)+c.first*(a.second-b.second);
}
int main(){
int n;
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%lld%lld", &l[i].first, &l[i].second);
}
int m;
scanf("%d", &m);
for(int i=0; i<m; i++){
scanf("%lld%lld", &svi[i].first, &svi[i].second);
}
sort(svi, svi+m);
for(int i=0; i<m; i++){
while(bitne.size()>1 && hull(bitne[bitne.size()-2], bitne.back(), svi[i])<=0){
bitne.pop_back();
}
bitne.push_back(svi[i]);
}
for(int i=m-1; i>-1; i--){
while(ost.size()>1 && hull(ost[ost.size()-2], ost.back(), svi[i])<=0){
ost.pop_back();
}
ost.push_back(svi[i]);
}
for(int i=1; i<ost.size()-1; i++){
bitne.push_back(ost[i]);
}
int sz=bitne.size();
/* printf("%d\n", sz);
for(int i=0; i<sz; i++){
printf("%lld %lld\n", bitne[i].first, bitne[i].second);
}*/
int pos1=0, pos2=0;
ll mini=1e10;
for(int i=0; i<sz; i++){
if(mini>abs(l[0].first-bitne[i].first)+abs(l[0].second-bitne[i].second)){
mini=abs(l[0].first-bitne[i].first)+abs(l[0].second-bitne[i].second);
pos1=i;
}
}
ll sum=0;
ll maksi=0;
int pos3;
for(int i=0; i<n; i++){
while(hull(l[i], bitne[(pos1+1)%sz], bitne[pos1])>0){
pos1=(pos1+1)%sz;
}
while(hull(l[i], l[(pos2+1)%n], bitne[pos1])>0){
sum+=hull(l[i], l[pos2], l[(pos2+1)%n]);
pos2=(pos2+1)%n;
}
pos3=(i+1)%n;
maksi=max(maksi, sum);
sum-=hull(l[i], l[pos3], l[pos2]);
}
printf("%lld\n", maksi);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |