QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139443 | #6517. Computational Geometry | UrgantTeam# | WA | 2ms | 3468kb | C++23 | 2.2kb | 2023-08-13 15:56:04 | 2023-08-13 15:56:07 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long double ld;
typedef long long ll;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll sqd(pii p) {
return ll(p.x) * p.x + ll(p.y) * p.y;
}
ll sqd(pii p, pii q) {
return sqd({ p.x - q.x, p.y - q.y });
}
int sum(int a, int b, int n) {
if ((a += b) >= n) a -= n;
return a;
}
int dif(int a, int b, int n) {
if ((a -= b) < 0) a += n;
return a;
}
ll find_ans(const vpii& v) {
const int n = v.size();
vvl diag(n, vl(n));
for (int j = 0; j < n; ++j)
for (int i = j, z = 0; z < n - 1; ++z) {
i = dif(i, 1, n);
diag[i][j] = max(diag[sum(i, 1, n)][j], sqd(v[i], v[j]));
}
vvl seg(n, vl(n));
for (int i = 0; i < n; ++i)
for (int j = i, z = 0; z < n - 1; ++z) {
j = sum(j, 1, n);
seg[i][j] = max(seg[i][dif(j, 1, n)], diag[i][j]);
}
ll ans = 1e18;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) {
if (j == sum(i, 1, n) || j == dif(i, 1, n)) continue;
ll q = seg[i][j] + seg[j][i];
if (q < ans)
ans = q;
}
/*cerr << "DIAG:\n";
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cerr << diag[i][j] << " \n"[j == n - 1];
cerr << "SEG:\n";
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cerr << seg[i][j] << " \n"[j == n - 1];*/
return ans;
}
void solve_test() {
int n;
cin >> n;
vpii v(n);
for (int i = 0; i < n; ++i)
cin >> v[i].x >> v[i].y;
cout << find_ans(v) << '\n';
}
void solve_tests() {
int t = 1;
cin >> t;
for (int i = 0; i < t; ++i)
solve_test();
}
int main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0);
solve_tests();
return 0;
}
/*
* TEST:
6
10 4
9 7
5 7
4 5
6 4
9 3
* DIAG:
0 10 34 37 18 32
37 0 16 29 18 32
37 29 0 5 10 32
37 29 34 0 5 29
16 18 34 37 0 10
2 16 34 37 18 0
* SEG:
0 10 34 37 37 37
37 0 16 29 29 32
37 37 0 5 10 32
37 37 37 0 5 29
16 18 34 37 0 10
2 16 34 37 37 0*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3452kb
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: 2ms
memory: 3468kb
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 706 687 1550 497 300 1668 471 162 519 190 786 983 367 930 580 524 509 275 617 298 146 1330 494 965 599 1321 866 1210 233 398 560 1548 871 938 366 500 371 1118 1222 1994 712 586 858 624 697 575 1274 882 1035 406 934 670 990 1231 513 2871 939 2735 1610 834 721 585 203 198 1666 617 1166 326 2...
result:
wrong answer 120th numbers differ - expected: '294', found: '284'