QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708056 | #9540. Double 11 | ucup-team3691 | WA | 1ms | 5776kb | C++20 | 1.6kb | 2024-11-03 19:10:49 | 2024-11-03 19:10:49 |
Judging History
answer
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int v[200005];
//int opt[200005];
long long spar[200005];
pair<long double,int> dp[200005];
int n;
pair<long double ,int>best;
long double calc(int i ,int j)
{
if(j==i)
{
return 1e9;
}
long double val=dp[i].first+sqrtl((spar[j]-spar[i])*(j-i));
if(val<=best.first)
{
best.first=val;
best.second=dp[i].second;
}
return val;
}
int check(long double plm)
{
long double valus;
int st,dr,mij;
dp[0]={0,0};
int opt=0;
for(int i=1;i<=n;i++)
{
best={1e9,0};
st=0;
dr=i-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(calc(mij,i)>=calc(mij+1,i))
{
st=mij+1;
}
else
{
dr=mij-1;
}
}
dp[i].first=best.first;
dp[i].second=best.second+1;
dp[i].first+=plm;
}
return dp[n].second;
}
int main()
{
int i,j,k,l,m,val;
long double st=-1e9,dr=1e9,mij;
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
sort(v+1,v+n+1);
for(i=1;i<=n;i++)
{
spar[i]=spar[i-1]+v[i];
}
for(i=1;i<=80;i++)
{
mij=(st+dr)/2;
val=check(mij);
if(val==m)
{
break;
}
else if(val>m)
{
st=mij;
}
else
{
dr=mij;
}
}
cout<<fixed<<setprecision(12)<<dp[n].first-m*mij;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5776kb
input:
4 2 1 2 3 4
output:
6.191147129517
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
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: 0ms
memory: 3908kb
input:
1 1 1
output:
1.000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
1 1 100000
output:
316.227766016838
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3860kb
input:
7 1 10 47 53 9 83 33 15
output:
1000000000.000000000000
result:
wrong answer 1st numbers differ - expected: '41.8330013', found: '1000000000.0000000', error = '23904571.1866878'