QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#710095 | #9540. Double 11 | OIer_kzc | WA | 0ms | 4132kb | C++17 | 1.4kb | 2024-11-04 18:38:48 | 2024-11-04 18:38:49 |
Judging History
answer
#include <stdio.h>
#include <cmath>
#include <vector>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef double DB;
typedef long long LL;
constexpr int N = 200005;
constexpr DB eps = 1e-9;
int n, m;
LL a[N];
DB D, f[N];
struct Dat {
int x, k;
} q[N]; int hh, tt;
DB val(int j, int i) {
return sqrt((a[i] - a[j]) * (i - j));
}
bool cmp(int i, int j, int k) {
return f[i] + val(i, k) <= f[j] + val(j, k);
}
DB DP() {
q[0] = (Dat){1, 0}, hh = tt = 0;
for (int i = 1; i <= n; ++i) {
while (hh < tt && q[hh + 1].x <= i) {
++hh;
}
f[i] = f[q[hh].k] + val(q[hh].k, i) + D;
int l = i + 1, r = n + 1, md;
while (hh < tt && cmp(i, q[tt].k, q[tt].x)) {
r = q[tt--].x;
}
if (l > q[tt].x) {
q[tt].x = l;
} else {
l = q[tt].x + 1;
}
while (l < r) {
md = l + r >> 1;
if (cmp(i, q[tt].k, md)) {
r = md;
} else {
l = md + 1;
}
}
if (r <= n) {
q[++tt] = (Dat){r, i};
}
}
return f[n] - m * D;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%lld", a + i);
a[i] += a[i - 1];
}
DB l = 0, r = sqrt(n * a[n]), xl, xr, vl, vr;
while (r - l > eps) {
xl = D = (2 * l + r) / 3, vl = DP();
xr = D = (l + 2 * r) / 3, vr = DP();
if (vl > vr) {
r = xr;
} else {
l = xl;
}
}
D = (l + r) / 2;
printf("%.30lf\n", DP());
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 2080kb
input:
4 2 1 2 3 4
output:
6.191147129557118766740586579544
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.591625366514129780171060701832
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4000kb
input:
1 1 1
output:
1.000000000000000000000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4084kb
input:
1 1 100000
output:
316.227766016838018003909382969141
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
7 1 10 47 53 9 83 33 15
output:
41.833001326703779909621516708285
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 4132kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
244.045793209414540569923701696098
result:
wrong answer 1st numbers differ - expected: '233.9016546', found: '244.0457932', error = '0.0433692'