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>
#define int long long
using namespace std;
int N, M, total=0, vis=0;
vector<pair<int, int> > bigger;
vector<pair<int, int> > smaller;
vector<pair<int, int> > p;
int bell=1, ans=0;
bool check(pair<int, int> a, pair<int, int> b, pair<int, int> c){
return ((b.first-a.first)*(c.second-a.second)-(c.first-a.first)*(b.second-a.second))>0;
}
bool chack(pair<int, int> a, pair<int, int> b, pair<int, int> c){
return ((b.first-a.first)*(c.second-a.second)-(c.first-a.first)*(b.second-a.second))<=0;
}
int get(pair<int, int> a, pair<int, int> b, pair<int, int> c){
return abs(a.first*(b.second-c.second)+b.first*(c.second-a.second)+c.first*(a.second-b.second));
}
bool trapp(pair<int, int> a, int ind){
int x=ind, y;
if(ind==smaller.size()-1){
y=0;
}else{
y=x+1;
}
return chack(a, smaller[x], smaller[y]);
}
bool troll(pair<int, int> a, int ind){
int x=ind, y;
if(ind==0){
y=smaller.size()-1;
}else{
y=x-1;
}
return chack(a, smaller[x], smaller[y]);
}
void solve(){
sort(p.begin(), p.end());
smaller.push_back(p[0]);
for(int i=1; i<M; i++){
while(smaller.size()>=2 && check(smaller[smaller.size()-2], smaller[smaller.size()-1], p[i])){
smaller.pop_back();
}
smaller.push_back(p[i]);
}
for(int i=M-2; i>=0; i--){
while(smaller.size()>=2 && check(smaller[smaller.size()-2], smaller[smaller.size()-1], p[i])){
smaller.pop_back();
}
smaller.push_back(p[i]);
}
if(M>1) smaller.pop_back();
}
signed main(){
cin>>N;
for(int i=1; i<=N; i++){
int x, y; cin>>x>>y; bigger.push_back({x, y});
}
reverse(bigger.begin(), bigger.end());
cin>>M;
for(int i=1; i<=M; i++){
int x, y; cin>>x>>y; p.push_back({x, y});
}
solve(); M=smaller.size();
for(int i=0; i<M; i++){
if(trapp(bigger[0], i) && troll(bigger[0], i)){
vis=i; break;
}
}
for(int i=0; i<bigger.size(); i++){
while(!(trapp(bigger[i], vis) && troll(bigger[i], vis))){
vis++; vis%=smaller.size();
}
if(i){
int x=i-1;
if(x==-1) x=N-1;
int y=bell-1;
if(y==-1) y=N-1;
ans-=get(bigger[x], bigger[i], bigger[y]);
}
for(bell; check(bigger[i], smaller[vis], bigger[bell]); bell++, bell%=N){
int x=bell-1;
if(x==-1) x=N-1;
ans+=get(bigger[i], bigger[x], bigger[bell]);
}
total=max(total, ans);
}
cout<<total;
}
Compilation message (stderr)
sir.cpp: In function 'bool trapp(std::pair<long long int, long long int>, long long int)':
sir.cpp:20:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if(ind==smaller.size()-1){
| ~~~^~~~~~~~~~~~~~~~~~
sir.cpp: In function 'int main()':
sir.cpp:69:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0; i<bigger.size(); i++){
| ~^~~~~~~~~~~~~~
sir.cpp:80:7: warning: statement has no effect [-Wunused-value]
80 | for(bell; check(bigger[i], smaller[vis], bigger[bell]); bell++, bell%=N){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |