Submission #59377

#TimeUsernameProblemLanguageResultExecution timeMemory
59377Benq2circles (balkan11_2circles)C++14
100 / 100
3398 ms8568 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int MOD = 1000000007; const ll INF = 1e18; const int MX = 100001; typedef pair<cd,ld> circ; int N; ld lo = 0, hi = 1e8; vcd p; template<class T> istream& operator>> (istream& is, complex<T>& p) { T value; is >> value; p.real(value); is >> value; p.imag(value); return is; } ld cross(cd a, cd b) { return (conj(a)*b).imag(); } ld area(cd a, cd b, cd c) { return cross(b-a,c-a); } cd line(cd a, cd b, cd c, cd d) { ld x = area(a,b,c), y = area(a,b,d); return (x*d-y*c)/(x-y); } pair<cd,cd> trans(pair<cd,cd> a, ld mid) { cd z = (a.s-a.f)/abs(a.s-a.f)*cd(0,1)*mid; a.f += z, a.s += z; return a; } cd inter(pair<cd,cd> a, pair<cd,cd> b, ld mid) { a = trans(a,mid); b = trans(b,mid); return line(a.f,a.s,b.f,b.s); } bool bad(pair<cd,cd> a, pair<cd,cd> b, pair<cd,cd> c, ld mid) { // exit(0); cd x = inter(a,b,mid); cd y = inter(b,c,mid); cd z = (y-x)/(b.s-b.f); return z.real() <= 0; } ld dia(vcd v) { ld ans = 0; int ind = 1; F0R(i,sz(v)) { while (abs(area(v[i],v[(i+1)%sz(v)],v[ind])) < abs(area(v[i],v[(i+1)%sz(v)],v[(ind+1)%sz(v)]))) { ans = max(ans,abs(v[ind]-v[i])); ind = (ind+1)%sz(v); } ans = max(ans,abs(v[ind]-v[i])); } return ans; } bool test(ld mid) { vector<pair<cd,cd>> st; F0R(i,N) { pair<cd,cd> nex = {p[i%N],p[(i+1)%N]}; while (sz(st) >= 2 && bad(st[sz(st)-2],st.back(),nex,mid)) st.pop_back(); st.pb(nex); } int l = 0, r = sz(st)-1; while (r-l+1 > 2) { if (bad(st[r-1],st[r],st[l],mid)) r --; else if (bad(st[r],st[l],st[l+1],mid)) l ++; else break; } st = vector<pair<cd,cd>>(st.begin()+l,st.begin()+r+1); if (sz(st) <= 2) return 0; vcd v; F0R(i,sz(st)) v.pb(inter(st[i],st[(i+1)%sz(st)],mid)); return dia(v) >= 2*mid; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; p.resize(N); F0R(i,N) cin >> p[i]; // counterclockwise order while (hi-lo > (1e-5)) { ld mid = (lo+hi)/2; if (test(mid)) lo = mid; else hi = mid; } cout << fixed << setprecision(3) << (lo+hi)/2; } /* Look for: * the exact constraints (multiple sets are too slow for n=10^6 :( ) * special cases (n=1?) * overflow (ll vs int?) * array bounds */
#Verdict Execution timeMemoryGrader output
Fetching results...