QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726121#9540. Double 11diandian2020WA 1ms8036kbC++141.2kb2024-11-08 21:44:242024-11-08 21:44:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 21:44:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8036kb
  • [2024-11-08 21:44:24]
  • 提交

answer

#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> PII;
const int N=2e5+9;
int n,m; LL s[N];
LD f[N]; int g[N];
int q[N],r[N],hh,tt;
LD get(int i,int j){
//	printf("g %d %d %Lf %Lf\n",i,j,sqrtl((i-j)*(s[i]-s[j])),f[j]+sqrtl((i-j)*(s[i]-s[j])));
	return f[j]+sqrtl((i-j)*(s[i]-s[j]));
}
int find(int x,int y){
	int l=x,r=n+1;
	while(l<r){
		int mid=l+r>>1;
		if(get(mid,x)+1e-12>=get(mid,y)) r=mid;
		else l=mid+1;
	}
	return l;
}
int check(LD mid){
	q[hh=tt=0]=0;
	for(int i=1;i<=n;i++){
		while(hh<tt&&r[hh]<=i) hh++;
		f[i]=get(i,q[hh])+mid; g[i]=g[q[hh]]+1;
//		printf("%d %d %Lf %Lf %d\n",q[hh],i,sqrtl((i-q[hh])*(s[i]-s[q[hh]])),f[i],g[i]);
		while(hh<tt&&r[tt-1]>=find(q[tt],i)) tt--;
		r[tt]=find(q[tt],i); q[++tt]=i;
	}
	return g[n];
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&s[i]),s[i]+=s[i-1];
	LD l=0,r=1e18/2e5;
	while(r-l>1e-9){
		LD mid=(l+r)/2;
		if(check(mid)<=m) r=mid;
		else l=mid;
	}
	check(r);
	printf("%.9Lf\n",f[n]-r*m);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5948kb

input:

4 2
1 2 3 4

output:

6.191147130

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

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

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.591625367

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

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

input:

1 1
1

output:

1.000000000

result:

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

Test #4:

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

input:

1 1
100000

output:

316.227766017

result:

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

Test #5:

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

input:

7 1
10 47 53 9 83 33 15

output:

41.833001327

result:

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

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

243.264376411

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '243.2643764', error = '0.0400285'