QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801524 | #9540. Double 11 | wangjunrui | WA | 2ms | 8108kb | C++14 | 1.6kb | 2024-12-07 01:04:20 | 2024-12-07 01:04:21 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int N = 2e5 + 5;
constexpr auto eps = 1e-9;
int n, m, a[N];
ll sum[N];
ld f[N];
int g[N];
int head, tail, p[N], q[N];
inline auto solve(ld add)
{
auto calc = [](int l, int r)
{
return sqrt((ld)(sum[r] - sum[l]) * (r - l)) + f[l];
};
head = 1, tail = 1;
p[head] = q[head] = 0;
for (int i = 1; i <= n; ++i)
{
while (head < tail && p[head + 1] <= i)
++head;
f[i] = calc(q[head], i) + add;
g[i] = g[q[head]] + 1;
while (head <= tail && calc(i, p[tail]) < calc(q[tail], p[tail]))
--tail;
if (head <= tail)
{
int l = p[tail], r = n, ans = -1;
while (l <= r)
{
int mid = (l + r) >> 1;
if (calc(i, mid) > calc(q[tail], mid) - eps)
l = mid + 1;
else
r = mid - 1;
}
p[++tail] = l;
q[tail] = i;
}
else
{
p[++tail] = i + 1;
q[tail] = i;
}
}
return make_pair(f[n], g[n]);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i)
sum[i] = sum[i - 1] + a[i];
ld l = -1e9, r = 1e9;
while (abs(r - l) > eps)
{
ld mid = (l + r) / 2;
auto [res, cnt] = solve(mid);
if (cnt == m)
{
printf("%.10Lf\n", res - cnt * mid);
return 0;
}
else if (cnt < m)
r = mid;
else
l = mid;
}
auto [res, cnt] = solve(l);
printf("%.10Lf\n", res - cnt * l);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6116kb
input:
4 2 1 2 3 4
output:
6.1911471296
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6056kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.5916253665
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7984kb
input:
1 1 1
output:
1.0000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 8052kb
input:
1 1 100000
output:
316.2277660168
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4020kb
input:
7 1 10 47 53 9 83 33 15
output:
41.8330013267
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6060kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
233.9016545519
result:
ok found '233.901654552', expected '233.901654552', error '0.000000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 8108kb
input:
58 1 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983
output:
1355.2652876835
result:
ok found '1355.265287683', expected '1355.265287684', error '0.000000000'
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 8100kb
input:
88 30 67117 31903 93080 85196 16438 97116 11907 72959 83651 41273 52873 81892 81468 51323 99992 58869 54258 7183 87358 90990 80596 41252 90769 82705 61434 8524 13575 10787 53950 96768 12062 34637 27806 70937 69653 28380 90236 3352 27537 3873 91006 89790 25369 91825 82734 5588 4539 74118 47098 84741 ...
output:
18791.4855685889
result:
wrong answer 1st numbers differ - expected: '18791.4753541', found: '18791.4855686', error = '0.0000005'