QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92349#142. 平面最近点对Yansuan_HCl#0 3ms3912kbC++141.4kb2023-03-30 16:03:492023-03-30 16:03:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 16:03:52]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:3912kb
  • [2023-03-30 16:03:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 400005;
const ll INF = 0x7FFFFFFFFFFFFFFF;

int n;
struct Point { ll x, y; } pt[N];
bool operator < (Point l, Point r) { return l.x < r.x; }

ll divide(int l, int r) { // sort by Y
    if (l == r) return INF;
    int mid((l + r) >> 1);
    ll midx = pt[mid].x;
    ll d = min(divide(l, mid), divide(mid + 1, r));
    static Point tmp[N];
    int p = l, q = mid + 1, k = l;
    for (; p <= mid && q <= r; ++k) {
        if (pt[p].y <= pt[q].y) tmp[k] = pt[p], ++p;
        else tmp[k] = pt[q], ++q;
    }
    for (; p <= mid; ++p, ++k) tmp[k] = pt[p];
    for (; q <= r; ++q, ++k) tmp[k] = pt[q];

    for (int i = l; i <= r; ++i) pt[i] = tmp[i];
    p = q = l;
    for (int i = l; i <= r; ++i) {
        while (q < r && (pt[q + 1].y - pt[i].y) * (pt[q + 1].y - pt[i].y) <= d) ++q;
        while (p < q && (pt[i].y - pt[p].y) * (pt[i].y - pt[p].y) > d) ++p;
        if ((pt[i].x - midx) * (pt[i].x - midx) > d) continue;
        for (int j = p; j <= q; ++j) if (j != i) {
            d = min(d, (pt[j].x - pt[i].x) * (pt[j].x - pt[i].x) + (pt[j].y - pt[i].y) * (pt[j].y - pt[i].y));
        }
    }
    return d;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%lld%lld", &pt[i].x, &pt[i].y);
    sort(pt + 1, pt + n + 1);
    printf("%.8lf", sqrtl(divide(1, n)));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3912kb

input:

2933
19320 28055
2053 27470
14635 1378
27582 9822
28729 107
22351 3093
17670 379
23901 4686
27182 12261
19443 8467
24208 20283
10763 10584
25953 28380
28290 27394
19572 14769
4024 12401
23295 3267
26949 176
13416 4517
23856 15413
26260 18957
18275 24409
999 3873
28202 14686
25446 2822
24009 8949
114...

output:

0.00000000

result:

wrong answer 1st numbers differ - expected: '2.8284271', found: '0.0000000', error = '1.0000000'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%