QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96974#5251. ConstellationssuperguymjWA 932ms111984kbC++141.4kb2023-04-16 13:58:212023-04-16 13:58:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-16 13:58:24]
  • 评测
  • 测评结果:WA
  • 用时:932ms
  • 内存:111984kb
  • [2023-04-16 13:58:21]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define pb push_back

using namespace std;
const int N=4005;
typedef long long LL;
bool vis[N];
int n,s[N];
LL dis[N][N];
vector <int> vt;

int getint()
{
	char ch;
	int f=1;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x*f;
}

struct point {int x,y;} dat[N];
struct D
{
	LL d;
	int x,y;

	bool operator < (const D &t) const
	{
		LL a=(LL)s[x]*s[y];
		LL b=(LL)s[t.x]*s[t.y];
		if(d*b==t.d*a) return x==t.x?y>t.y:x>t.x;
		return d*b>t.d*a;
	}
} ;

priority_queue <D> q;

LL sqr(LL x) {return x*x;}
LL len(point a,point b) {return sqr(a.x-b.x)+sqr(a.y-b.y);}

void del(int x)
{
	vis[x]=1;
	int sz=vt.size();
	rep(i,0,sz-1) if(vt[i]==x)
	{
		rep(j,i+1,sz-1) vt[j-1]=vt[j];
		break;
	}
	vt.pop_back();
}

LL d(int x,int y)
{
	if(x>y) swap(x,y);
	return dis[x][y];
}

int main()
{
	n=getint();
	rep(i,1,n) dat[i].x=getint(),dat[i].y=getint();
	rep(i,1,n) rep(j,i+1,n) q.push((D){dis[i][j]=len(dat[i],dat[j]),i,j});
	rep(i,1,n) s[i]=1,vt.pb(i);
	int m=n-1;
	while(m)
	{
		D t=q.top(); q.pop();
		if(vis[t.x] || vis[t.y]) continue;
		del(t.x),del(t.y);
		s[++n]=s[t.x]+s[t.y];
		for(auto j:vt)
			q.push((D){dis[j][n]=d(j,t.x)+d(j,t.y),j,n});
		vt.push_back(n),--m;
		printf("%d\n",s[n]);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3504kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 932ms
memory: 111984kb

input:

2000
1000 -1000
1000 -999
1000 -998
1000 -997
1000 -996
1000 -995
1000 -994
1000 -993
1000 -992
1000 -991
1000 -990
1000 -989
1000 -988
1000 -987
1000 -986
1000 -985
1000 -984
1000 -983
1000 -982
1000 -981
1000 -980
1000 -979
1000 -978
1000 -977
1000 -976
1000 -975
1000 -974
1000 -973
1000 -972
1000...

output:

2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
11
12
13
14
15
16
2
3
17
2
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
44
2
3
4
5
6
7
8
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
18
17
19...

result:

wrong answer 3rd lines differ - expected: '2', found: '3'