QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649183#8242. V-DiagramAa#TL 1ms6004kbC++17791b2024-10-17 21:58:222024-10-17 21:58:23

Judging History

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

  • [2024-10-17 21:58:23]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:6004kb
  • [2024-10-17 21:58:22]
  • 提交

answer

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const double INF=1e18;
int n;
int a[300010];
double s[300010];
bool check(double mid){
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+(double)a[i]-mid;
	double mi=INF;
	for(int i=1;i<n;i++){
		if(a[i]>a[i+1]) mi=min(mi,s[i-1]);
		else if(a[i]==a[i+1]) mi=INF;
		else if(mi!=INF){
			int j=i+1;
			while(j<=n && a[j]>a[j-1]){
				if(s[j++]-mi>=0) return true;
			}
			mi=INF;
			i=j-2;
		}
	}
	return false;
}
signed main(){
	int t;
	scanf("%lld",&t);
	while(t--){
		scanf("%lld",&n);
		for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
		double l=0,r=1e9;
		while(r-l>1e-12){
			double mid=(l+r)/2;
			if(check(mid)) l=mid;
			else r=mid;
		}
		printf("%.18lf\n",r);
	}
	return 0;
} 

详细

Test #1:

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

input:

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

output:

6.750000000000401457
5.833333333333419191

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: