QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717931 | #9540. Double 11 | Fesdrer | WA | 24ms | 6268kb | C++14 | 1.4kb | 2024-11-06 19:18:16 | 2024-11-06 19:18:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
const int N=2e5+5;
const long double eps=1e-9;
int n,m,s[N],g[N],top;
long double sum[N],f[N];
struct Node{int l,r,x;}base[N];
inline long double w(int l,int r){
return sqrt((sum[r]-sum[l])*(r-l));
}
inline long double turn(int x,int y){
return f[x]+w(x,y);
}
inline bool le(long double x,long double y){
return x<=y||fabs(x-y)<=eps;
}
inline void solve(long double mid){
Node *q=base;
top=1,q[1]=(Node){1,n,0};
for(int i=1;i<=n;i++){
f[i]=turn(q[1].x,i)-mid,g[i]=g[q[1].x]+1;
if(q[1].r==i) q=q+1,--top;
else ++q[1].l;
while(top&&le(turn(i,q[top].l),turn(q[top].x,q[top].l))) --top;
if(top&&le(turn(i,q[top].r),turn(q[top].x,q[top].r))){
int l=q[top].l,r=q[top].r;
while(l<r){
int mid=(l+r)/2;
if(le(turn(i,mid),turn(q[top].x,mid))) r=mid;
else l=mid+1;
}
q[top].r=l-1;
}
if(top&&q[top].r<n) ++top,q[top]=(Node){q[top-1].r+1,n,i};
else if(!top) q[++top]=(Node){i+1,n,i};
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&s[i]);
sort(s+1,s+n+1);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+s[i];
long double l=-20000000000.0,r=0,ans=-1;
while(r-l>=eps){
long double mid=(l+r)/2;
solve(mid);
if(g[n]<m) l=mid;
else if(g[n]>m) r=mid;
else{ans=f[n]+mid*g[n];break;}
}
printf("%.13Lf\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5944kb
input:
4 2 1 2 3 4
output:
6.1911471295571
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5928kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.5916253665141
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5996kb
input:
1 1 1
output:
1.0000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
1 1 100000
output:
316.2277660164982
result:
ok found '316.227766016', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 5940kb
input:
7 1 10 47 53 9 83 33 15
output:
41.8330013267696
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
233.9016545519436
result:
ok found '233.901654552', expected '233.901654552', error '0.000000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5916kb
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.2652876833454
result:
ok found '1355.265287683', expected '1355.265287684', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5860kb
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.4753540941001
result:
ok found '18791.475354094', expected '18791.475354094', error '0.000000000'
Test #9:
score: 0
Accepted
time: 2ms
memory: 6028kb
input:
987 59 5209 1618 7129 7700 893 6647 8231 3314 9844 1347 6789 2711 3968 7416 5864 9190 9564 8874 7357 2087 530 8754 7935 6772 3475 8206 2898 2717 9252 8686 6604 5188 7451 9977 9366 7618 6294 6454 3919 3232 8164 8403 8617 2191 5257 626 8554 1952 1727 4759 205 9453 3312 9387 4798 7774 7005 8892 3570 50...
output:
66075.5085870546468
result:
ok found '66075.508587055', expected '66075.508587055', error '0.000000000'
Test #10:
score: 0
Accepted
time: 2ms
memory: 5936kb
input:
572 529 48392 84311 16267 29255 52276 20511 75195 95522 64489 52229 74478 69766 41777 25148 59976 66512 62953 16779 69312 98832 96131 94700 46403 58028 12868 83503 80367 51036 63398 7509 55193 76715 29143 75925 89863 89244 5561 21242 9047 89763 78016 86274 11382 88520 72343 29729 70986 86600 43707 7...
output:
119849.3226817580610
result:
ok found '119849.322681758', expected '119849.322681758', error '0.000000000'
Test #11:
score: 0
Accepted
time: 17ms
memory: 6132kb
input:
6133 2231 2292 4026 3420 3246 5243 41 4223 468 682 5008 1497 584 1573 7049 5848 4129 5555 9957 9311 7225 6065 9498 3569 1695 717 1968 9690 7557 8700 9427 5142 371 8788 2260 9576 2674 4322 7448 5829 9123 982 7591 438 1590 9459 5982 5002 243 4144 4254 9585 9988 6745 3691 9602 2297 9518 1181 9814 1746 ...
output:
406852.3669004761890
result:
ok found '406852.366900476', expected '406852.366900471', error '0.000000000'
Test #12:
score: -100
Wrong Answer
time: 24ms
memory: 6268kb
input:
8384 5123 19058 18998 87373 34122 75328 47694 7628 72373 15038 82392 99284 70202 49919 24589 3369 42325 8281 56682 20694 78018 67433 34318 26086 37124 18668 94430 78732 53794 58279 21730 60156 95172 58849 10021 70991 26522 88420 92248 63779 33077 16703 80111 94041 85804 3110 21282 12757 69593 53872 ...
output:
-1.0000000000000
result:
wrong answer 1st numbers differ - expected: '1764954.7611287', found: '-1.0000000', error = '1.0000006'