QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#886652 | #9540. Double 11 | Coffins | WA | 0ms | 10208kb | C++17 | 1.4kb | 2025-02-07 10:29:25 | 2025-02-07 10:29:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
using ld=long double;
const ld inf=1e18+7;
const ld eps=1e-10;
int n,m;ld s[N],f[N];
int p[N];ld calc(int x,int y)
{return f[x]+sqrtl((s[y]-s[x])*(y-x));}
int L[N],R[N],x[N],ql,qr;
int main()
{
cin>>n>>m;for(int i=1;i<=n;i++)cin>>s[i];
sort(s+1,s+n+1);for(int i=1;i<=n;i++)s[i]+=s[i-1];
ld l=0,r=1e11,c;ld rs=0;
for(int tm=1;tm<=100;tm++)
{
c=(l+r)*0.5;f[0]=0;
ql=qr=1;L[1]=1,R[1]=n,x[1]=0;
for(int i=1;i<=n;i++)
{
p[i]=x[ql],f[i]=calc(p[i],i)+c;
if(i==R[ql])ql++;else L[ql]=i+1;
while(qr>=ql)
{
int ps=L[qr];
if(calc(x[qr],ps)-
calc(i,ps)<eps)
qr--;else break;
}if(qr<ql)
{
qr++;
L[qr]=i+1,R[qr]=n,x[qr]=i;
continue;
}int l=L[qr]+1,r=R[qr]+1,mid;
int x=i,y=::x[qr];while(l<r)
{
mid=(l+r)>>1;
if(calc(y,mid)-calc(x,mid)<eps)
r=mid;else l=mid+1;
}R[qr]=l-1;qr++;
L[qr]=l,R[qr]=n,::x[qr]=i;
}int ps=n,ct=0;
while(ps)ct++,ps=p[ps];
if(ct==m){rs=f[n]-c*m;break;}
if(ct<m)r=c;else l=c;
}cout<<setprecision(12)<<rs<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10208kb
input:
4 2 1 2 3 4
output:
0
result:
wrong answer 1st numbers differ - expected: '6.1911471', found: '0.0000000', error = '1.0000000'