QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725350#9520. Concave HullqvzeyangWA 1ms7952kbC++232.8kb2024-11-08 17:13:532024-11-08 17:13:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 17:13:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7952kb
  • [2024-11-08 17:13:53]
  • 提交

answer

#include<bits/stdc++.h>
namespace FRTMLV{
	// #define int ll
#define ll long long 
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1e5+5;
int rd(){int d=1,k=0;char c=getchar();
while(!(c>='0' and c<='9' or c=='-'))c=getchar();if(c=='-')d=-1,c=getchar();
while(c>='0' and c<='9')k=(k<<3)+(k<<1)+(c^48),c=getchar();return d*k;}
int n,cnt1,cnt2,bk[N];
struct node{
	ll x,y;
	bool operator <(const node &a)const{re x==a.x?y>a.y:x<a.x;}
}p[N],h1[N],h2[N];
node operator -(const node &a,const node &b){
	return (node){a.x-b.x,a.y-b.y};
}
inline ll gtx(node a,node b){
	ll ans=(ll)a.x*b.y-(ll)b.x*a.y;
	if(ans<0)ans=-ans;
	re ans;
}
inline LD gtk(int a,int b){
	if(p[a].x==p[b].x){
		re p[a].y>p[b].y?0x3f3f3f3f:-0x3f3f3f3f;
	}
	re (LD)(p[a].y-p[b].y)/(p[a].x-p[b].x);
}
int q[N],hd,tl;
int tmp[N];
void gth(node *h,int &cnt){
	memset(tmp+1,0,sizeof tmp[0]*n);
	hd=tl=0;
	for(int i=1;i<=n;i++){
		if(bk[i])con;
		while(hd+1<tl&&gtk(i,q[tl-2])>gtk(q[tl-1],q[tl-2]))--tl;
		q[tl++]=i;
	}
	for(int i=hd;i<tl;i++)h[++cnt]=p[q[i]],tmp[q[i]]=1;
	hd=tl=0;

	for(int i=1;i<=n;i++){
		if(bk[i])con;
		while(hd+1<tl&&gtk(i,q[tl-2])<gtk(q[tl-1],q[tl-2]))--tl;
		q[tl++]=i;
	}
	for(int i=tl-2;i>hd;i--)h[++cnt]=p[q[i]],bk[q[i]]=1;
	for(int i=1;i<=n;i++)
		if(tmp[i]==1)bk[i]=1;
}
signed main(){
	int T=rd();
	while(T--){
		n=rd(),cnt1=cnt2=0;
		memset(bk+1,0,sizeof bk[0]*n);
		for(int i=1;i<=n;i++){
			int x=rd(),y=rd();
			p[i]={x,y};
		}
		sort(p+1,p+n+1);
		gth(h1,cnt1);
		gth(h2,cnt2);

		// for(int i=1;i<=cnt1;i++)printf("[%lld,%lld]\n",h1[i].x,h1[i].y);
		// for(int i=1;i<=cnt2;i++)printf("{%lld,%lld}\n",h2[i].x,h2[i].y);


		if(!cnt2){
			puts("-1");
			con;
		}
		ll ans=0x3f3f3f3f3f3f3f3f;
		int nw=0;
		h1[cnt1+1]=h1[1],h2[cnt2+1]=h2[1];

		if(cnt2<=3){
			for(int i=1;i<=cnt1;i++)
				for(int j=1;j<=cnt2;j++)ckmin(ans,gtx(h1[i]-h2[j],h1[i+1]-h2[j]));
		}
		else{
			for(int i=1;i<=cnt2;i++){
				if(ckmin(ans,gtx(h1[1]-h2[i],h1[2]-h2[i])))nw=i;
			}

			for(int i=2;i<=cnt1;i++){
				while(gtx(h1[i]-h2[nw],h1[i+1]-h2[nw])>gtx(h1[i]-h2[nw+1],h1[i+1]-h2[nw+1])){
					++nw;
					if(nw>cnt2)nw=1;
				}
				ckmin(ans,gtx(h1[i]-h2[nw],h1[i+1]-h2[nw]));
			}
		}
		ans=-ans;

		// ll xx=0;

		for(int i=2;i<n;i++){
			ans+=gtx(h1[i]-h1[1],h1[i+1]-h1[1]);
			// xx+=gtx(h1[i]-h1[1],h1[i+1]-h1[1]);
		}
		// printf("%lld\n",xx);
		printf("%lld\n",ans);
	}
	re 0; 
}
/*
g++ FTL.cpp -o FTL.exe -std=c++14 -Wall  -O2


2
4
0 0
1 0
0 1
1 1
6
-2 0
1 -2
5 2
0 4
1 2
3 1


*/
}signed main(){re FRTMLV::main();}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7924kb

input:

2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1

output:

40
-1

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 7952kb

input:

10
243
-494423502 -591557038
-493438474 -648991734
-493289308 -656152126
-491185085 -661710614
-489063449 -666925265
-464265894 -709944049
-447472922 -737242534
-415977509 -773788538
-394263365 -797285016
-382728841 -807396819
-373481975 -814685302
-368242265 -818267002
-344482838 -833805545
-279398...

output:

2178418010787347715
2521099956104606756
1651687576234220014
2333895875529601714
3311174883188206872
1119361972970337947
2365615119167805472
1998643358049669416
1789898345202904798
1404432918684849715

result:

wrong answer 2nd lines differ - expected: '1826413114144932145', found: '2521099956104606756'