#include <bits/stdc++.h>
#define m first
#define b second
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
using ld = long double;
typedef pair <double, double> line;
const int N = int(2e5) + 500;
const int base = int(1e9) + 7;
double dp[N];
int n, k;
int cnt[N], which[N];
line lines[N];
double intersect(line f, line s) { return (f.m == s.m) ? 1e18 : (f.b - s.b) / (s.m - f.m); }
double val(line a, double x) { return (a.m * x + a.b); }
void solve(double cost) {
int l = 0, r = 0;
dp[0] = cnt[0] = 0;
for (int i = 1; i <= n; ++i) {
line nline = {dp[i - 1], -i};
while (r - l > 1 && intersect(nline, lines[r - 1]) < intersect(lines[r - 1], lines[r - 2]))
--r;
which[r] = i - 1;
lines[r++] = nline;
while (r - l > 1 && val(lines[l], i) <= val(lines[l + 1], i))
++l;
dp[i] = (val(lines[l], i) + i + 1) / i - cost;
cnt[i] = cnt[which[l]] + 1;
}
}
int main() {
fast_io;
cin >> n >> k;
double low = 0, high = 20;
while (high - low >= 1e-12) {
double md = (low + high) / 2;
solve(md);
if (cnt[n] <= k) high = md;
else low = md;
}
solve(high);
cout.precision(20); cout << fixed;
cout << dp[n] + cnt[n] * high << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
396 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
3200 KB |
Output is correct |
2 |
Correct |
55 ms |
3448 KB |
Output is correct |
3 |
Correct |
57 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
3448 KB |
Output is correct |
2 |
Correct |
62 ms |
3456 KB |
Output is correct |
3 |
Correct |
58 ms |
3328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
3200 KB |
Output is correct |
2 |
Correct |
60 ms |
3456 KB |
Output is correct |
3 |
Correct |
60 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
3328 KB |
Output is correct |
2 |
Correct |
61 ms |
3456 KB |
Output is correct |
3 |
Correct |
55 ms |
3248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
3200 KB |
Output is correct |
2 |
Correct |
57 ms |
3456 KB |
Output is correct |
3 |
Correct |
58 ms |
3344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3456 KB |
Output is correct |
2 |
Correct |
53 ms |
3384 KB |
Output is correct |
3 |
Correct |
57 ms |
3352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
3440 KB |
Output is correct |
2 |
Correct |
55 ms |
3200 KB |
Output is correct |
3 |
Correct |
55 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
3328 KB |
Output is correct |
2 |
Correct |
60 ms |
3456 KB |
Output is correct |
3 |
Correct |
55 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3456 KB |
Output is correct |
2 |
Correct |
59 ms |
3328 KB |
Output is correct |
3 |
Correct |
59 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
3456 KB |
Output is correct |
2 |
Correct |
58 ms |
3380 KB |
Output is correct |
3 |
Correct |
57 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
3456 KB |
Output is correct |
2 |
Correct |
70 ms |
3576 KB |
Output is correct |
3 |
Correct |
63 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
3584 KB |
Output is correct |
2 |
Correct |
57 ms |
3456 KB |
Output is correct |
3 |
Correct |
63 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
3456 KB |
Output is correct |
2 |
Correct |
66 ms |
3528 KB |
Output is correct |
3 |
Correct |
59 ms |
3456 KB |
Output is correct |