답안 #498263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498263 2021-12-24T17:40:42 Z beepbeepsheep Akvizna (COCI19_akvizna) C++17
65 / 130
1500 ms 1488 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
typedef pair<ll,ll> ii;
typedef pair<ld,ll> ldll;
const ll mod=1e9+7;
const ll maxn=3e5+5;
const ll inf=1e15;
ll n,k;
struct line{
    ld m,c;
    ll used;
    line():m(0),c(0),used(0){}
    line(ld M, ld C, ll Used):m(M),c(C),used(Used){}
    ld operator()(ld x){return m*x+c;}
    ld POI(line l){
        return (this->c-l.c)/(l.m-this->m);
    }
    bool toPop(line a, line b){
        return (this->c-a.c)*(b.m-this->m)<=(this->c-b.c)*(a.m-this->m);
    }
};
struct lch{
    deque<line> dq;
    void upd(line a){
        while (dq.size()>1){
            ll s=dq.size();
            if (a.toPop(dq[s-1],dq[s-2])) dq.pop_back();
            else break;
        }
        dq.push_back(a);
    }
    ldll query(ld p){
        while (dq.size()>1){
            if (dq[0](p)<dq[1](p)) dq.pop_front();
            else if (abs(dq[0](p)-dq[1](p))<=1e-16 && dq[1].used<dq[0].used) dq.pop_front();
            else break;
        }
        return make_pair(dq[0](p),dq[0].used);
    }
}*hull; //max hull
ldll solve(ld cost){
    hull->dq.clear();
    line l;
    l.m=(ld)1/n,l.c=0,l.used=0;
    hull->upd(l);
    ld temp=0;
    for (int i=1;i<=n;i++){
        ldll p = hull->query(i);
        temp = p.first - cost;
        if (i==n){
            return make_pair(temp,p.second+1);
        }
        l.m=(ld)1/(n-i),l.c=temp-((ld) i/(n-i)),l.used=p.second+1;
        hull->upd(l);
    }
    return {0,0};
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    ld l=0,r=1,m;
    ld ans=0;
    hull=new lch();
    ll cnt=0;
    while (cnt!=300){
        m=(l+r)/2;
        ldll p=solve(m);
        if (p.second>k){
            l=m;
        } else{
            ans=m*p.second+p.first;
            r=m;
        }
        cnt++;
    }
    cout<<setprecision(10)<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 336 KB Output is correct
2 Correct 52 ms 316 KB Output is correct
3 Correct 40 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 336 KB Output is correct
2 Correct 52 ms 336 KB Output is correct
3 Correct 38 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 336 KB Output is correct
2 Correct 46 ms 316 KB Output is correct
3 Correct 36 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 336 KB Output is correct
2 Correct 55 ms 336 KB Output is correct
3 Correct 38 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 336 KB Output is correct
2 Correct 56 ms 336 KB Output is correct
3 Correct 40 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 336 KB Output is correct
2 Correct 53 ms 336 KB Output is correct
3 Correct 50 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 340 KB Output is correct
2 Correct 50 ms 336 KB Output is correct
3 Correct 44 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 320 KB Output is correct
2 Correct 61 ms 336 KB Output is correct
3 Correct 56 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 336 KB Output is correct
2 Correct 50 ms 336 KB Output is correct
3 Correct 48 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1587 ms 1360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 1388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 1360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1573 ms 1416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1576 ms 1488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 1468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1583 ms 1488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1583 ms 1480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1583 ms 1468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1590 ms 1488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1590 ms 1468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1594 ms 1488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1564 ms 1488 KB Time limit exceeded
2 Halted 0 ms 0 KB -