Submission #222218

# Submission time Handle Problem Language Result Execution time Memory
222218 2020-04-12T11:29:34 Z VEGAnn Akvizna (COCI19_akvizna) C++14
130 / 130
854 ms 9916 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define ft first
#define sd second
#define MP make_pair
#define all(x) x.begin(),x.end()
#define PB push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 100100;
const ll OO = 1e18;
const ld E = 1e-9;
const ld CNST = 1;
vector<int> vc;
pair<ld, int> f[N];
int n, k;

struct line{
    ld k, b;
    int bl;

    line(): k(0.0), b(0.0), bl(0) {}
    line(ld _k, ld _b, int i): k(_k), b(_b), bl(i) {}
};

vector<line> hull;

ld get_cross_point(line fi, line se){
    return (fi.b - se.b) / (se.k - fi.k);
}

void insert(line nw){
    if (sz(hull) == 0){
        hull.PB(nw);
        return;
    }

    while (sz(hull) > 1){
        ld pt1 = get_cross_point(nw, hull[sz(hull) - 2]);
        ld pt2 = get_cross_point(hull[sz(hull) - 2], hull.back());

        if (pt2 > pt1) break;

        hull.pop_back();
    }

    hull.PB(nw);
}

bool check(ld extra){
  	hull.clear();

    f[n] = MP(0.0, 0);

    insert({-1.0 / ld(n), f[n].ft, 0});

    for (int j = n - 1; j >= 0; j--){

        if (sz(hull)) {

            int l = 0, r = sz(hull) - 1;

            while (l < r) {
                int md = (l + r) >> 1;

                if (get_cross_point(hull[md], hull[md + 1]) + E < j)
                    r = md;
                else l = md + 1;
            }

            f[j] = MP(hull[l].b + 1.0 + hull[l].k * ld(j) + extra, hull[l].bl + 1);
        }

        insert({-1.0 / ld(j), f[j].ft, f[j].sd});
    }

    return (f[0].sd <= k);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

//    freopen("in.txt","r",stdin);

    cin >> n >> k;

    ld l = 0, r = ld(1e9);

    for (int it = 0; it < 80; it++){
        ld md = (l + r) / 2.0;

        if (check(-md))
            r = md;
        else l = md;

        if (f[0].sd == k){
            l = md;
            break;
        }
    }

    check(-l);

    assert(f[0].sd == k);

    cout << fixed << setprecision(10) << (f[0].ft + l * ld(k) * CNST) / CNST;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 768 KB Output is correct
2 Correct 19 ms 768 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 768 KB Output is correct
2 Correct 21 ms 768 KB Output is correct
3 Correct 19 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 768 KB Output is correct
2 Correct 16 ms 768 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 768 KB Output is correct
2 Correct 17 ms 768 KB Output is correct
3 Correct 18 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 768 KB Output is correct
2 Correct 18 ms 768 KB Output is correct
3 Correct 22 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 768 KB Output is correct
2 Correct 20 ms 768 KB Output is correct
3 Correct 18 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 768 KB Output is correct
2 Correct 20 ms 768 KB Output is correct
3 Correct 20 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 768 KB Output is correct
2 Correct 18 ms 768 KB Output is correct
3 Correct 22 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 768 KB Output is correct
2 Correct 17 ms 768 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 630 ms 9564 KB Output is correct
2 Correct 854 ms 9620 KB Output is correct
3 Correct 736 ms 9444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 9568 KB Output is correct
2 Correct 793 ms 9828 KB Output is correct
3 Correct 755 ms 9696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 602 ms 9568 KB Output is correct
2 Correct 797 ms 9824 KB Output is correct
3 Correct 777 ms 9700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 728 ms 9700 KB Output is correct
2 Correct 777 ms 9700 KB Output is correct
3 Correct 675 ms 9576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 646 ms 9604 KB Output is correct
2 Correct 764 ms 9792 KB Output is correct
3 Correct 771 ms 9572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 698 ms 9808 KB Output is correct
2 Correct 732 ms 9696 KB Output is correct
3 Correct 760 ms 9700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 659 ms 9700 KB Output is correct
2 Correct 731 ms 9444 KB Output is correct
3 Correct 672 ms 9572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 633 ms 9572 KB Output is correct
2 Correct 712 ms 9852 KB Output is correct
3 Correct 736 ms 9444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 652 ms 9700 KB Output is correct
2 Correct 715 ms 9696 KB Output is correct
3 Correct 777 ms 9800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 602 ms 9692 KB Output is correct
2 Correct 716 ms 9916 KB Output is correct
3 Correct 840 ms 9696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 630 ms 9828 KB Output is correct
2 Correct 773 ms 9696 KB Output is correct
3 Correct 778 ms 9828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 671 ms 9696 KB Output is correct
2 Correct 792 ms 9824 KB Output is correct
3 Correct 820 ms 9824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 696 ms 9828 KB Output is correct
2 Correct 734 ms 9700 KB Output is correct
3 Correct 828 ms 9700 KB Output is correct