QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207441#142. 平面最近点对james1BadCreeper0 1ms3632kbC++141.3kb2023-10-08 15:34:092023-10-08 15:34:11

Judging History

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

  • [2023-10-08 15:34:11]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3632kb
  • [2023-10-08 15:34:09]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long i64;
const i64 INF = 2e18;

int n;
struct Point {
    int x, y;
    bool operator < (const Point &a) const {
        if (x == a.x) return y < a.y;
        return x < a.x;
    }
} a[400005];

i64 dist(int i, int j) {
    i64 x = 1ll * (a[i].x - a[j].x) * (a[i].x - a[j].x);
    i64 y = 1ll * (a[i].y - a[j].y) * (a[i].y - a[j].y);
    return x + y;
}

bool cmp(const int &x, const int &y) {
    return a[x].y < a[y].y;
}

int g[200005];
i64 merge(int l, int r) {
    if (l == r) return INF;
    if (l + 1 == r) return dist(l, r);
    int mid = l + r >> 1;
    i64 d1 = merge(l, mid), d2 = merge(mid + 1, r);
    i64 d = min(d1, d2);
    int tot = 0;
    for (int i = l; i <= r; ++i)
        if (abs(a[mid].x - a[i].x) * abs(a[mid].x - a[i].x) < d) g[++tot] = i;
    sort(g + 1, g + tot + 1, cmp);
    for (int i = 1; i < tot; ++i)
        for (int j = i + 1; j <= tot && a[g[j]].y - a[g[i]].y < d; ++j)
            d = min(d, dist(g[i], g[j]));
    return d;
}

int main(void) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].x, &a[i].y);
    sort(a + 1, a + n + 1);
    printf("%lld\n", merge(1, n));
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3632kb

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:

8

result:

wrong answer 1st numbers differ - expected: '2.8284271', found: '8.0000000', error = '1.8284271'

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%