Submission #222189

# Submission time Handle Problem Language Result Execution time Memory
222189 2020-04-12T09:58:25 Z kartel Akvizna (COCI19_akvizna) C++14
130 / 130
608 ms 7544 KB
#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(200500)
#define sz(x) x.size()
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;

ld f[N], b[N];
ll n, m, i, j, kol, sz, num[N], pr, K;
ld cht[N], k[N];

void AddInCHT(int i)
{
    ld x;
    while (1)
    {
        pr = num[sz];

        x = (b[pr] - b[i]) / (k[i] - k[pr]);
//        cerr << x << el;

        if (x - cht[sz] > 1e-18) break;

        sz--;
    }

    sz++;

    cht[sz] = x;
    num[sz] = i;
}

int ch(ld X)
{
    sz = 1;

    cht[sz] = -1e18;

    num[sz] = n;

    b[n] = 0;
    f[n] = 0;
    k[n] = 1.0 / ld(n);

    for (i = n - 1; i >= 0; i--)
        {
            int l = 1;
            int r = sz;

            while (l < r)
            {
                int md = (l + r + 1) >> 1;
                ld x = cht[md];

                if (x + ld(i) < 1e-18) l = md;
                                  else r = md - 1;
            }

            K = num[l];

            f[i] = f[K] + 1;

            b[i] = b[K] + 1 - ld(i) * k[K] + X;

            k[i] = ld(1) / ld(i);

            AddInCHT(i);
        }

    return f[0];
}

int main()
{
//    in("input.txt");
//    out("output.txt");

    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    ld l = 0;
    ld r = 1e12;

    while (r - l > 1e-18)
    {
        ld md = (l + r) * 0.5;

        if (ch(-md) > m) l = md + 1e-18;
                   else r = md;

    }

    ch(-l);

    cout << setprecision(9) << fixed << b[0] + l * ld(m);
}

# 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 18 ms 640 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 640 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 640 KB Output is correct
2 Correct 17 ms 512 KB Output is correct
3 Correct 16 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 640 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 17 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 640 KB Output is correct
2 Correct 17 ms 640 KB Output is correct
3 Correct 17 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 512 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 19 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 640 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 17 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 640 KB Output is correct
2 Correct 19 ms 660 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 512 KB Output is correct
2 Correct 27 ms 560 KB Output is correct
3 Correct 18 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 6840 KB Output is correct
2 Correct 529 ms 7160 KB Output is correct
3 Correct 481 ms 6776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 7032 KB Output is correct
2 Correct 516 ms 7416 KB Output is correct
3 Correct 484 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 482 ms 6904 KB Output is correct
2 Correct 543 ms 7440 KB Output is correct
3 Correct 550 ms 7292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 7288 KB Output is correct
2 Correct 517 ms 7164 KB Output is correct
3 Correct 480 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 7032 KB Output is correct
2 Correct 551 ms 7416 KB Output is correct
3 Correct 525 ms 6908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 7544 KB Output is correct
2 Correct 527 ms 7032 KB Output is correct
3 Correct 508 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 7160 KB Output is correct
2 Correct 504 ms 6908 KB Output is correct
3 Correct 510 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 6904 KB Output is correct
2 Correct 572 ms 7388 KB Output is correct
3 Correct 515 ms 6868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 524 ms 7392 KB Output is correct
2 Correct 550 ms 7256 KB Output is correct
3 Correct 577 ms 7420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 7356 KB Output is correct
2 Correct 547 ms 7068 KB Output is correct
3 Correct 565 ms 7352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 583 ms 7424 KB Output is correct
2 Correct 588 ms 7460 KB Output is correct
3 Correct 608 ms 7456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 535 ms 7388 KB Output is correct
2 Correct 574 ms 7544 KB Output is correct
3 Correct 584 ms 7452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 7420 KB Output is correct
2 Correct 566 ms 7544 KB Output is correct
3 Correct 554 ms 7544 KB Output is correct