QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#415370#4423. AMPPZ in the times of diseaseargtargTL 0ms0kbC++202.0kb2024-05-20 20:06:592024-05-20 20:07:00

Judging History

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

  • [2024-05-20 20:07:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-20 20:06:59]
  • 提交

answer

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

#define endl '\n'

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


signed main() {
	ios::sync_with_stdio(false);
	cin.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({ abs(x[i] - x[j]) + abs(y[i] - y[j]),j });
			}
		}
		//
		vector<vector<int>>g(n + 1);
		for (int i = k + 1; i <= n; i++) {
			int mi = 2e9+1;
			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({ abs(x[v[w]] - x[i]) + abs(y[v[w]] - y[i]),v[w] });
					}
				}
				else {
					st[m].insert({ abs(x[v[m]] - x[i]) + abs(y[v[m]] - y[i]),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]);
			st[j.first].clear();
			for (int m = 1; m <= k + 1; m++) {
				if (m == j.first)continue;
				st[m].erase({ abs(x[v[m]] - x[v[j.first]]) + abs(y[v[m]] - y[v[j.first]]),v[j.first] });
			}
			
		}//return 0;
		vector<int>ans;
		auto dfs = [&](auto dfs, int u, int fa) ->void{
			ans.emplace_back(u);
			for (int i : g[u]) {
				if (i == fa)continue;
				dfs(dfs, i, u);
			}
			return;
		}; 
		vector<int>c(n + 1);
		int t = 0;
		for (int i = 1; i <= k + 1; i++) {
			if (st[i].size()) {
				t++;
				ans.clear();
				dfs(dfs, v[i], -1);
				
				for (auto x : ans) {
					c[x] = t;
				}
				
			}
		}
		for (int i = 1; i <= n; i++) {
			cout << c[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:

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

result: