QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313362 | #4423. AMPPZ in the times of disease | HHY_zZhu | TL | 0ms | 0kb | C++23 | 2.6kb | 2024-01-24 18:09:33 | 2024-01-24 18:09:33 |
answer
//#pragma GCC optimize("O3, unroll-loops")
//#pragma GCC target("avx2, bmi, bmi2, lzcnt, popcnt")
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
#ifdef LOCAL
#include "C:/Users/lijia/Desktop/vscode/algo/debug.h"
#else
#define debug(...) 42
#endif
//const int MN = 2e5 + 20;//MaxN 记得改一下
const int INF = 2e9 + 1000;//INF
const LL INFLL = 8e18 + 1000;//INF long long
mt19937 mrand(random_device{}());
//模板区域~~~~~~~
//模板结束~~~~~~~
void solve() {
int n; cin >> n;
int k; cin >> k;
V<pi> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i].fi >> a[i].se;
}
LL l = 0, r = 1e18;
auto ok = [&](LL mid){
V<int> vis(n + 1);
int cnt = 0;
for(int i = 1; i <= n && cnt < k; i++) {
if(vis[i]) continue;
vis[i] = 1;
cnt++;
auto sqr = [&] (int x) -> LL {return 1LL * x * x;};
auto dis = [&] (pi a, pi b) -> LL {
return sqr(a.fi - b.fi) + sqr(a.se - b.se);
};
for(int j = 1; j <= n; j++) {
if(vis[j] == 1) continue;
if(dis(a[i], a[j]) <= mid) vis[j] = 1;
}
}
if(cnt < k) return 0;
return 1;
};
while(l != r) {
LL mid = (l + r + 1) / 2;
if(ok(mid)) l = mid;
else r = mid - 1;
}
debug(l);
V<int> vis(n + 1);
int now = 1;
for(int i = 1; i <= n; i++) {
if(vis[i]) continue;
vis[i] = now;
auto sqr = [&] (int x) -> LL {return 1LL * x * x;};
auto dis = [&] (pi a, pi b) -> LL {
return sqr(a.fi - b.fi) + sqr(a.se - b.se);
};
for(int j = 1; j <= n; j++) {
if(vis[j]) continue;
if(dis(a[i], a[j]) <= l) vis[j] = now;
}
now++;
}
for(int i = 1; i <= n; i++) {
cout << vis[i] << " \n"[i == n];
}
}
int32_t main() {
#ifndef LOCAL
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
#ifdef LOCAL
freopen("C:/Users/lijia/Desktop/vscode/in.in", "r", stdin);
freopen("C:/Users/lijia/Desktop/vscode/out.out", "w", stdout);
#endif
int tt = 1;
cin >> tt;
while (tt--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
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 2 3 4 5 5 6 7 3 8 9 10 11 8 7 6 12 9 13 6 12 10 14 4 15 1 11 16 14 5 2 10 17 15 16 4 13 11 4 17 17 9 2 1 5 14 1 2 12 2 14 2 10 14 14 18 8 1 8 14 14 13 18 9 4 11 13 16 15 13 17 10 16 15 8 10 13 12 18 19 4 6 3 12 3 9 11 15 2 12 2 5 5 14 14 4 12 15 6 14 12 1 8 1 8 14 8 11 13 12 15 17 14 15 7 2 5 14 7...