QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329700 | #6517. Computational Geometry | tien_noob | WA | 0ms | 3652kb | C++20 | 2.4kb | 2024-02-17 01:15:34 | 2024-02-17 01:15:35 |
Judging History
answer
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 5e3;
int n;
long long res, l[N], r[N], dp_l[N], dp_r[N];
struct TPoint
{
int x, y;
} p[N];
using TVector = TPoint;
TVector operator - (TPoint a, TPoint b)
{
return {b.x - a.x, b.y - a.y};
}
long long dis (TPoint a, TPoint b) // dis
{
return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y);
}
long long operator * (TVector a, TVector b)
{
return 1LL * a.x * b.y - 1LL * a.y * b.x;
}
bool Straight(TPoint a, TPoint b, TPoint c)
{
return (b - a) * (c - b) == 0;
}
int nxt(int i)
{
if (i == n - 1)
{
return 0;
}
return i + 1;
}
int pre(int i)
{
if (i == 0)
{
return n - 1;
}
return i - 1;
}
void read()
{
res = 1e18;
cin >> n;
for (int i = 0; i < n; ++ i)
{
cin >> p[i].x >> p[i].y;
}
}
void solve()
{
for (int i = 0; i < n; ++ i)
{
int k = nxt(i);
for (int j = nxt(i); j != i; j = nxt(j))
{
while(k != i && dis(p[j], p[nxt(k)]) >= dis(p[j], p[k]))
{
k = nxt(k);
}
l[j] = dis(p[j], p[k]);
}
k = pre(i);
for (int j = pre(i); j != i; j = pre(j))
{
while(k != i && dis(p[j], p[pre(k)]) >= dis(p[j], p[k]))
{
k = pre(k);
}
r[j] = dis(p[j], p[k]);
}
long long mx = 0;
for (int j = pre(i); j != i; j = pre(j))
{
mx = max(mx, l[j]);
dp_l[j] = mx;
}
mx = 0;
for (int j = nxt(i); j != i; j = nxt(j))
{
mx = max(mx, r[j]);
dp_r[j] = mx;
if (!Straight(p[i], p[j], p[nxt(i)]) && !Straight(p[j], p[pre(i)], p[i]))
{
res = min(res, dp_l[j] + dp_r[j]);
}
}
}
cout << res << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = true;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 3652kb
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 675 1550 497 300 1668 471 162 519 190 786 983 364 930 580 524 509 275 617 298 146 1330 494 965 599 1321 866 1106 233 398 560 1548 871 938 366 500 367 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 4th numbers differ - expected: '687', found: '675'