QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703021 | #9540. Double 11 | ucup-team5319# | WA | 1ms | 10080kb | C++14 | 2.5kb | 2024-11-02 16:59:07 | 2024-11-02 16:59:08 |
Judging History
answer
//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}
namespace LinkWish{
ci N=200005,eps=1e-12;
si int sign(ld x){
if(x<-eps)return -1;
if(x>eps)return 1;
return 0;
}
int n,m;
ld a[N],sum[N];
ld f[N];int g[N];
si ld w(int l,int r){
return sqrtl((sum[r]-sum[l])/(r-l))*(r-l);
}
int q[N],head,tail;
int L[N],R[N];
si pair<ld,int> calc(ld k){
//cout<<"CAL "<<fixed<<setprecision(10)<<k<<endl;
f[0]=0,g[0]=0;
q[head=tail=1]=0,L[0]=1,R[0]=n;
for(int i=1;i<=n;i++){
//f[i]=1e18;
//for(int j=0;j<i;j++)if(gmin(f[i],f[j]+w(j,i)+k))g[i]=g[j]+1;
//cout<<"GETI "<<i<<' '<<f[i]<<' '<<g[i]<<endl;
for(;head<=tail&&i>R[q[head]];head++);
f[i]=f[q[head]]+w(q[head],i)+k,g[i]=g[q[head]]+1;
//cout<<"GETI "<<i<<' '<<q[head]<<' '<<w(q[head],i)<<' '<<f[i]<<' '<<g[i]<<endl;
auto getp=[&](int x){
int l=max(i+1,L[x]),r=n,mid,res=-1;
while(l<=r){
mid=(l+r)>>1;
if(sign((f[x]+w(x,mid))-(f[i]+w(i,mid)))!=-1)res=mid,r=mid-1;
else l=mid+1;
}
return res;
};
bool flag=true;
while(head<=tail){
int x=q[tail],pos=getp(x);
//if(~pos)cout<<"PO "<<x<<' '<<pos<<' '<<f[x]+w(x,pos)<<' '<<f[i]+w(i,pos)<<endl;
if(pos==-1){
flag=false;
break;
}
if(pos==L[x])tail--;
else{
R[x]=pos-1,L[i]=pos,R[i]=n;
break;
}
}
if(flag)q[++tail]=i;
}
return make_pair(f[n],g[n]);
}
void mian(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int x;cin>>x;
a[i]=x;
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
ld ans=1e18;
ld l=-1e13,r=1e13,mid;
for(int i=1;i<=60;i++){
mid=(l+r)/2;
auto res=calc(mid);
if(res.se<=m){
if(res.se<=m)gmin(ans,res.fi-res.se*mid);
r=mid;
}
else l=mid;
}
long double Ans=ans;
cout<<fixed<<setprecision(10)<<Ans<<endl;
}
}
signed main(){
#ifndef ONLINE_JUDGE
assert(freopen("in.in","r",stdin));
assert(freopen("out.out","w",stdout));
#endif
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
LinkWish::mian();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7852kb
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: 1ms
memory: 7920kb
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: 10072kb
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: 9984kb
input:
1 1 100000
output:
316.2277660168
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 10080kb
input:
7 1 10 47 53 9 83 33 15
output:
41.8330011368
result:
wrong answer 1st numbers differ - expected: '41.8330013', found: '41.8330011', error = '0.0000000'