Submission #222214

# Submission time Handle Problem Language Result Execution time Memory
222214 2020-04-12T11:25:04 Z VEGAnn Akvizna (COCI19_akvizna) C++14
65 / 130
1500 ms 8620 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) {}
};

deque<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.push_front(nw);
        return;
    }

    while (sz(hull) > 1){
        ld pt1 = get_cross_point(nw, hull[1]);
        ld pt2 = get_cross_point(hull[1], hull[0]);

        if (pt2 > pt1) break;

        hull.pop_front();
    }

    hull.push_front(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) >> 1;

                assert(md > 0);

                if (get_cross_point(hull[md], hull[md - 1]) + E < j)
                    l = md;
                else r = 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 < 100; 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 304 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 28 ms 512 KB Output is correct
2 Correct 39 ms 640 KB Output is correct
3 Correct 34 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 636 KB Output is correct
2 Correct 38 ms 612 KB Output is correct
3 Correct 39 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 512 KB Output is correct
2 Correct 32 ms 512 KB Output is correct
3 Correct 33 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 512 KB Output is correct
2 Correct 35 ms 640 KB Output is correct
3 Correct 36 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 640 KB Output is correct
2 Correct 36 ms 612 KB Output is correct
3 Correct 35 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 512 KB Output is correct
2 Correct 38 ms 640 KB Output is correct
3 Correct 39 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 512 KB Output is correct
2 Correct 39 ms 640 KB Output is correct
3 Correct 40 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 512 KB Output is correct
2 Correct 35 ms 512 KB Output is correct
3 Correct 37 ms 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 512 KB Output is correct
2 Correct 36 ms 640 KB Output is correct
3 Correct 33 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 7900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1590 ms 8168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 8176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 8272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1591 ms 7916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1591 ms 8620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 8300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 7952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1596 ms 8496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1590 ms 8500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1585 ms 8584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 8544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1596 ms 8488 KB Time limit exceeded
2 Halted 0 ms 0 KB -