QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876622 | #9540. Double 11 | lunchbox | WA | 1ms | 6248kb | C++17 | 1.3kb | 2025-01-31 09:22:26 | 2025-01-31 09:22:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using db=double;
using ll=long long;
const int N=2e5;
const db EPS=1e-9;
int n,m;
ll s[N+1];
pair<db,int> solve(db pen){
auto C=[&](int l,int r){
return sqrt((r-l)*(s[r]-s[l]))+pen;
};
static pair<db,int>dp[N+1];
auto T=[&](int l,int r){
return make_pair(dp[l].first+C(l,r),dp[l].second+1);
};
dp[0]={0,0};
static pair<int,int>opt[N+1];
int l=0,r=0;
opt[r++]={1,0};
for(int i=1;i<=n;i++){
while(l+1<r&&opt[l+1].first<=i)l++;
dp[i]=T(opt[l].second,i);
while(r-l&&opt[r-1].first>i&&T(opt[r-1].second,opt[r-1].first)>T(i,opt[r-1].first))r--;
if(l==r)opt[r++]={i+1,i};
else{
int low=max(i+1,opt[r-1].first),hi=n+1;
while(low<hi){
int mid=(low+hi)/2;
T(i,mid)<T(opt[r-1].second,mid)?hi=mid:low=mid+1;
}
if(low<=n)opt[r++]={low,i};
}
}
return dp[n];
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>s[i],s[i]+=s[i-1];
db low=0,hi=1e18;
while(hi-low>EPS){
db mid=(low+hi)/2;
auto[a,b]=solve(mid);
b>=m?low=mid:hi=mid;
}
db x=(low+hi)/2;
auto[a,b]=solve(x);
cout<<fixed<<setprecision(12)<<a-x*m<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6248kb
input:
4 2 1 2 3 4
output:
6.191147129557
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6112kb
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: -100
Wrong Answer
time: 1ms
memory: 6240kb
input:
1 1 1
output:
0.000000000000
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '0.0000000', error = '1.0000000'