QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179503#7235. PointsPhantomThreshold#TL 5ms3700kbC++203.1kb2023-09-14 21:54:072023-09-14 21:54:08

Judging History

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

  • [2023-09-14 21:54:08]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:3700kb
  • [2023-09-14 21:54:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef double db;
const db eps=1e-6;
int sign(db k)
{
	if(k>eps)return 1;
	if(k<-eps)return -1;
	return 0;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct p3
{
	db x,y,z;
	long long sub;
	p3 operator+(const p3 &k1)const{return {(p3){x+k1.x,y+k1.y,z+k1.z,sub|k1.sub}};}
	p3 operator-(const p3 &k1)const{return {(p3){x-k1.x,y-k1.y,z-k1.z,sub|k1.sub}};}
	p3 operator*(const db k1)const{return {(p3){x*k1,y*k1,z*k1,sub}};}
	p3 operator/(const db k1)const{return {(p3){x/k1,y/k1,z/k1,sub}};}
	db abs2()const{return x*x+y*y+z*z;}
	db abs()const{return hypot(hypot(x,y),z);}
	p3 unit()const{return *this/abs();}
	int operator<(const p3&k1)const
	{
		if(cmp(x,k1.x)!=0)return x<k1.x;
		if(cmp(y,k1.y)!=0)return y<k1.y;
		return cmp(z,k1.z)==-1;
	}
	int operator==(const p3 &k1)const
	{
		return cmp(x,k1.x==0) and cmp(y,k1.y)==0 and cmp(z,k1.z)==0;
	}
};
p3 cross(const p3 &k1,const p3 &k2)
{
	return (p3){k1.y*k2.z-k1.z*k2.y,k1.z*k2.x-k1.x*k2.z,k1.x*k2.y-k1.y*k2.x,0};
}
db dot(const p3 &k1,const p3 &k2)
{
	return k1.x*k2.x+k1.y*k2.y+k1.z*k2.z;
}
typedef vector<p3> vp;
typedef vector<vp> vvp;
mt19937 rng(58);
db rand_db(){return (rng()%1000000000)/1e9;}
db getV(const p3 &k1,const p3 &k2,const p3 &k3,const p3 &k4)
{
	return dot(cross(k2-k1,k3-k1),k4-k1);
}
namespace CH3
{
	vvp ret;set<pair<int,int>> e;
	int n;vp p,q;
	void wrap(int a,int b)
	{
		if(not e.contains({a,b}))
		{
			int c=-1;
			for(int i=0;i<n;i++)
				if(i!=a and i!=b)
					if(c==-1 or sign(getV(q[c],q[a],q[b],q[i]))>0)c=i;
			if(c!=-1)
			{
				ret.push_back({p[a],p[b],p[c]});
				e.emplace(a,b);e.emplace(b,c);e.emplace(c,a);
				wrap(c,b);wrap(a,c);
			}
		}
	}
	vvp convexhull3d(vp _p)
	{
		p=q=_p;n=p.size();
		ret.clear();e.clear();
		for(auto &i:q)i=i+(p3){rand_db()/1e4,rand_db()/1e4,rand_db()/1e4,0};
		for(int i=1;i<n;i++)if(q[i].x<q[0].x)swap(p[0],p[i]),swap(q[0],q[i]);
		for(int i=2;i<n;i++)if((q[i].x-q[0].x)*(q[1].y-q[0].y)>(q[i].y-q[0].y)*(q[1].x-q[0].x))swap(q[1],q[i]),swap(p[1],p[i]);
		wrap(0,1);
		return ret;
	}
}
vp merge(const vp &A,const vp &B,const p3 &x)//merge A+x and B
{
	vp C;
	for(auto &z:A)C.emplace_back(z+x);
	for(auto &z:B)C.emplace_back(z);
	if(C.size()<=2u)return C;
	auto tmp=CH3::convexhull3d(C);
	map<tuple<int,int,int>,long long> tmp2;
	for(const auto &vec:tmp)
		for(const auto &pt:vec)
			tmp2[{pt.x,pt.y,pt.z}]=pt.sub;
	vp ret;
	for(const auto &[pt,sub]:tmp2)
		ret.push_back((p3){get<0>(pt),get<1>(pt),get<2>(pt),sub});
	return ret;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,k;
		cin>>n>>k;
		vvp hull(n+5);
		hull[0].push_back((p3){0,0,0,0});
		for(int i=1;i<=n;i++)
		{
			p3 now;
			cin>>now.x>>now.y>>now.z;
			now.sub=(1ll<<(i-1));
			for(int j=i-1;j>=0;j--)
			{
				hull[j+1]=merge(hull[j],hull[j+1],now);
			}
		}
		db maxx=0;
		long long maxp=0;
		for(const auto &x:hull[k])
		{
			if(x.abs2()>maxx)maxx=x.abs2(),maxp=x.sub;
		}
		cout<<fixed<<setprecision(0)<<maxx<<endl;
		for(int i=0;i<n;i++)
			if((maxp>>i)&1)
				cout<<i+1<<' ';
		cout<<endl;
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 1
4 2 6
4 9 7
6 4 2
3 2
7 3 2
8 2 4
4 7 9

output:

146
2 
394
2 3 

result:

ok Correct (2 tests)

Test #2:

score: 0
Accepted
time: 5ms
memory: 3700kb

input:

48
3 1
506486 41876 692904
165261 762859 246395
781549 425052 316880
8 2
525015 8224 970327
874558 80119 462001
290805 478077 274544
39054 312160 524182
199036 939842 834707
951223 75070 806760
548951 460563 421778
513649 561297 743730
4 1
817567 315632 508886
99778 825028 141365
311062 215938 94373...

output:

891900976505
3 
5344254728649
1 6 
1925054261378
4 
4272030273153
1 2 
5862467200611
1 2 
9221910684849
1 2 3 
1216569228449
1 
17835055670598
1 4 5 7 
1341292964490
1 
29357482136450
2 3 4 5 6 
1764061360298
3 
538912373466
1 
1312222964918
7 
1300748107849
7 
14803216579502
1 2 4 
12152396511653
2...

result:

ok Correct (48 tests)

Test #3:

score: -100
Time Limit Exceeded

input:

5
40 11
91406 989734 719664
162744 233803 716286
917527 609704 351890
282 578278 154507
39455 956096 454235
34402 773703 937545
67001 729884 613200
675806 111928 752155
594666 410066 824852
805401 682493 981233
563377 19394 647273
418154 871916 968817
401635 747220 410569
630989 482086 942247
77540 ...

output:


result: