QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721056#9520. Concave HullffffycWA 1ms7732kbC++143.7kb2024-11-07 15:06:372024-11-07 15:06:37

Judging History

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

  • [2024-11-07 15:06:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7732kb
  • [2024-11-07 15:06:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=1e5+10;
struct Point{
	ll x,y;
	Point(ll X=0,ll Y=0){ x=X,y=Y; }
	inline friend ll operator*(const Point &a,const Point &b){ return 1ll*a.x*b.y-1ll*a.y*b.x; }
	inline friend Point operator+(const Point &a,const Point &b){ return Point(a.x+b.x,a.y+b.y); }
	inline friend Point operator-(const Point &a,const Point &b){ return Point(a.x-b.x,a.y-b.y); }
	inline friend bool operator<(const Point &a,const Point &b){ return a.x==b.x?a.y<b.y:a.x<b.x; }
	inline ll calc(){ return 1ll*x*x+1ll*y*y; }
}a[N];
inline ll area(Point a,Point b,Point c){
	return abs((b-a)*(c-a));
}
inline ll area(int i,int j,int k){
	return area(a[i],a[j],a[k]);
}
int n,stk[N],stk2[N*2],vis[N];
int main(){
	int QT=read();
	while(QT--){
		n=read();
		for(int i=1;i<=n;i++)
			a[i].x=read(),a[i].y=read();
		sort(a+1,a+n+1);
		int top=0,top2=0;
		for(int i=1;i<=n;i++){
	        while(top>1&&(a[stk[top]]-a[stk[top-1]])*(a[i]-a[stk[top-1]])<=0) vis[stk[top]]--,top--;
	        stk[++top]=i,vis[i]++;
	    }
	    int cur=top;
	    for(int i=n-1;i>=1;i--){
	        while(top>cur&&(a[stk[top]]-a[stk[top-1]])*(a[i]-a[stk[top-1]])<=0) vis[stk[top]]--,top--;
	        stk[++top]=i,vis[i]++;
	    }
	    bool fl=0;
	    for(int i=1;i<=n;i++)
	    	fl|=!vis[i];
//	    for(int i=1;i<=top;i++)
//	    	printf("(%d,%d) ",a[stk[i]].x,a[stk[i]].y);puts("");
		if(!fl){
	    	write(-1),putc('\n');
			for(int i=1;i<=n;i++)
				vis[i]=0;
	    	continue;
		}
		for(int i=1;i<=n;i++){
			if(vis[i]) continue;
	        while(top2>1&&(a[stk2[top2]]-a[stk2[top2-1]])*(a[i]-a[stk2[top2-1]])<=0) top2--;
	        stk2[++top2]=i;
	    }
	    cur=top2;
	    for(int i=n-1;i>=1;i--){
			if(vis[i]||i==stk2[cur]) continue;
	        while(top2>cur&&(a[stk2[top2]]-a[stk2[top2-1]])*(a[i]-a[stk2[top2-1]])<=0) top2--;
	        stk2[++top2]=i;
	    }
	    if(top2>1) top2--;
	    assert(top2>0);
//	    for(int i=1;i<=top2;i++)
//	    	printf("(%d,%d) ",a[stk2[i]].x,a[stk2[i]].y);puts("");
	    ll s=0,mn=4e18;
	    for(int i=3;i<=top;i++)
	    	s+=area(stk[1],stk[i-1],stk[i]);
//	    printf("%d\n",s);
	    for(int i=1;i<=top2;i++)
	    	stk2[i+top2]=stk2[i];
	    if(top2<=10){
		    for(int i=1;i<=top;i++){
		    	int p1=stk[i],p2=i==top?stk[1]:stk[i+1];
		    	for(int j=1;j<=top2;j++)
		    		mn=min(mn,area(p1,p2,stk2[j]));
			}
//			assert(mn<s);
		}else{
			for(int i=1,j=1;i<=top;i++){
		    	int p1=stk[i],p2=i==top?stk[1]:stk[i+1];
		    	while(j<top2*2&&area(p1,p2,stk2[j])>=area(p1,p2,stk2[j+1])) j++;
	//	    	printf("%d %d %d %d\n",p1,p2,stk2[j],area(p1,p2,stk2[j]));
		    	mn=min(mn,area(p1,p2,stk2[j]));
			}
		}
		write(s-mn),putc('\n');
		for(int i=1;i<=n;i++)
			vis[i]=0;
	}
	flush();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7732kb

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:

44
-1

result:

wrong answer 1st lines differ - expected: '40', found: '44'