This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[3001][3001];
ll n, m, i, j, kol, sz, num[N], pr, K;
ld cht[N], b[3001][3001], k[3001][3001];
void AddInCHT(int i, int j)
{
ld x;
while (1)
{
pr = num[sz];
x = (b[pr][j] - b[i][j]) / (k[i][j] - k[pr][j]);
// cerr << x << el;
if (x - cht[sz] > 1e-9) break;
sz--;
}
sz++;
cht[sz] = x;
num[sz] = i;
}
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;
f[n][0] = 0;
for (i = 1; i < n; i++) b[i][0] = -1e18, k[i][0] = 0;
for (i = 1; i <= m; i++) f[n][i] = 0, k[n][i] = 0, b[n][i] = -1e18;
k[n][0] = ld(1) / ld(n);
b[n][0] = 0;
for (j = 1; j <= m; j++)
{
sz = 1;
cht[sz] = -1e18;
num[sz] = n - j + 1;
for (i = n - j; 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-9) l = md;
else r = md - 1;
}
K = num[l];
f[i][j] = b[K][j - 1] + 1 - ld(i) * k[K][j - 1];
k[i][j] = ld(1) / ld(i);
b[i][j] = f[i][j];
if (k[i][j - 1] != 0) AddInCHT(i, j - 1);
}
}
cout << setprecision(9) << fixed << f[0][m];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |