QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733834#9540. Double 11forget-starWA 1ms8116kbC++202.1kb2024-11-10 21:27:072024-11-10 21:27:07

Judging History

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

  • [2024-11-10 21:27:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8116kb
  • [2024-11-10 21:27:07]
  • 提交

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];

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];
const double eps=1e-9;
int solve(double del){
	while(!Q.empty())Q.pop_back();
 	Q.push_back((node){0,1,n});
	fr(i,1,n){
		while(!Q.empty()&&Q.front().r<i)Q.pop_front();
		int p=Q.front().x;
		f[i]=f[p]+w(p,i)+del;
		//printf("%lld %lld %lld %lld %.4lf\n",i,p,Q.front().l,Q.front().r,f[i]);
		d[i]=d[p]+1;
		while(!Q.empty()&&f[Q.back().x]+w(Q.back().x,Q.back().l)>f[i]+w(i,Q.back().l)){
			Q.pop_back();
		}
		//printf("%lld\n",Q.back().x);
		if(Q.empty())Q.push_back((node){i,i+1,n});
		else if(f[Q.back().x]+w(Q.back().x,Q.back().r)>f[i]+w(i,Q.back().r)){
		//	printf("this\n");
			int l=Q.back().l,r=Q.back().r,pos=-1;
			//assert(r==n);
			while(l<=r){
				int mid=(l+r>>1);
				if(f[Q.back().x]+w(Q.back().x,mid)-eps<f[i]+w(i,mid)){
					pos=mid;
					l=mid+1;
				}
				else r=mid-1;
			}
			assert(pos!=-1);
			//printf("insert(%lld,%lld)\n",i,pos+1);
			Q.back().r=pos;
			Q.push_back((node){i,pos+1,n});
		//	printf("=%lld\n",Q.back().x);
		}else if(Q.back().r!=n)Q.push_back((node){i,Q.back().r+1,n}); 

	}
	//printf("%lf %lf\n",w(0,2)+w(2,7),w(0,3)+w(3,7));
	return d[n]; 
}
signed main(){
#ifdef pig
	freopen("pig.in","r",stdin);
	freopen("pig.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;
	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("%.12lf\n",f[n]-l*m);
	return 0;
}

详细

Test #1:

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

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

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

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

input:

1 1
100000

output:

316.227766036987

result:

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

Test #5:

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

input:

7 1
10 47 53 9 83 33 15

output:

41.833001315594

result:

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

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

244.637975628693

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '244.6379756', error = '0.0459010'