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 <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int *xx[N]; double *yy[N]; int cnt[N], cnt_[N], xx_[N], n; double k;
int crossover(int x1, double y1, int x2, double y2) {
int lower = x2, upper = n + 1;
while (upper - lower > 1) {
int x = (lower + upper) / 2;
if (y1 + pow(x - x1, k) >= y2 + pow(x - x2, k))
upper = x;
else
lower = x;
}
return upper;
}
void add(int a, double y) {
while (cnt[a] && crossover(xx[a][cnt[a] - 2], yy[a][cnt[a] - 2], xx[a][cnt[a] - 1], yy[a][cnt[a] - 1]) <= crossover(xx[a][cnt[a] - 1], yy[a][cnt[a] - 1], xx_[a], y))
cnt[a]--;
if (cnt[a] == cnt_[a]) {
xx[a] = (int *) realloc(xx[a], cnt_[a] * 2 * sizeof *xx[a]);
yy[a] = (double *) realloc(yy[a], cnt_[a] * 2 * sizeof *yy[a]);
cnt_[a] *= 2;
}
xx[a][cnt[a]] = xx_[a], yy[a][cnt[a]] = y, cnt[a]++;
xx_[a]++;
}
int main() {
int i, a;
double y;
scanf("%lf%d", &k, &n), k /= 2;
for (a = 0; a < n; a++) {
xx[a] = (int *) malloc((cnt_[a] = 2) * sizeof *xx[a]);
yy[a] = (double *) malloc((cnt_[a] = 2) * sizeof *yy[a]);
}
y = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a), a--;
add(a, y);
while (cnt[a] && yy[a][cnt[a] - 1] + pow(xx_[a] - xx[a][cnt[a] - 1], k) <= yy[a][cnt[a] - 2] + pow(xx_[a] - xx[a][cnt[a] - 2], k))
cnt[a]--;
y = yy[a][cnt[a] - 1] + pow(xx_[a] - xx[a][cnt[a] - 1], k);
}
printf("%.9f\n", y);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%lf%d", &k, &n), k /= 2;
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d", &a), a--;
| ~~~~~^~~~~~~~~~
# | 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... |