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 <stdio.h>
#define N 100000
double dp[N + 1]; int kk[N + 1], n;
double cross(int i, int j, int k) {
return (j - i) * (dp[k] - dp[i]) - (k - i) * (dp[j] - dp[i]);
}
double eval(int i, double x) {
return -i * x + dp[i];
}
void solve(double c) {
static int qu[N + 1];
int i, head, cnt;
dp[0] = 0, kk[0] = 0;
head = cnt = 0;
qu[head + cnt++] = 0;
for (i = 1; i <= n; i++) {
while (cnt >= 2 && eval(qu[head], (double) 1 / i) < eval(qu[head + 1], (double) 1 / i))
head++, cnt--;
dp[i] = eval(qu[head], (double) 1 / i) + 1 - c, kk[i] = kk[qu[head]] + 1;
while (cnt >= 2 && cross(qu[head + cnt - 2], qu[head + cnt - 1], i) >= 0)
cnt--;
qu[head + cnt++] = i;
}
}
int main() {
int k, r;
double lower, upper;
scanf("%d%d", &n, &k);
lower = 0, upper = 1;
for (r = 0; r < 60; r++) {
double c = (lower + upper) / 2;
solve(c);
if (kk[n] <= k)
upper = c;
else
lower = c;
}
solve(upper);
printf("%.9f\n", dp[n] + k * upper);
return 0;
}
Compilation message (stderr)
akvizna.c: In function 'main':
akvizna.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |