QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356828 | #6436. Paimon Polygon | PorNPtree | WA | 1ms | 6248kb | C++14 | 5.3kb | 2024-03-18 12:57:51 | 2024-03-18 12:57:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
pair<int, int> operator - (pair<int, int> x, pair<int, int> y)
{
return make_pair(x.first - y.first, x.second - y.second);
}
long long operator * (pair<int, int> x, pair<int, int> y)
{
return 1ll * x.first * y.second - 1ll * x.second * y.first;
}
double atan3(int y, int x)
{
double f = atan2(y, x);
return (f > -1e-6 ? f : f + 2 * acos(-1.0));
}
int cmp(pair<int, int> x, pair<int, int> y)
{
return atan3(x.second, x.first) < atan3(y.second, y.first);
}
pair<int, int> jz;
int cmp2(pair<int, int> x, pair<int, int> y)
{
return cmp(x - jz, y - jz);
}
int flag, S[N], top, vis[N];
pair< vector< pair<int, int> >, vector< pair<int, int> > > convexHull(vector< pair<int, int> > z)
{
for (int i = 1; i < (int)z.size(); ++i) {
if (z[i].second < z[0].second || (z[i].second == z[0].second && z[i].first < z[0].first)) {
swap(z[0], z[i]);
}
}
jz = z[0];
sort(z.begin() + 1, z.end(), cmp2);
S[top = 1] = 0;
for (int i = 1; i < (int)z.size(); ++i) {
while (top >= 2 && (z[S[top]] - z[S[top - 1]]) * (z[i] - z[S[top]]) < 0) {
--top;
}
S[++top] = i;
}
for (int i = 0; i < (int)z.size(); ++i) {
vis[i] = 0;
}
if (top <= 2) {
flag = 0;
return {{}, {}};
}
vector< pair<int, int> > S1, S2;
for (int i = 1; i <= top; ++i) {
S1.push_back(z[S[i]]);
vis[S[i]] = 1;
if ((z[S[i]] - z[S[(i == 1 ? top : i - 1)]]) * (z[S[(i == 1 ? top : i - 1)]] - z[S[(i == 1 ? top - 1 : (i == 2 ? top : i - 2))]]) == 0) {
flag = 0;
return {{}, {}};
}
}
for (int i = 0; i < (int)z.size(); ++i) {
if (!vis[i]) {
S2.push_back(z[i]);
}
}
return make_pair(S1, S2);
}
double jerry(vector< pair<int, int> > z)
{
double res = 0;
for (int i = 0; i < (int)z.size(); ++i) {
int j = (i + 1 == (int)z.size() ? 0 : i + 1);
res += hypot(z[i].first - z[j].first, z[i].second - z[j].second);
}
return res;
}
signed main()
{
int T;
scanf("%d", &T);
for (int test = 1; test <= T; ++test) {
int n;
scanf("%d", &n);
vector< pair<int, int> > z, tz;
for (int i = 1, x, y; i <= n; ++i) {
scanf("%d%d", &x, &y);
z.emplace_back(x, y);
}
flag = 1;
tz = z;
z.emplace_back(0, 0);
pair< vector< pair<int, int> >, vector< pair<int, int> > > tmp = convexHull(z);
double res = 0;
if (flag) {
vector< pair<int, int> > p1 = tmp.first, p2 = tmp.second, p3;
int hv = 0;
for (int i = 0; i < (int)p1.size(); ++i) {
hv |= (p1[i] == make_pair(0, 0));
}
if (hv) {
p2.emplace_back(0, 0);
if ((int)p2.size() >= 3) {
tmp = convexHull(p2);
p2 = tmp.first, p3 = tmp.second;
if (flag && p3.empty()) {
res = max(res, jerry(p1) + jerry(p2));
}
}
}
}
z.pop_back();
sort(z.begin(), z.end(), cmp);
vector<int> hv;
for (int i = 0; i < (int)z.size(); ++i) {
if ((z[i] - z[(i + n - 1) % n]) * (z[(i + 1) % n] - z[i]) <= 0) {
hv.push_back(i);
}
}
if ((int)hv.size() > 4) {
printf("%.10lf\n", res);
continue;
}
int ok = 1;
for (int i = 0; i < (int)z.size(); ++i) {
int j = (i + 1) % n;
if (z[i] * z[j] == 0 && ((z[i].first > 0) == (z[j].first > 0) || (z[i].first == 0 && z[j].first == 0 && (z[i].second > 0) == (z[j].second > 0)))) {
ok = 0;
break;
}
}
if (!ok) {
printf("%.10lf\n", res);
continue;
}
double ts = jerry(z);
for (int i = 0, j = 1; i < (int)z.size(); ++i) {
while ((j + 1) % n != i && (make_pair(0, 0) - z[i]) * z[(j + 1) % n] <= 0) {
j = (j + 1) % n;
}
if ((make_pair(0, 0) - z[i]) * z[(j + 1) % n] == 0 || (make_pair(0, 0) - z[j]) * z[(i + 1) % n] == 0) {
continue;
}
int ok = 1;
for (auto x : hv) {
if (x != i && x != j && x != (i + 1) % n && x != (j + 1) % n) {
ok = 0;
break;
}
}
if (ok) {
res = max(res, ts + hypot(z[i].first, z[i].second)
+ hypot(z[(i + 1) % n].first, z[(i + 1) % n].second)
+ hypot(z[j].first, z[j].second)
+ hypot(z[(j + 1) % n].first, z[(j + 1) % n].second)
- hypot(z[i].first - z[(i + 1) % n].first, z[i].second - z[(i + 1) % n].second)
- hypot(z[j].first - z[(j + 1) % n].first, z[j].second - z[(j + 1) % n].second));
}
}
printf("%.10lf\n", res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4216kb
input:
3 4 0 3 3 0 2 3 3 2 5 4 0 5 -5 -4 -2 1 -2 -5 -2 4 0 1 1 0 0 2 1 1
output:
17.2111025509 36.6326947621 0.0000000000
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 6248kb
input:
14 4 0 3 1 3 3 1 3 0 4 -4 0 5 3 0 -4 -1 0 5 4 4 5 0 3 3 3 2 -4 2 5 1 1 2 4 1 4 0 4 -1 1 4 4 5 -2 4 1 4 -5 -2 5 3 5 3 -1 4 -5 4 1 2 4 5 4 0 5 -5 -4 -2 1 -2 -5 -2 5 3 4 3 5 -5 -1 1 2 4 1 5 -5 -3 3 -3 -3 -3 2 -3 -4 5 5 0 1 -3 -1 -3 -3 -4 -4 -3 0 6 1 -3 -3 -3 2 -2 -3 1 -4 -5 3 -3 6 -1 -4 -3 0 0 4 -4 -3 ...
output:
14.3245553203 0.0000000000 30.6896447944 18.7482240257 30.2540122179 27.8210682918 36.6326947621 33.4097258671 29.5562146354 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000
result:
ok 14 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 6236kb
input:
100 6 -4 1 -1 4 1 4 -4 -1 -2 3 3 2 7 -5641417 962017 -5641417 -962017 -5719589 193284 -5693492 -578972 -5693492 578972 -5563601 1340673 -5719589 -193284 9 -25 55 58 15 -13 14 -1 19 -60 6 -17 8 11 15 16 58 16 11 10 398546 -221163 -87181 -447383 -221163 -398546 -467649 -57196 55334 -452427 -427086 -19...
output:
25.1141680517 24824262.6835847646 359.1097585858 3042924.9210867863 547.7541625009 62188.8862666670 34663049.5304524601 51604481.6979927868 2264792232.4113187790 69911.1777695327 6924993.0023835879 27901.9604859406 0.0000000000 68869955.9200051129 741423.3147931471 35164453.6311061978 671.8132617321...
result:
ok 100 numbers
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 6240kb
input:
100 5 -1 3 -3 -1 -2 -2 -2 2 -3 1 10 12304563 85714062 39425590 -77096858 -41257504 76132260 -63303220 -59084727 -14839769 -85311687 77575790 -38474659 85621241 -12934672 55622697 66365791 83459695 -23082068 21276755 -83938086 8 2890069 4853907 -4693652 -4650419 2902770 -2219431 -3844676 8770039 5979...
output:
16.8098366946 787989807.6659953594 0.0000000000 1990.2717756307 0.0000000000 56.6254303179 38028.2640999908 535.6659455590 235257.8675583731 184.9505138061 602881.3711287220 46.4849160494 4110.4659447832 7564262751.1217308044 46670198.1187152490 2588369380.2164812088 338944.2793992752 0.0000000000 4...
result:
wrong answer 10th numbers differ - expected: '180.9505138', found: '184.9505138', error = '0.0221055'