Submission #222192

# Submission time Handle Problem Language Result Execution time Memory
222192 2020-04-12T10:03:00 Z kartel Akvizna (COCI19_akvizna) C++14
130 / 130
454 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(100500)
#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-13)
    {
        ld md = (l + r) * 0.5;

        if (ch(-md) > m) l = md + 1e-13;
                   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 512 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 14 ms 512 KB Output is correct
2 Correct 16 ms 512 KB Output is correct
3 Correct 20 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 512 KB Output is correct
2 Correct 15 ms 512 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 512 KB Output is correct
2 Correct 14 ms 512 KB Output is correct
3 Correct 14 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 512 KB Output is correct
2 Correct 16 ms 512 KB Output is correct
3 Correct 17 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 640 KB Output is correct
2 Correct 16 ms 640 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 512 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 640 KB Output is correct
2 Correct 17 ms 512 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 512 KB Output is correct
2 Correct 16 ms 512 KB Output is correct
3 Correct 15 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 512 KB Output is correct
2 Correct 15 ms 512 KB Output is correct
3 Correct 15 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 6904 KB Output is correct
2 Correct 426 ms 7160 KB Output is correct
3 Correct 392 ms 6752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 394 ms 7032 KB Output is correct
2 Correct 413 ms 7160 KB Output is correct
3 Correct 420 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 6904 KB Output is correct
2 Correct 454 ms 7484 KB Output is correct
3 Correct 444 ms 7288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 423 ms 7268 KB Output is correct
2 Correct 424 ms 7160 KB Output is correct
3 Correct 412 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 6904 KB Output is correct
2 Correct 432 ms 7416 KB Output is correct
3 Correct 398 ms 7008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 7420 KB Output is correct
2 Correct 421 ms 7160 KB Output is correct
3 Correct 387 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 7288 KB Output is correct
2 Correct 393 ms 6752 KB Output is correct
3 Correct 410 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 399 ms 6904 KB Output is correct
2 Correct 431 ms 7500 KB Output is correct
3 Correct 405 ms 6776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 423 ms 7288 KB Output is correct
2 Correct 415 ms 7140 KB Output is correct
3 Correct 432 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 7292 KB Output is correct
2 Correct 396 ms 7032 KB Output is correct
3 Correct 418 ms 7292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 7416 KB Output is correct
2 Correct 445 ms 7544 KB Output is correct
3 Correct 439 ms 7436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 445 ms 7544 KB Output is correct
2 Correct 428 ms 7416 KB Output is correct
3 Correct 446 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 7440 KB Output is correct
2 Correct 440 ms 7416 KB Output is correct
3 Correct 437 ms 7544 KB Output is correct