QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#306880 | #3139. Largest Quadrilateral | xx019 | AC ✓ | 1027ms | 4076kb | C++14 | 3.4kb | 2024-01-17 14:56:06 | 2024-01-17 14:56:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
struct Point{
int x,y;
Point(const int &_x=0,const int &_y=0):x(_x),y(_y){}
inline Point operator +(const Point &o){return Point(x+o.x,y+o.y);}
inline Point operator -(const Point &o){return Point(x-o.x,y-o.y);}
inline Point operator *(const int &k){return Point(x*k,y*k);}
};
ll dot(Point a,Point b){return 1ll*a.x*b.x+1ll*a.y*b.y;}
ll det(Point a,Point b){return 1ll*a.x*b.y-1ll*a.y*b.x;}
int st[5005],used[5005];
vector<Point>ConvexHull(vector<Point>poly){
int top=0,len=(int)poly.size();vector<Point>convex;
sort(poly.begin(),poly.end(),[](Point x,Point y){
return tie(x.x,x.y)<tie(y.x,y.y);
});
st[++top]=0;
for(int i=1;i<len;i++){
while(top>=2&&det(poly[st[top]]-poly[st[top-1]],poly[i]-poly[st[top]])<=0)top--;
st[++top]=i;
}
for(int i=1;i<=top;i++)if(!used[st[i]])convex.push_back(poly[st[i]]),used[st[i]]=1;
top=0;st[++top]=len-1;
for(int i=len-2;i>=0;i--){
while(top>=2&&det(poly[st[top]]-poly[st[top-1]],poly[i]-poly[st[top]])<=0)top--;
st[++top]=i;
}
for(int i=1;i<=top;i++)if(!used[st[i]])convex.push_back(poly[st[i]]),used[st[i]]=1;
for(int i=0;i<len;i++)used[i]=0;
return convex;
}
ll GetArea(vector<Point>poly){
int len=(int)poly.size();
if(len<=2)return 0;
ll res=0;
for(int i=0;i<len;i++)res+=det(poly[i],poly[(i+1)%len]);
return abs(res);
}
ll RotatingCalipers(vector<Point>poly,vector<Point>p){
int len=(int)poly.size();
// for(auto x:poly)printf("%lld %lld\n",x.x,x.y);
if(len<=2)return 0;
if(len==3){
int f0=0,f1=0,f2=0;ll res=0,sum=GetArea(poly);
// printf("{%lld}\n",sum);
for(auto x:p){
if(x.x==poly[0].x&&x.y==poly[0].y){
if(!f0){f0=1;continue;}
return sum;
}
if(x.x==poly[1].x&&x.y==poly[1].y){
if(!f1){f1=1;continue;}
return sum;
}
if(x.x==poly[2].x&&x.y==poly[2].y){
if(!f2){f2=1;continue;}
return sum;
}
res=max(res,sum-GetArea({poly[0],poly[1],x}));
res=max(res,sum-GetArea({poly[1],poly[2],x}));
res=max(res,sum-GetArea({poly[2],poly[0],x}));
// printf("(%lld,%lld){%lld,%lld,%lld}\n",x.x,x.y,GetArea({poly[0],poly[1],x}),GetArea({poly[1],poly[2],x}),GetArea({poly[2],poly[0],x}));
}
return res;
}
ll res=0;
for(int i=0;i<len;i++){
for(int j=(i+2)%len,a=(i+1)%len,b=j;(j+1)%len!=i;j=(j+1)%len){
if(b==j)b=(b+1)%len;
while((a+1)%len!=j&&abs(det(poly[i],poly[a])+det(poly[a],poly[j])+det(poly[j],poly[i]))<=abs(det(poly[i],poly[(a+1)%len])+det(poly[(a+1)%len],poly[j])+det(poly[j],poly[i])))a=(a+1)%len;
while((b+1)%len!=i&&abs(det(poly[i],poly[b])+det(poly[b],poly[j])+det(poly[j],poly[i]))<=abs(det(poly[i],poly[(b+1)%len])+det(poly[(b+1)%len],poly[j])+det(poly[j],poly[i])))b=(b+1)%len;
res=max(res,abs(det(poly[i],poly[a])+det(poly[a],poly[j])+det(poly[j],poly[b])+det(poly[b],poly[i])));
}
}
return res;
}
void solve(){
int n=read();vector<Point>p;
for(int i=1;i<=n;i++){
int x=read(),y=read();
p.push_back(Point(x,y));
}
vector<Point>convex=ConvexHull(p);
ll ans=RotatingCalipers(convex,p);
if(ans%2==0)printf("%lld\n",ans/2);
else printf("%lld.5\n",ans/2);
}
signed main(){
int T=read();
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
3 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1 4 0 0 1 1 2 2 1 1
output:
3 6 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 4 0 0 1 0 0 1 3 2
output:
2.5
result:
ok single line: '2.5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
3 4 0 0 0 0 0 0 0 0 5 0 0 1 0 3 1 1 2 0 1 4 0 0 4 0 0 4 1 1
output:
0 3 6
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
3 4 0 0 1 1 2 2 1 1 5 0 0 3 3 1 1 4 4 2 2 6 0 0 0 4 4 0 0 0 1 1 1 2
output:
0 0 8
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
3 6 0 0 8 8 7 9 6 9 5 8 0 99 29 999891293 708205 369022896 771 993004062 999827531 929592437 29458 994968624 999539287 569046020 1943 2200 986643253 11189 5792636 712825 999917190 2482686 272282 43058 665660 10373878 31825 508452623 112 3304 269412577 43817590 3789 999996618 957802194 999902626 9749...
output:
388 996775018731291724.5 965005706567704502.5
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 1027ms
memory: 3824kb
input:
3 4096 53819837 441491349 842988334 208694314 834815184 199336081 754579314 871065186 798603871 163346278 881287987 261003199 69176974 629967383 167500703 196776949 934427498 382642646 949669136 517253054 205028216 839840619 904403509 697377307 909983630 685508552 106436006 718191161 704172704 90101...
output:
405000001187842381 405000001187842381 405000001187842381
result:
ok 3 lines