QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876624#9540. Double 11lunchboxWA 1ms8288kbC++171.4kb2025-01-31 09:25:462025-01-31 09:25:47

Judging History

This is the latest submission verdict.

  • [2025-01-31 09:25:47]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 8288kb
  • [2025-01-31 09:25:46]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using db=long double;
using ll=long long;
const int N=2e5;
const db EPS=1e-12;
int n,m;
ll s[N+1];
pair<db,int> solve(db pen){
    auto C=[&](int l,int r){
        return sqrt((db)(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';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 6244kb

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: 8160kb

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: 8156kb

input:

1 1
1

output:

1.000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 6244kb

input:

1 1
100000

output:

316.227766016838

result:

ok found '316.227766017', expected '316.227766017', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 8288kb

input:

7 1
10 47 53 9 83 33 15

output:

41.833001326704

result:

ok found '41.833001327', expected '41.833001327', error '0.000000000'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 8288kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

244.045793209415

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '244.0457932', error = '0.0433692'