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 ii pair<int,int>
const int N=6e5+5;
int n,m;
struct p{
int x,y;
};
p a[N],b[N];
vector<p> dinh;
bool cmp(p i,p j){
if(i.x==j.x) return i.y<j.y;
return i.x<j.x;
}
vector<p> baoloi;
//ben trai thi tra ve true
bool check1(p a,p b,p c){
return (b.x-a.x) *(c.y-a.y)-(c.x-a.x)*(b.y-a.y)>=0;
}
bool check(p a,p b,p c){
return (b.x-a.x) *(c.y-a.y)-(c.x-a.x)*(b.y-a.y)>0;
}
void convexhull(){
sort(dinh.begin(),dinh.end(),cmp);
baoloi.push_back(dinh[0]);
for(int i=1;i<m;i++){
while(baoloi.size()>=2&&check(baoloi[baoloi.size()-2],baoloi[baoloi.size()-1],dinh[i])) baoloi.pop_back();
baoloi.push_back(dinh[i]);
}
for(int i=m-2;i>=0;i--){
while(baoloi.size()>=2&&check(baoloi[baoloi.size()-2],baoloi[baoloi.size()-1],dinh[i])) baoloi.pop_back();
baoloi.push_back(dinh[i]);
}
if(baoloi.size()>1) baoloi.pop_back();
}
int id=0;
int kt(p x,p y,p z){
if(x.x==y.x&&x.y==y.y) return 1;
if(!check(x,y,baoloi[id])&&!check(y,z,baoloi[id])&&!check(z,x,baoloi[id])) return 0;
return 1;
}
int get(p a, p b, p c){
if(a.x==b.x&&a.y==b.y) return 0;
return abs(a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y));
}
p luu[N];
int cross(p a, p b){
return a.x*b.y-b.x*a.y;
}
p operator - (p a, p b){
return {a.x-b.x,a.y-b.y};
}
int s[N+10];
signed main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>luu[i].x>>luu[i].y;
}
for(int i=n-1;i>=0;i--){
a[i]=luu[n-1-i];
}
for (int i=0;i<n;i++) a[n+i] = a[i-1]; a[2*n] = a[0];
for (int i=0;i<=2*n;i++) s[i+1] =s[i]+ cross(a[i],a[i+1]);
cin>>m;
for(int i=1;i<=m;i++){
cin>>b[i].x>>b[i].y;
dinh.push_back({b[i].x,b[i].y});
}
convexhull();
int sz=baoloi.size();
// for(p i:baoloi){
// cout<<i.x<<" "<<i.y<<endl;
// }
int r=1;
int res=0;
int ans=-1e18;
for(int i=0;i<sz;i++){
if(check(a[0],baoloi[id],baoloi[i])) id=i;
}
for(int i=0;i<n;i++){
while(!(cross(baoloi[id]-a[i],baoloi[(id+1)%sz]-a[i])<=0)){
id++;
id%=sz;
}
//cout<<i<<" "<<baoloi[id].x<<" "<<baoloi[id].y<<endl;
while(cross(a[r+1]-a[i],baoloi[id]-a[i])<0){
//congdientich
ans = max(abs(s[r+1+1]-s[i+1]+cross(a[r+1],a[i])),ans);
// cout <<i<<" "<<r+1<<" "<<s[r+1]<<" "<<s[i]<<" "<<cross(a[r+1],a[i])<<endl;
r++;
}
ans=max(ans,res);
}
cout<<ans;
}
//>1 4
//>2 4
//>3 0
//>4 1
//>5 3
Compilation message (stderr)
sir.cpp: In function 'int main()':
sir.cpp:68:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
68 | for (int i=0;i<n;i++) a[n+i] = a[i-1]; a[2*n] = a[0];
| ^~~
sir.cpp:68:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
68 | for (int i=0;i<n;i++) a[n+i] = a[i-1]; a[2*n] = a[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... |