QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111024 | #6436. Paimon Polygon | 5ab | WA | 317ms | 5848kb | C++20 | 3.9kb | 2023-06-05 15:04:50 | 2023-06-05 15:04:54 |
Judging History
answer
/* name: 6436
* author: 5ab
* created at: 2023-06-04
*/
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
using db = double;
const int max_n = 500000;
struct point
{
int x, y;
point operator-(const point& rhs) const {
return point{ x - rhs.x, y - rhs.y };
}
bool operator==(const point& rhs) const = default;
}
a[max_n], b[max_n + 1];
inline void chmax(db& _a, db _b) { if (_a < _b) _a = _b; }
inline bool cclkw(point x, point y)
{
return 1ll * x.x * y.y > 1ll * x.y * y.x;
}
inline bool cln(point x, point y)
{
return 1ll * x.x * y.y == 1ll * x.y * y.x;
}
inline db dis(point x, point y)
{
return hypot(x.x - y.x, x.y - y.y);
}
template<class It>
void cr(It bg, It ed)
{
swap(*bg, *max_element(bg, ed, [](auto& x, auto& y) {
return x.x == y.x ? x.y < y.y : x.x < y.x;
}));
sort(bg + 1, ed, [&](auto& lhs, auto& rhs) {
return cclkw(lhs - *bg, rhs - *bg);
});
}
template<class It>
db calc(It bg, It ed)
{
db res = dis(*bg, *prev(ed));
for (auto s = bg, t = next(bg); t != ed; s++, t++)
res += dis(*s, *t);
return res;
}
db solve1(int n)
{
b[0] = {0, 0};
copy(a, a + n, b + 1);
cr(b, b + n + 1);
static vector<point> c1, c2;
c1.clear(), c2.clear();
for (int i = 0; i <= n; i++)
{
while (ssize(c1) > 1 && cclkw(b[i] - c1.back(), c1.back() - end(c1)[-2]))
c2.push_back(c1.back()), c1.pop_back();
c1.push_back(b[i]);
}
// for (auto [x, y] : c1)
// cerr << "(" << x << "," << y << ") ";
// cerr << endl;
// check colinearity
for (int i = 1; i < ssize(c1) - 1; i++)
if (cln(c1[i + 1] - c1[i], c1[i] - c1[i - 1]))
return 0;
for (int i = 1; i <= n; i++)
if (c1.back() != b[i] && cln(c1.back() - b[i], b[i] - b[0]))
return 0;
if (find(c1.begin(), c1.end(), point{0, 0}) == c1.end())
return 0;
c2.push_back(point{0, 0});
cr(c2.begin(), c2.end());
for (int i = 0; i < ssize(c2); i++)
if (!cclkw(c2[i] - c2[(i - 1 + ssize(c2)) % ssize(c2)], c2[(i + 1) % ssize(c2)] - c2[i]))
return 0;
return calc(c1.begin(), c1.end()) + calc(c2.begin(), c2.end());
}
db solve2(int n)
{
int l = partition(a, a + n, [](auto& x) {
return x.y < 0 || (x.y == 0 && x.x > 0);
}) - a;
sort(a, a + l, cclkw), sort(a + l, a + n, cclkw);
auto nxt = [&](int x) {
return x + 1 == n ? 0 : x + 1;
};
for (int i = 0; i < n; i++)
if (cln(a[i], a[nxt(i)]) && 1ll * a[i].x * a[nxt(i)].x + 1ll * a[i].y * a[nxt(i)].y > 0)
return 0;
db ans = 0, bsv = calc(a, a + n);
vector<int> xps;
auto pre = [&](int x) {
return x == 0 ? n - 1 : x - 1;
};
for (int i = 0; i < n; i++)
if (!cclkw(a[i] - a[pre(i)], a[nxt(i)] - a[i]))
xps.push_back(i);
if (xps.size() > 4)
return 0;
auto od = [&](int id) {
return hypot(a[id].x, a[id].y);
};
for (int i = 0, j = 1; i < n; i++)
{
while (nxt(j) != i && !cclkw(point{0, 0} - a[i], a[nxt(j)]))
{
// cerr << i << " " << j << " " << a[i].x << " " << a[i].y << " " << a[nxt(j)].x << " " << a[nxt(j)].y << endl;
j = nxt(j);
}
if (!cclkw(point{0, 0} - a[i], a[nxt(j)]) || !cclkw(point{0, 0} - a[j], a[nxt(i)]))
continue;
bool ok = true;
for (int x : xps)
if (x != i && x != j && x != nxt(i) && x != nxt(j))
{
ok = false;
break;
}
if (ok)
{
// cerr << i << " " << j << endl;
chmax(ans, bsv - dis(a[i], a[nxt(i)]) - dis(a[j], a[nxt(j)])
+ od(i) + od(nxt(i)) + od(j) + od(nxt(j)));
}
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int cas, n;
cin >> cas;
while (cas--)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].x >> a[i].y;
cout << fixed << setprecision(10) << max(solve1(n), solve2(n)) << "\n";
}
return 0;
}
// started coding at: 06-04 17:50:44
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5556kb
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: 2ms
memory: 5616kb
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: 5848kb
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.9210867872 547.7541625009 62188.8862666670 34663049.5304524675 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: 0
Accepted
time: 3ms
memory: 5668kb
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 180.9505138061 602881.3711287220 46.4849160494 4110.4659447832 7564262751.1217308044 46670198.1187152490 2588369380.2164812088 338944.2793992752 0.0000000000 4...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 2ms
memory: 5796kb
input:
100 8 11998 28379 -21628 21945 -11714 -4752 92 12641 21945 21628 -4752 11714 -30810 224 -11643 4922 4 753 -34290 34290 753 24779 -23714 -23714 -24779 5 -10003 94641 47536 82445 86918 38759 63721 -70687 8533 -1809 10 -2 -4 5 2 7 7 10 -2 9 -5 -5 10 1 -5 4 -9 5 1 7 -7 7 47999701 49571963 -18823337 -785...
output:
172915.4991715059 189693.6987251514 500121.8889460589 0.0000000000 404174872.6039223075 0.0000000000 7627885.1724237995 19929200.3387993127 0.0000000000 383750556.9717311859 217740941.8789575994 54.0037867350 469600775.6014016271 5373804146.8582611084 3096896.5349608143 48655.4723474732 424091181.18...
result:
ok 100 numbers
Test #6:
score: -100
Wrong Answer
time: 317ms
memory: 5696kb
input:
100000 8 -821105972 997119455 155098008 -782026135 999422988 -96073894 -199413884 -677661014 -198376812 -103268925 -871949583 -113805666 -870766708 -124679611 403309120 -797553920 10 -2884 -5808 -5808 2884 -4129 -698 6729 2528 -2992 2930 -2930 -2992 -3003 5746 -1081 6393 -3712 -1940 -4143 612 9 -561...
output:
6635241621.2371349335 0.0000000000 0.0000000000 47255.5024139637 22167105.4928279221 26656.7768842985 6358960.5547562968 4832622736.3216419220 400102464.6059833765 23350.8099848297 61.4363536929 5471759482.6362094879 0.0000000000 365216943.6330448985 0.0000000000 459002454.2754567862 0.0000000000 46...
result:
wrong answer 16732nd numbers differ - expected: '60.4580843', found: '0.0000000', error = '1.0000000'