QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326641#8242. V-Diagramucup-team134#TL 0ms3900kbC++17817b2024-02-13 17:22:562024-02-13 17:22:56

Judging History

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

  • [2024-02-13 17:22:56]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3900kb
  • [2024-02-13 17:22:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ldb double

const int N=300050;
const ldb eps=1e-10;
int a[N];
int main(){
	int t;
	scanf("%i",&t);
	while(t--){
		int n;
		scanf("%i",&n);
		for(int i=1;i<=n;i++)scanf("%i",&a[i]);
		int j;
		for(int i=2;i<n;i++){
			if(a[i]<a[i-1] && a[i]<a[i+1]){
				j=i;
			}
		}
		ldb bot=0,top=2e9;
		int cnt=0;
		while(top-bot>eps){
			cnt++;

			ldb mid=(top+bot)/2;
			ldb sum=0,L,R;
			for(int i=j-1;i>=0;i--){
				sum+=a[i]-mid;
				if(i==j-1 || sum>L)L=sum;
			}
			sum=0;
			for(int i=j+1;i<=n;i++){
				sum+=a[i]-mid;
				if(i==j+1 || sum>R)R=sum;
			}
			ldb best=L+R+a[j]-mid;
			if(best>=0){
				bot=mid;
			}else{
				top=mid;
			}
		}
		printf("%.12f\n",(top+bot)/2);
		//printf("cnt:%i\n",cnt);
	}
	return 0;
}

详细

Test #1:

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

input:

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

output:

6.749999999998
5.833333333326

result:

ok 2 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

100000
3
948511478 739365502 813471668
3
881046825 27458122 398507422
3
987554257 399092415 924260278
3
984128569 125199021 716360525
3
529589236 45783262 313507287
3
645443456 85994112 226010681
3
914820717 228360911 572267310
3
418958362 56703604 195276041
3
64461646 26764720 26995581
3
914535039 ...

output:


result: