QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722731#9540. Double 11eastcloudWA 20ms8024kbC++202.5kb2024-11-07 20:04:012024-11-07 20:04:02

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 20:04:02]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:8024kb
  • [2024-11-07 20:04:01]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array

using namespace std;

#define N 500005

int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

int n,m;
int a[N],s[N];
struct tup{
    int x,l,r;
    tup(int x=0,int l=0,int r=0):x(x),l(l),r(r){}
};

deque<tup> q;
long double f[N];
int g[N];

long double w(int pos,int r){
    return sqrt((r-pos)*(s[r]-s[pos]));
}
long double calc(long double k){
    while(q.size())q.pop_front();
    q.push_front(tup(0,1,n));
    for(int i=1;i<=n;i++){
        int pos=q.front().x;
        f[i]=f[pos]+w(pos,i)+k;g[i]=g[pos]+1;
        if(q.front().l==q.front().r)q.pop_front();
        else{
            auto [x,l,r]=q.front();q.pop_front();
            q.push_front(tup(x,l+1,r));
        }
        while(q.size() && f[i]+w(i,q.back().l)<=f[q.back().x]+w(q.back().x,q.back().l))q.pop_back();
        if(q.size()){
            if(f[i]+w(i,q.back().r)<=f[q.back().x]+w(q.back().x,q.back().r)){
                pos=q.back().x;int l=q.back().l,r=q.back().r;
                while(l<r){
                    int mid=(l+r)>>1;
                    if(f[i]+w(i,mid)<=f[pos]+w(pos,mid))r=mid;
                    else l=mid+1;
                }
                auto [X,L,R]=q.back();q.pop_back();
                q.push_back(tup(X,L,l-1));
            }
        }
        
        if(q.size() && q.back().r!=n)q.push_back(tup(i,q.back().r+1,n));
        if(!q.size())q.push_back(tup(i,i+1,n));
    }
    return f[n];
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif

    n=read(),m=read();
    for(int i=1;i<=n;i++)a[i]=read();
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
    long double L=-0x3f3f3f3f,R=0x3f3f3f3f,eps=1e-12;
    for(int i=1;i<=n;i++)
    while(R-L>eps){
        long double mid=(L+R)/2;calc(mid);
        //cerr<<mid<<' '<<g[n]<<endl;
        if(g[n]<=m)R=mid;
        else L=mid;
    }
    printf("%.12Lf",calc(L)-L*m);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7952kb

input:

4 2
1 2 3 4

output:

6.191147129556

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7840kb

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.591625366514

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5896kb

input:

1 1
1

output:

1.000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7892kb

input:

1 1
100000

output:

316.227766016847

result:

ok found '316.227766017', expected '316.227766017', error '0.000000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7912kb

input:

7 1
10 47 53 9 83 33 15

output:

41.833001326703

result:

ok found '41.833001327', expected '41.833001327', error '0.000000000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 8024kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

233.901654551943

result:

ok found '233.901654552', expected '233.901654552', error '0.000000000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 7960kb

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.265287683559

result:

ok found '1355.265287684', expected '1355.265287684', error '0.000000000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 7960kb

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.475354094100

result:

ok found '18791.475354094', expected '18791.475354094', error '0.000000000'

Test #9:

score: -100
Wrong Answer
time: 20ms
memory: 8020kb

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:

66077.716850906165

result:

wrong answer 1st numbers differ - expected: '66075.5085871', found: '66077.7168509', error = '0.0000334'