QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102510#5251. Constellationsfz_zsl#WA 2216ms128668kbC++172.1kb2023-05-03 14:09:232023-05-03 14:09:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 14:09:27]
  • 评测
  • 测评结果:WA
  • 用时:2216ms
  • 内存:128668kb
  • [2023-05-03 14:09:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define fi first
#define se second
const int MAX_N = 2e3 + 5;
int N, tim, T[MAX_N], sz[MAX_N];
LL X[MAX_N], Y[MAX_N], A[MAX_N], B[MAX_N], C[MAX_N];
struct node { 
	LL sum, sz;
	pair<int, int> e;
} ;
bool operator == (const node &l, const node &r) {
	return l.sum == r.sum && l.e == r.e && l.sz == r.sz;
}
bool operator < (const node &l, const node &r) {
	LL tl = l.sum * r.sz, tr = r.sum * l.sz;
	if (tl != tr) return tl < tr;
	else {
		auto u = make_pair(T[l.e.fi], T[l.e.se]);
		auto v = make_pair(T[r.e.fi], T[r.e.se]);
		return u > v;
	}
}
int pa[MAX_N];
int getf(int x) { while (x != pa[x]) x = pa[x] = pa[pa[x]]; return x; }
void unite(int x, int y) {
	x = getf(x), y = getf(y);
	A[x] += A[y], B[x] += B[y], C[x] += C[y];
	sz[x] += sz[y], T[x] = ++tim;
	pa[y] = x;
}
int main() {
	scanf("%d", &N); tim = N;
	for (int i = 1; i <= N; i++) {
		scanf("%lld %lld", X + i, Y + i), pa[i] = i;
		A[i] = X[i] * X[i] + Y[i] * Y[i];
		B[i] = X[i];
		C[i] = Y[i];
		T[i] = N + 1 - i;
		sz[i] = 1;
	}
	multiset<node> S;
	for (int i = 1; i <= N; i++) 
		for (int j = i + 1; j <= N; j++)
			S.insert((node){A[i] + A[j] - 2 * B[i] * B[j] - 2 * C[i] * C[j], 1, make_pair(i, j)});
	for (int stp = 1; stp < N; stp++) {
		auto p = *S.begin(); S.erase(S.begin()); 
		int u = p.e.fi, v = p.e.se;
		for (int i = 1; i <= N; i++) {
			if (i == getf(i)) {
				if (i == u || i == v) continue;
				S.erase(S.find((node){A[i] + A[u] - 2 * B[i] * B[u] - 2 * C[i] * C[u], sz[i] * sz[u], 
								(T[i] < T[u] ? make_pair(u, i) : make_pair(i, u))}));
				S.erase(S.find((node){A[i] + A[v] - 2 * B[i] * B[v] - 2 * C[i] * C[v], sz[i] * sz[v],
								(T[i] < T[v] ? make_pair(v, i) : make_pair(i, v))}));
			}
		}
		unite(u, v);
		printf("%d\n", sz[getf(u)]);
		for (int i = 1; i <= N; i++) {
			if (i == getf(i) && i != u) {
				S.insert((node){A[i] + A[u] - 2 * B[i] * B[u] - 2 * C[i] * C[u], sz[i] * sz[u], 
								(T[i] < T[u] ? make_pair(u, i) : make_pair(i, u))});
			}
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 2216ms
memory: 128668kb

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
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
10...

result:

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