QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797090#3224. DirectionsKazemaruTL 0ms0kbC++171.4kb2024-12-02 16:03:452024-12-02 16:03:46

Judging History

This is the latest submission verdict.

  • [2024-12-02 16:03:46]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-12-02 16:03:45]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for(;'0'>ch||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
	return x*f;
}
void write(int x){if(x>9)write(x/10);putchar(x%10+48);}
const int N=3e5,V=1e9+7;
struct op{
	int x,y,z,v,w;double d;
	void rev(){x=-x;y=-y;z=-z;}
	void cv(int u){v=((x+V)*V*2+y)*2+(z+1)/2;w=u;}
	void dv(){d=atan2(x*z,y*z);}
}a[N];int b[N],c[N];
int ask(op A){
	if(!A.x&&!A.y)return V*9;
	int x=0,y=V*9,z=V*9,m=n/2;
	f(i,1,n)if(a[i].v==A.v)x=i;
	f(i,1,n)(i>m?c[i-m]:b[i])=a[(x+i-2)%n+1].w;
	f(i,2,m)y=min(y,b[i]+z),z=min(z,c[i]);
	return A.w+y;
}
signed main(){
	s=read();
	int x=1,y=1,z=V*9;
	f(_,0,s){
		if(_)x=read(),y=read(),z=read();
		if(!x&&!y)continue;l=abs(__gcd(x,y));
		a[++m]={x/l,y/l,1};
		if(a[m].x<0)a[m].rev();
		if(a[m].y<0)a[m].rev();
		a[m].cv(z);
		a[m+1]=a[m];a[++m].z*=-1;
		a[m].cv(V*9);
	}
	sort(a+1,a+m+1,[&](op a,op b){return a.v<b.v;});
	f(i,1,m){
		if(a[n].v<a[i].v)a[++n]=a[i];
		else a[n].w=min(a[n].w,a[i].w);
	}
	m=1;
	f(i,1,n)if(a[i].w<a[m].w)m=i;
	f(i,1,n)a[i].dv();
	op A=a[m-1],B=a[m],C=a[m+1];
	sort(a+1,a+n+1,[&](op a,op b){return a.d<b.d;});
	m=min({ask(A),ask(B),ask(C)});
	if(m>V*3)m=-1;cout<<m;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

200000
-1 -1 1
1 1 1
0 1 1
1 0 1
1 -1 1
1 1 1
1 1 1
-1 1 1
1 -1 1
0 1 1
0 0 1
0 0 1
1 -1 1
-1 -1 1
0 0 1
1 0 1
-1 1 1
-1 1 1
1 1 1
1 1 1
-1 1 1
0 -1 1
1 -1 1
-1 0 1
1 0 1
1 -1 1
0 -1 1
1 0 1
-1 1 1
1 0 1
-1 0 1
1 1 1
1 0 1
-1 -1 1
-1 1 1
-1 -1 1
0 -1 1
0 -1 1
1 1 1
1 -1 1
0 1 1
1 1 1
-1 1 1
1 -1 1
0...

output:


result: