QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220143#7584. Support or NotPhantomThreshold#WA 6578ms11008kbC++203.1kb2023-10-19 22:37:272023-10-19 22:37:27

Judging History

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

  • [2023-10-19 22:37:27]
  • 评测
  • 测评结果:WA
  • 用时:6578ms
  • 内存:11008kb
  • [2023-10-19 22:37:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll sq(ll x){
	ll sz=sqrtl(x);
	for (;(sz)*(sz)<x;) sz++;
	for (;(sz-1)*(sz-1)>=x;) sz--;
	return sz; 	
}
ll calc(ll x,ll y,ll z){
	ll w2=x*x+y*y+z*z;
	ll sz=sq(w2);
	return sz;	
}

typedef double db;

struct point{
	db x,y,z;
	point operator + (const point &k1){return (point){x+k1.x,y+k1.y,z+k1.z};}
	point operator - (const point &k1){return (point){x-k1.x,y-k1.y,z-k1.z};}
	db abs(){return hypot(hypot(x,y),z);}
	point unit(){
		db w=abs();
		return (point){x/w,y/w,z/w};	
	}
};
db dot(point k1,point k2){
	return k1.x*k2.x+k1.y*k2.y+k1.z*k2.z;	
}

const int maxn=100000;
const int maxk=300;
mt19937 rng((unsigned long long)(new char));
db pi=acos(-1);
db scale=0.5;
const int magicD=1200;

int n,k;
ll _x[maxn+50],_y[maxn+50],_z[maxn+50];
point a[maxn+50];
ll r[maxn+50];

vector<tuple<ll,int,int>> candidate;
ll ans[maxk+50];
pair<db,db> b[maxn+50];

tuple<db,int,int> mn[magicD+5];
int mn_sz=0;
tuple<db,int,int> nxt[magicD+5];
int nxt_sz=0;
void gao(point dir){
	for (int i=1;i<=n;i++){
		db mid=dot(a[i],dir);
		b[i]=make_pair(mid-scale*r[i],mid+scale*r[i]);	
	}
	sort(b+1,b+n+1);
//	cerr << "ok1" << endl;
	for (int i=1;i<n;i++){
	//	cerr << "gao : " << i << endl;
		int mn_pos=1;
		nxt_sz=0;
		for (int j=i+1;j<=i+magicD && j<=n;j++){
			db proj_dis=b[j].first-b[i].second;
			while (mn_pos<=mn_sz){
				if (nxt_sz==magicD) break;
				if (get<0>(mn[mn_pos])<proj_dis){
					nxt[++nxt_sz]=mn[mn_pos];
				}
				else break;
				mn_pos++;
			}
			if (nxt_sz==magicD) break;
			nxt[++nxt_sz]=make_tuple(proj_dis,i,j);
		}
		while (mn_pos<=mn_sz){
			if (nxt_sz==magicD) break;
			nxt[++nxt_sz]=mn[mn_pos];
			mn_pos++;
		}
	//	cerr << "mn_sz,nxt_sz : " << mn_sz << " " << nxt_sz << endl;
		mn_sz=nxt_sz;
		for (int t=1;t<=nxt_sz;t++) mn[t]=nxt[t];
	}
//	cerr << "ok2" << endl;
	for (int sel=1;sel<=mn_sz;sel++){
		int i=get<1>(mn[sel]);
		int j=get<2>(mn[sel]);
		ll d=calc(_x[i]-_x[j],_y[i]-_y[j],_z[i]-_z[j])-r[i]-r[j];
		d=max(d,(ll)0);
		candidate.emplace_back(d,i,j);
	}
}

void solve(){
	cin >> n >> k;
	for (int i=1;i<=n;i++){
		int _r=0;
		cin >> _x[i] >> _y[i] >> _z[i] >> _r;
		a[i].x=_x[i];
		a[i].y=_y[i];
		a[i].z=_z[i];
		r[i]=_r;
	}
	for (int cc=1;cc<=16;cc++){
		point dir;
		dir.x=(int)(rng()%20000001)-10000000;
		dir.y=(int)(rng()%20000001)-10000000;
		dir.z=(int)(rng()%20000001)-10000000;
		while (dir.abs()>10000000){
			dir.x=(int)(rng()%20000001)-10000000;
			dir.y=(int)(rng()%20000001)-10000000;
			dir.z=(int)(rng()%20000001)-10000000;
		}
		dir=dir.unit();
		gao(dir);
	}
	
//	cerr << "candy size :" << candidate.size() << endl;
	
	sort(candidate.begin(),candidate.end());
	candidate.resize(
		unique(candidate.begin(),candidate.end())
		-candidate.begin()
	);
//	cerr << "candy size :" << candidate.size() << endl;
	
	for (int i=0;i<k;i++){
		ans[i]=get<0>(candidate[i]);
	}
	for (int i=0;i<k;i++){
		cout << ans[i] << "\n";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	int Tcase=3;
	cin >> Tcase;
	for (;Tcase--;){
		solve();
	}
	return 0;	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
4 6
0 0 0 1
0 3 2 2
3 2 1 1
1 1 2 2

output:

0
0
0
1
1
2

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 6578ms
memory: 11008kb

input:

3
100000 300
874914 604395 333852 94
487016 56485 38106 94
593651 138336 969260 37
353586 222361 911579 10
865600 791274 47766 5
22401 596667 465329 21
466027 350897 62260 16
728026 787017 272219 76
955473 207969 90699 18
252804 854316 349023 34
59964 288736 663393 72
667204 542533 993769 48
754023 ...

output:

68421
75944
82014
83037
83476
83615
85509
85909
86059
87171
87286
88342
91403
91454
94858
97206
97566
104257
109716
112316
112462
112776
113161
120599
121717
123114
123419
123984
125287
126870
126973
128302
130723
131446
135933
136258
136297
138719
138721
141476
142582
142930
145991
150712
151370
15...

result:

wrong answer 1st numbers differ - expected: '181', found: '68421'