QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#415483 | #4423. AMPPZ in the times of disease | argtarg | WA | 7423ms | 5312kb | C++20 | 1.7kb | 2024-05-20 22:06:32 | 2024-05-20 22:06:32 |
Judging History
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 abs(a.first - b.first) + abs(a.second - b.second);
}
pair<int, int> closest(const vector<pii>& a) {
int64_t d = dis2(a[0], a[1]);
pair<int, int> ans = { 0, 1 };
for (int i = 0; i < int(a.size()); ++i) {
for (int j = i + 1; j < int(a.size()); ++j) {
pii cur = { i,j };
int64_t curd = dis2(a[i], a[j]);
if (curd < d) {
ans = cur;
d = curd;
}
}
}
return ans;
}
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];
}
set<int>s;
for (int i = 1; i <= k; i++) {
s.insert(i);
}
//
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++) {
vector<int> v;
vector<pii> que;
s.insert(i);
for (auto si : s) {
v.push_back(si);
que.push_back({x[si],y[si]});
}
pii it=closest(que);
int x = it.first, y = it.second;
int ai = find(find, v[x]), bi = find(find, v[y]);
p[ai] = bi;
s.erase(v[x]);
s.erase(v[y]);
s.insert(v[x]);
}//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
Wrong Answer
time: 7423ms
memory: 5312kb
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:
wrong answer wrong solution (test case 12)