#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int inf = 1e9; // INT_MAX;
const long long llinf = 1e18; // LLONG_MAX;
template<class X, class Y>
bool minimize(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y>
bool maximize(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
template<class X, class Y>
bool add(X &a, Y b) {
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return true;
}
const double eps = 1e-10;
int n, k;
int cnt[N];
double f[N];
double F(int j, int k) {
return (f[j] - f[k]) / (j - k);
}
bool ok(double mid) {
deque<int> q;
q.push_back(0);
for (int i = 1; i <= n; ++i) {
while (q.size() >= 2 && F(q[0], q[1]) > 1.0 / i) q.pop_front();
int j = q.front();
f[i] = f[j] + (double) (i - j) / i - mid;
cnt[i] = cnt[j] + 1;
while (q.size() >= 2 && F(q[q.size() - 2], q[q.size() - 1]) < F(q[q.size() - 1], i)) q.pop_back();
q.push_back(i);
}
return cnt[n] >= k;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
double l = 0, r = 1e9, mid;
while (r - l >= eps) {
mid = (l + r) / 2;
if (ok(mid)) l = mid; else r = mid;
}
cout.precision(12);
cout << fixed;
cout << f[n] + (double) mid * k;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
536 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
556 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
544 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
600 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
3680 KB |
Output is correct |
2 |
Correct |
150 ms |
3748 KB |
Output is correct |
3 |
Correct |
151 ms |
3656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
3680 KB |
Output is correct |
2 |
Correct |
155 ms |
3852 KB |
Output is correct |
3 |
Correct |
157 ms |
3920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
3664 KB |
Output is correct |
2 |
Correct |
158 ms |
3760 KB |
Output is correct |
3 |
Correct |
164 ms |
4168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
3744 KB |
Output is correct |
2 |
Correct |
157 ms |
3728 KB |
Output is correct |
3 |
Correct |
176 ms |
3680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
3680 KB |
Output is correct |
2 |
Correct |
159 ms |
3752 KB |
Output is correct |
3 |
Correct |
152 ms |
3736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
3756 KB |
Output is correct |
2 |
Correct |
150 ms |
3748 KB |
Output is correct |
3 |
Correct |
146 ms |
3672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
3756 KB |
Output is correct |
2 |
Correct |
143 ms |
3668 KB |
Output is correct |
3 |
Correct |
143 ms |
3664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
3676 KB |
Output is correct |
2 |
Correct |
156 ms |
3764 KB |
Output is correct |
3 |
Correct |
142 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
3760 KB |
Output is correct |
2 |
Correct |
154 ms |
3724 KB |
Output is correct |
3 |
Correct |
154 ms |
3752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
3744 KB |
Output is correct |
2 |
Correct |
156 ms |
3768 KB |
Output is correct |
3 |
Correct |
156 ms |
3764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
3868 KB |
Output is correct |
2 |
Correct |
162 ms |
3956 KB |
Output is correct |
3 |
Correct |
173 ms |
3700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
3704 KB |
Output is correct |
2 |
Correct |
162 ms |
3720 KB |
Output is correct |
3 |
Correct |
177 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
3820 KB |
Output is correct |
2 |
Correct |
159 ms |
3764 KB |
Output is correct |
3 |
Correct |
156 ms |
3764 KB |
Output is correct |