답안 #59375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59375 2018-07-21T21:35:00 Z Benq 두 개의 원 (balkan11_2circles) C++14
80 / 100
4000 ms 8300 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;
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);
    }
    if (sz(st)) {
        auto a = st.front();
        while (sz(st) >= 2) {
            if (bad(st[sz(st)-2],st.back(),a,mid)) st.pop_back();
            else if (bad(st.back(),st[0],st[1],mid)) st.erase(st.begin());
            else break;
        }
    }
    
    if (sz(st) <= 2) return 0;
    /*F0R(i,sz(st)) if (bad(st[i],st[(i+1)%sz(st)],st[(i+2)%sz(st)],mid)) {
        cout << i << " " << sz(st);
        exit(0);
    }*/
    vcd v;
    F0R(i,sz(st)) v.pb(inter(st[i],st[(i+1)%sz(st)],mid));
    // cout << "AH " << sz(st) << " " << dia(v) << " " << 2*mid << "\n";
    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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 5 ms 356 KB Output is correct
3 Correct 14 ms 560 KB Output is correct
4 Correct 21 ms 560 KB Output is correct
5 Correct 185 ms 896 KB Output is correct
6 Correct 716 ms 2684 KB Output is correct
7 Correct 865 ms 2684 KB Output is correct
8 Execution timed out 4003 ms 3100 KB Time limit exceeded
9 Correct 2594 ms 4904 KB Output is correct
10 Incorrect 3062 ms 8300 KB Output isn't correct