QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#415518#4423. AMPPZ in the times of diseaseargtargTL 0ms0kbC++202.1kb2024-05-20 22:31:542024-05-20 22:31:55

Judging History

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

  • [2024-05-20 22:31:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-20 22:31:54]
  • 提交

answer

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

#define endl '\n'

#define int long long
using pii = pair<int, int>;
using ll = long long;

int dis2(pii a, pii b) {
	return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second);
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tt = 1;
	cin >> tt;
	while (tt--) {
		int n, k;
		cin >> n >> k;
		vector<int>x(n + 1), y(n + 1);
		for (int i = 1; i <= n; i++) {
			cin >> x[i] >> y[i];
		}
		vector < set<pii> >st(k + 2);
		vector<int>v(k + 2);
		for (int i = 1; i <= k; i++) {
			v[i] = i;
		}
		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				if (i == j)continue;
				st[i].insert({ dis2({x[i],y[i]},{x[j],y[j]}),j});
			}
		}
		//
		//vector<vector<int>>g(n + 1);
		vector<int>p(n + 1);
		for (int i = 1; i <= n; i++) {
			p[i] = i;
		}
		auto find = [&](auto find, int x)->int {
			if (p[x] != x)return p[x] = find(find, p[x]);
			return p[x];
		};
		for (int i = k + 1; i <= n; i++) {
			int mi = 9e18 ;
			pii j = { 0,0 };
			for (int m = 1; m <= k + 1; m++) {
				if (st[m].size() == 0) {
					v[m] = i;
					for (int w = 1; w <= k + 1; w++) {
						if (w == m)continue; 
						st[m].insert({ dis2({x[i],y[i]},{x[v[w]],y[v[w]]}),v[w] });
					}
				}
				else {
					st[m].insert({ dis2({x[i],y[i]},{x[v[m]],y[v[m]]}),i });
					pii tmp = (*st[m].begin());
					if (mi > tmp.first) {
						mi = tmp.first;
						j = { m,tmp.second };
					}
				}
			}
			//g[v[j.first]].emplace_back(j.second);
			//g[j.second].emplace_back(v[j.first]);
			int ai = find(find, v[j.first]), bi = find(find, j.second);
			p[ai] = bi;
			st[j.first].clear();
			for (int m = 1; m <= k + 1; m++) {
				if (m == j.first)continue;
				st[m].erase({ dis2({x[v[j.first]],y[v[j.first]]},{x[v[m]],y[v[m]]}),v[j.first] });
			}

		}//return 0;


		vector<int>c(n + 1);
		for (int i = 1; i <= n; i++) {
			if (find(find, i) == i) {
				c[i] = k--;
			}
		}
		for (int i = 1; i <= n; i++) {
			cout << c[find(find, i)] << ' ';
		}
		cout << endl;
	}
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

100
100000 20
270505 510725
245104 76414
131477 992924
781607 895592
562469 622976
564354 637966
980036 112090
522903 687218
113871 977855
6615 123673
13847 347618
657794 165707
420561 183995
11367 136391
507836 694877
985069 105115
774110 486921
14319 338715
774937 118145
981468 99089
803866 491315...

output:

1 16 18 4 6 6 14 10 18 13 8 7 12 13 10 14 17 8 11 14 17 7 3 4 2 1 12 19 3 6 16 7 5 2 19 4 11 12 4 5 5 8 16 1 6 3 1 20 17 20 3 20 7 3 3 15 13 1 13 3 3 11 15 8 4 12 11 19 2 11 5 7 19 2 13 7 11 17 15 9 4 14 18 17 18 8 12 2 20 17 16 6 6 3 3 4 17 2 14 3 17 1 13 1 13 3 13 12 11 17 2 5 3 2 10 20 6 3 10 10 ...

result: