QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733801#9540. Double 11forget-starWA 1ms10004kbC++201.3kb2024-11-10 21:13:252024-11-10 21:13:26

Judging History

This is the latest submission verdict.

  • [2024-11-10 21:13:26]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 10004kb
  • [2024-11-10 21:13:25]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define fr(i,a,b) for(int i(a),end##i(b);i<=end##i;i++)
#define fd(i,a,b) for(int i(a),end##i(b);i>=end##i;i--)
#define de fprintf(stderr,"on-%d\n",__LINE__)
using namespace std;
const int maxn=2e5+5;
int a[maxn];
int n,m;
double f[maxn];
int s[maxn];
int fa[maxn];
int find(int x){
	if(fa[x]==x)return x;
	return fa[x]=find(fa[x]);
}
double S[maxn];
double w(int x,int y){
	return sqrt(1.*(s[y]-s[x])*(y-x));
}
struct node{
	int x,l,r;
};
deque<node> Q;
int d[maxn];
int pre[maxn];
const double eps=1e-9;
int solve(double del){
	fr(i,1,n){
		f[i]=10000;
		fr(j,0,i-1)if(f[i]>f[j]+w(j,i)+del){
			f[i]=f[j]+w(j,i)+del;
			pre[i]=j;
			d[i]=d[j]+1;
		}
	}
	return d[n]; 
}
signed main(){
#ifdef pig
	freopen("pig.in","r",stdin);
	freopen("bf.out","w",stdout);	
#endif
	cin>>n>>m;
	fr(i,1,n)scanf("%lld",&a[i]);
	fr(i,1,n)s[i]=s[i-1]+a[i];
	sort(a+1,a+n+1);
	double l=0,r=1e9,ans1,ans2,X,Y;
	while(r-l>eps){
		double mid=(l+r)/2;
		int t=solve(mid);
	//	cout<<t<<'\n';
		if(t==m){
			printf("%.12lf\n",f[n]-mid*m);
			return 0;
		}
		if(t<m){
			ans1=f[n]-mid*t;
			X=t;
		}
		if(t>m){
			ans2=f[n]-mid*t;
			Y=t;
		}
		if(t<m)r=mid;
		else l=mid;
	}
	//printf("%lf %lf %lf %lf\n",X,Y,ans1,ans2);
	printf("%.12lf\n",ans1+(ans2-ans1)/(Y-X)*(m-X));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 10004kb

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: 1ms
memory: 7972kb

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

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

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: 1ms
memory: 7908kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

237.218705015256

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '237.2187050', error = '0.0141814'