QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140252#6517. Computational GeometrymeomeoWA 1ms3468kbC++141.9kb2023-08-15 16:05:192023-08-15 16:05:21

Judging History

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

  • [2023-08-15 16:05:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-08-15 16:05:19]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long

using namespace std;

int dist(pair<int, int> &A, pair<int, int> &B) {
    return (A.first - B.first) * (A.first - B.first) + (A.second - B.second) * (A.second - B.second);
}

int solve(vector<pair<int, int>> &p, int x, int dir) {
    int n = p.size();
    int l = 0, r = n - 2, res = 0;

    while (l <= r) {
        int mid = l + r >> 1;
        int pos = (x + mid * dir) % n;
        if (pos < 0) pos += n;
        res = max(res, dist(p[pos], p[x]));
        if (dist(p[(pos + dir + n) % n], p[x]) - dist(p[pos], p[x]) >= 0) {
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }

    return res;;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
//    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int t;

    cin >> t;

    while (t--) {
        int n;

        cin >> n;

        vector<pair<int, int>> p(n);

        for (auto &[u, v]: p) {
            cin >> u >> v;
        }

        int res = 4E18;

        for (int i = 0 ; i < n ; i++) {
            if (sqrtl(dist(p[i], p[(i + 1) % n])) + sqrtl(dist(p[(i + 1) % n], p[(i + 2) % n])) == sqrtl(dist(p[i], p[(i+2)%n]))) {
                continue;
            }
            if (sqrtl(dist(p[i], p[(i + 3) % n])) + sqrtl(dist(p[(i + 3) % n], p[(i + 2) % n])) == sqrtl(dist(p[i], p[(i+2)%n]))) {
                continue;
            }
            int d1 = solve(p, i, -1);
            int d2 = solve(p, (i+2) % n, 1);
            int d = max({
                dist(p[i], p[(i+1)%n]),
                dist(p[i], p[(i+2)%n]),
                dist(p[(i+1)%n], p[(i+2)%n])
            });

            // cout << i << " " << d1 << " " << d2 << " " << d << " DEBUG\n";

            res = min(res, max(d1, d2) + d);
        }

        cout << res << "\n";
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3468kb

input:

2
4
1 0
2 0
1 1
0 0
6
10 4
9 7
5 7
4 5
6 4
9 3

output:

4
44

result:

ok 2 number(s): "4 44"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3456kb

input:

713
8
8 25
3 15
0 5
10 0
19 2
24 6
23 15
15 34
8
25 16
18 25
10 32
1 23
0 14
21 0
27 2
32 6
7
16 15
8 20
1 16
0 12
16 0
21 1
24 5
7
15 1
18 0
24 8
27 15
4 19
0 17
7 8
4
10 20
0 30
15 0
14 10
6
15 0
24 10
21 14
12 14
7 11
0 3
7
18 7
16 9
12 10
6 9
0 4
5 0
15 1
9
0 23
8 13
14 6
24 0
34 1
41 11
37 20
1...

output:

1075
1389
739
687
1550
524
300
1530
471
162
534
190
889
966
405
930
710
524
509
275
605
298
146
1330
494
1199
527
1209
802
1210
233
362
611
1417
854
980
262
500
370
1115
1283
2521
712
586
885
624
697
596
1193
843
1035
406
934
620
974
1159
513
2248
939
1791
1283
834
721
585
203
198
1593
617
1166
326
...

result:

wrong answer 3rd numbers differ - expected: '706', found: '739'