/*input
6
0 0
8 0
8 6
4 8
2 8
0 4
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct point
{
ld x, y;
point() {}
point(ld x, ld y): x(x), y(y) {}
ld r()
{
return sqrtl(x * x + y * y);
}
};
point operator+(const point &a, const point &b)
{
return point(a.x + b.x, a.y + b.y);
}
point operator-(const point &a, const point &b)
{
return point(a.x - b.x, a.y - b.y);
}
point operator*(const point &a, const point &b)
{
return point(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
point operator*(point a, ld k)
{
return point(a.x * k, a.y * k);
}
ld dot(const point &a, const point &b)
{
return a.x * b.x + a.y * b.y;
}
ld cross(const point &a, const point &b)
{
return a.x * b.y - a.y * b.x;
}
point x(const point &a, point b, const point &c, point d)
{
b = b - a;
d = d - c;
ld y = cross(a - c, b) / cross(d, b);
return c + d * y;
}
ld y(const point &a, point b, const point &c, point d)
{
b = b - a;
d = d - c;
return cross(a - c, b) / cross(d, b);
}
struct line
{
point a, b;
};
point x(const line &a, const line &b)
{
return x(a.a, a.b, b.a, b.b);
}
ld y(const line &a, const line &b)
{
return y(a.a, a.b, b.a, b.b);
}
int n;
point A[505050];
bool nereik(const line &a, const line &b, const line &c)
{
return y(a, b) >= y(c, b);
}
void taisom(list<line> &a)
{
int kiek = a.size() * 5 + 7;
auto ii = a.begin();
while (kiek--)
{
if (a.size() <= 2)
{
a = {};
return;
}
auto jj = ii;
jj++;
if (jj == a.end())
jj = a.begin();
auto kk = jj;
kk++;
if (kk == a.end())
kk = a.begin();
if (abs(cross(ii->b - ii->a, kk->b - kk->a)) > 0.5)
{
if (nereik(*ii, *jj, *kk))
{
a.erase(jj);
}
}
else
{
if (cross(kk->a - ii->a, ii->b - ii->a) > 0)
{
a = {};
return;
}
}
ii++;
if (ii == a.end())
ii = a.begin();
}
}
vector<point>x(list<line>a)
{
vector<point>ret;
for (auto it = a.begin(); it != a.end(); it++)
{
auto it1 = it;
it1++;
if (it1 == a.end())
it1 = a.begin();
ret.push_back(x(*it, *it1));
}
return ret;
}
ld maxi(const vector<point> &a)
{
ld ret = 0;
for (int i = 0; i < (int)a.size(); i++)
{
for (int j = 0; j < i; j++)
{
ret = max(ret, (a[i] - a[j]).r());
}
}
return ret;
}
bool ok(ld r)
{
list<line>tieses;
for (int i = 0; i < n; i++)
{
point v = (A[i + 1] - A[i]) * point(0, 1);
v = v * (r / v.r());
tieses.push_back(line());
tieses.back().a = A[i] + v;
tieses.back().b = A[i + 1] + v;
}
taisom(tieses);
ld rr = maxi(x(tieses));
return rr >= 2 * r;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i].x >> A[i].y;
A[n] = A[0];
ld lo = 0;
ld hi = 1ll << 30;
for (int t = 0; t < 50; t++)
{
ld r = (lo + hi) / 2;
if (ok(r))
lo = r;
else
hi = r;
}
ld r = (lo + hi) / 2;
cout << fixed << setprecision(15) << r << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
37 ms |
768 KB |
Output isn't correct |
6 |
Execution timed out |
4096 ms |
3404 KB |
Time limit exceeded |
7 |
Incorrect |
333 ms |
2016 KB |
Output isn't correct |
8 |
Execution timed out |
4013 ms |
3952 KB |
Time limit exceeded |
9 |
Execution timed out |
4016 ms |
6972 KB |
Time limit exceeded |
10 |
Execution timed out |
4014 ms |
10956 KB |
Time limit exceeded |