QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138695#5251. ConstellationsUNos_maricones#WA 5858ms3508kbC++202.1kb2023-08-12 08:28:322023-08-12 08:28:36

Judging History

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

  • [2023-08-12 08:28:36]
  • 评测
  • 测评结果:WA
  • 用时:5858ms
  • 内存:3508kb
  • [2023-08-12 08:28:32]
  • 提交

answer

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

#define ff   first
#define ss   second
#define pb   push_back

typedef long long   ll;
typedef pair<ll,ll>   ii;

const int N = 2005;
const int mod = 1e9+7;
const ll oo = 5e12;

int sumx[N], sumxs[N], sumy[N], sumys[N], tmm[N], fat[N], sz[N];
int x[N], y[N];
int curr;

void ini (int n) { 
	for (int i = 0; i < n; ++i) {
		fat[i] = i;
		sumx[i] = x[i];
		sumxs[i] = x[i] * x[i];
		sumy[i] = y[i];
		sumys[i] = y[i] * y[i];
		tmm[i] = i;
		sz[i] = 1;
	}
	curr=n;
}

int fnd(int x) { 
	if (x == fat[x]) return x;
	return fat[x] = fnd(fat[x]);
}

void uni (int x, int y) { 
	int fx = fnd(x);
	int fy = fnd(y);
	fat[fx] = fy;
	sumx[fy] += sumx[fx];
	sumxs[fy] += sumxs[fx];
	sumy[fy] += sumy[fx];
	sumys[fy] += sumys[fy];
	tmm[fy] = curr++;
	sz[fy] += sz[fx];
}

int allw[N];

int main() { 
	#ifdef LOCAL
	freopen("in","r",stdin);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
	ini(n);
//	cout << n << endl;
	//return 0;
	for (int i = 0; i + 1 < n; ++i) { 
		int szz = 0;
		for (int j = 0; j < n; ++j) { 
			if (fnd(j) == j) {
				allw[szz++] = j;
			}
		}
		pair<ii,ii> best={{oo,1},{-1,-1}};
		int tj=-1,tk=-1;
		for (int j = 0; j < szz; ++j) { 
			for (int k = j + 1; k < szz; ++k) { 
				int rj = allw[j];
				int rk = allw[k];
				ll cost = 1ll * (sumxs[rj] + sumys[rj]) * sz[rk] + 1ll * (sumxs[rk] + sumys[rk]) * sz[rj] - 2ll * (1ll * sumx[rj] * sumx[rk] + 1ll * sumy[rj] * sumy[rk]);
				ii pr = {min(tmm[rj], tmm[rk]),max(tmm[rj],tmm[rk])};
				
			//	cout << rj << ' ' << rk << ' ' << cost << endl;
				
				if (1ll * cost * best.ff.ss < 1ll * sz[rk] * sz[rj] * best.ff.ff) { 
					best = {{cost, 1ll * sz[rk] * sz[rj]},pr};
					tj = rj;
					tk = rk;
				}
				else if (1ll * cost * best.ff.ss == 1ll*sz[rk] * sz[rj] * best.ff.ff && pr < best.ss) {
					best = {{cost, 1ll * sz[rk] * sz[rj]},pr};
					tj = rj;
					tk = rk;
				}
			}
		}
	//	cout <<tj<<' ' << tk << endl;
		
	//	return 0;
		cout << sz[tj] + sz[tk] << '\n';
		uni(tj, tk);
	}
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 0
1 0

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 5858ms
memory: 3508kb

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'