QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220124#7584. Support or NotPhantomThreshold#WA 858ms10936kbC++203.0kb2023-10-19 22:25:482023-10-19 22:25:48

Judging History

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

  • [2023-10-19 22:25:48]
  • 评测
  • 测评结果:WA
  • 用时:858ms
  • 内存:10936kb
  • [2023-10-19 22:25:48]
  • 提交

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.515709995651;
const int magicD=600;

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<=4;cc++){
		point dir;
		dir.x=(int)(rng()%2001)-1000;
		dir.y=(int)(rng()%2001)-1000;
		dir.z=(int)(rng()%2001)-1000;
		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: 7800kb

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: 858ms
memory: 10936kb

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:

51789
67850
106549
122984
130065
133856
135644
138970
151253
157130
165859
171139
179166
182608
191924
192460
192573
194707
196843
197546
198564
202607
203029
205302
214865
215051
217423
218045
221355
221853
222409
222645
223383
224550
230525
232156
237893
238113
241699
242948
249592
249792
250148
2...

result:

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