답안 #59374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59374 2018-07-21T21:27:00 Z Benq 두 개의 원 (balkan11_2circles) C++14
70 / 100
3192 ms 8464 KB
#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;
cd p[50000];

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);
        }
    }
    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);
    }
    if (sz(st)) {
        auto a = st.front();
        while (sz(st) >= 2 && bad(st[sz(st)-2],st.back(),a,mid)) st.pop_back();
    }
    
    if (sz(st) <= 2) return 0;
    vcd v;
    F0R(i,sz(st)) v.pb(inter(st[i],st[(i+1)%sz(st)],mid));
    //cout << dia(v) << " " << 2*mid << "\n";
    return dia(v) >= 2*mid;
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N) cin >> p[i]; // counterclockwise order
    //cout << test(68575);
    //exit(0);
    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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 12 ms 456 KB Output is correct
4 Correct 17 ms 624 KB Output is correct
5 Correct 155 ms 852 KB Output is correct
6 Correct 656 ms 2716 KB Output is correct
7 Incorrect 774 ms 2716 KB Output isn't correct
8 Incorrect 825 ms 2716 KB Output isn't correct
9 Correct 1921 ms 4880 KB Output is correct
10 Incorrect 3192 ms 8464 KB Output isn't correct