QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139100#4423. AMPPZ in the times of disease8BQube#TL 0ms0kbC++201.4kb2023-08-12 17:46:412023-08-12 17:46:44

Judging History

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

  • [2023-08-12 17:46:44]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-12 17:46:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define pb push_back
#define ALL(v) v.begin(), v.end()

pll operator-(const pll &a, const pll &b) { return pll(a.X - b.X, a.Y - b.Y); }
ll dot(const pll &a, const pll &b) { return a.X * b.X + a.Y * b.Y; }
ll abs2(const pll &a) { return dot(a, a); }

const ll MAXC = 2e18;
pll arr[2000005];
int num[2000005];

void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> arr[i].X >> arr[i].Y;

    auto check = [&](ll mid) {
        fill_n(num + 1, n, 0);
        for (int t = 1; t <= k + 1; ++t) {
            int cur = 0;
            for (int i = 1; i <= n; ++i)
                if (!num[i]) {
                    if (!cur) cur = i, num[i] = t;
                    else if (abs2(arr[cur] - arr[i]) <= mid)
                        num[i] = t;
                }
            if (!cur) return true;
        }
        return false;
    };

    ll l = -1, r = MAXC;
    while (r - l > 1) {
        ll mid = (l + r) >> 1;
        if (check(mid)) r = mid;
        else l = mid;
    }
    check(r);
    for (int i = 1; i <= n; ++i)
        cout << num[i] << " \n"[i == n];
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

详细

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 18 12 18 14 18 10 14 14 19 8 1 8 14 14 13 19 9 4 11 13 16 15 13 17 10 16 15 8 10 13 12 19 20 4 6 3 12 3 9 11 15 18 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 18 5...

result: