#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 100 * 1000 + 10;
int n, k;
long double dp[nax];
int cnt[nax];
struct Line {
long double a, b;
int id;
long double intersect(Line &he) {
return (b - he.b) / (he.a - a);
}
long double eval(int x) {
return a * x + b;
}
};
deque<Line>lines;
int main() {_
cin >> n >> k;
long double low = 0.0, high = 1.0000, mid;
for(int rep = 0; rep < 40; ++rep) {
mid = (low + high) / 2.0;
while((int)lines.size() > 0) lines.pop_back();
for(int used = 0; used <= n; ++used) {
dp[used] = 0;
cnt[used] = 0;
while((int)lines.size() > 1 && lines[0].eval(used - n) <= lines[1].eval(used - n)) {
lines.pop_front();
}
long double res = 0.0;
if((int)lines.size() > 0) {
res = lines[0].eval(used - n) - mid;
cnt[used] = cnt[lines[0].id] + 1;
}
dp[used] = max(dp[used], res);
if(used < n) {
Line l = {(long double)1/(n - used), dp[used] + 1.0, used};
while((int)lines.size() > 1 && lines[(int)lines.size() - 2].intersect(l) <= lines[(int)lines.size() - 2].intersect(lines.back())) {
lines.pop_back();
}
lines.push_back(l);
}
}
if(cnt[n] <= k) {
high = mid;
} else {
low = mid;
}
}
mid = high;
while((int)lines.size() > 0) lines.pop_back();
for(int used = 0; used <= n; ++used) {
dp[used] = 0;
cnt[used] = 0;
while((int)lines.size() > 1 && lines[0].eval(used - n) <= lines[1].eval(used - n)) {
lines.pop_front();
}
long double res = 0.0;
if((int)lines.size() > 0) {
res = lines[0].eval(used - n) - mid;
cnt[used] = cnt[lines[0].id] + 1;
}
dp[used] = max(dp[used], res);
if(used < n) {
Line l = {(long double)1/(n - used), dp[used] + 1.0, used};
while((int)lines.size() > 1 && lines[(int)lines.size() - 2].intersect(l) <= lines[(int)lines.size() - 2].intersect(lines.back())) {
lines.pop_back();
}
lines.push_back(l);
}
}
cout << setprecision(10);
cout << fixed;
cout << dp[n] + mid * k;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
412 KB |
Output is correct |
2 |
Correct |
11 ms |
332 KB |
Output is correct |
3 |
Correct |
9 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
424 KB |
Output is correct |
3 |
Correct |
8 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
412 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
332 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
420 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
404 KB |
Output is correct |
2 |
Correct |
9 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
416 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
412 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
420 KB |
Output is correct |
2 |
Correct |
8 ms |
416 KB |
Output is correct |
3 |
Correct |
8 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
281 ms |
3404 KB |
Output is correct |
2 |
Correct |
269 ms |
3376 KB |
Output is correct |
3 |
Correct |
242 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
3296 KB |
Output is correct |
2 |
Correct |
284 ms |
3404 KB |
Output is correct |
3 |
Correct |
287 ms |
3376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
3276 KB |
Output is correct |
2 |
Correct |
282 ms |
3512 KB |
Output is correct |
3 |
Correct |
267 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
3352 KB |
Output is correct |
2 |
Correct |
270 ms |
3404 KB |
Output is correct |
3 |
Correct |
259 ms |
3312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
3304 KB |
Output is correct |
2 |
Correct |
272 ms |
3612 KB |
Output is correct |
3 |
Correct |
253 ms |
3340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
308 ms |
3404 KB |
Output is correct |
2 |
Correct |
289 ms |
3368 KB |
Output is correct |
3 |
Correct |
274 ms |
3344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
3428 KB |
Output is correct |
2 |
Correct |
250 ms |
3160 KB |
Output is correct |
3 |
Correct |
262 ms |
3276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
267 ms |
3256 KB |
Output is correct |
2 |
Correct |
276 ms |
3404 KB |
Output is correct |
3 |
Correct |
256 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
3404 KB |
Output is correct |
2 |
Correct |
273 ms |
3404 KB |
Output is correct |
3 |
Correct |
298 ms |
3512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
286 ms |
3404 KB |
Output is correct |
2 |
Correct |
268 ms |
3360 KB |
Output is correct |
3 |
Correct |
274 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
285 ms |
3404 KB |
Output is correct |
2 |
Correct |
285 ms |
3404 KB |
Output is correct |
3 |
Correct |
275 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
3404 KB |
Output is correct |
2 |
Correct |
291 ms |
3488 KB |
Output is correct |
3 |
Correct |
299 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
3432 KB |
Output is correct |
2 |
Correct |
285 ms |
3504 KB |
Output is correct |
3 |
Correct |
278 ms |
3436 KB |
Output is correct |