QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733775 | #9540. Double 11 | forget-star | WA | 1ms | 8104kb | C++20 | 2.0kb | 2024-11-10 20:58:54 | 2024-11-10 20:58:56 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fr(i,a,b) for(int i(a),end##i(b);i<=end##i;i++)
#define fd(i,a,b) for(int i(a),end##i(b);i>=end##i;i--)
#define de fprintf(stderr,"on-%d\n",__LINE__)
using namespace std;
const int maxn=2e5+5;
int a[maxn];
int n,m;
double f[maxn];
int s[maxn];
double S[maxn];
double w(int x,int y){
return sqrt(1.*(s[y]-s[x])*(y-x));
}
struct node{
int x,l,r;
};
deque<node> Q;
int d[maxn];
const double eps=1e-9;
int solve(double del){
while(!Q.empty())Q.pop_back();
Q.push_back((node){0,1,n});
fr(i,1,n){
while(!Q.empty()&&Q.front().r<i)Q.pop_front();
int p=Q.front().x;
f[i]=f[p]+w(p,i)+del;
//printf("%lld %lld %lld %lld %.4lf\n",i,p,Q.front().l,Q.front().r,f[i]);
d[i]=d[p]+1;
while(!Q.empty()&&f[Q.back().x]+w(Q.back().x,Q.back().l)>f[i]+w(i,Q.back().l)){
Q.pop_back();
}
//printf("%lld\n",Q.back().x);
if(Q.empty())Q.push_back((node){i,i+1,n});
else if(f[Q.back().x]+w(Q.back().x,Q.back().r)>f[i]+w(i,Q.back().r)){
// printf("this\n");
int l=Q.back().l,r=Q.back().r,pos=-1;
//assert(r==n);
while(l<=r){
int mid=(l+r>>1);
if(f[Q.back().x]+w(Q.back().x,mid)-eps<f[i]+w(i,mid)){
pos=mid;
l=mid+1;
}
else r=mid-1;
}
assert(pos!=-1);
//printf("insert(%lld,%lld)\n",i,pos+1);
Q.back().r=pos;
Q.push_back((node){i,pos+1,n});
// printf("=%lld\n",Q.back().x);
}else if(Q.back().r!=n)Q.push_back((node){i,Q.back().r+1,n});
}
//printf("%lf %lf\n",w(0,2)+w(2,7),w(0,3)+w(3,7));
return d[n];
}
signed main(){
#ifdef pig
freopen("pig.in","r",stdin);
freopen("pig.out","w",stdout);
#endif
cin>>n>>m;
fr(i,1,n)scanf("%lld",&a[i]);
fr(i,1,n)s[i]=s[i-1]+a[i];
sort(a+1,a+n+1);
double l=0,r=1e8,ans1,ans2,X,Y;
while(r-l>eps){
double mid=(l+r)/2;
int t=solve(mid);
if(t<=m){
ans1=f[n]-mid*t;
X=t;
}
if(t>m){
ans2=f[n]-mid*t;
Y=t;
}
if(t<m)r=mid;
else l=mid;
}
printf("%.12lf\n",ans1+(ans2-ans1)/(Y-X)*(m-X));
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8104kb
input:
4 2 1 2 3 4
output:
6.191147129557
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7920kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
34.134348068238
result:
wrong answer 1st numbers differ - expected: '22.5916254', found: '34.1343481', error = '0.5109293'