QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345111#8242. V-Diagramoscaryang#AC ✓159ms13196kbC++201.2kb2024-03-06 08:49:502024-03-06 08:49:51

Judging History

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

  • [2024-03-06 08:49:51]
  • 评测
  • 测评结果:AC
  • 用时:159ms
  • 内存:13196kb
  • [2024-03-06 08:49:50]
  • 提交

answer

#include<bits/stdc++.h>

#define db long double
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)

using namespace std;

inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
}

const int N = 3e5 + 5;
const db eps = 1e-9, inf = 1e15;

int n, pos;
db a[N], s[N];

inline int check(db v) {
	db mx1 = -inf, mx2 = -inf;
	rep(i, 1, n) 
		if(i < pos) mx1 = max(mx1, s[i] - (pos - i) * v);
		else if(i > pos) mx2 = max(mx2, s[i] - (i - pos) * v);
	return mx1 + mx2 + a[pos] - v >= 0.0;
}

inline void testcase() {
	n = read(); 
	rep(i, 1, n) a[i] = read(), s[i] = 0;
	rep(i, 2, n) if(a[i] < a[i - 1] && a[i] < a[i + 1]) pos = i;
	rep(i, pos + 1, n) s[i] = s[i - 1] + a[i];
	lep(i, pos - 1, 1) s[i] = s[i + 1] + a[i];
	
	db l = 0, r = 1e9, mid;
	while(l + eps <= r) {
		mid = (l + r) / 2.0;
		if(check(mid)) l = mid;
		else r = mid;
	}
	printf("%.30Lf\n", r);
}

signed main() {
	int t = read(); while(t--) testcase(); 
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

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

output:

6.750000000783906717316540380125
5.833333333732371173141473263968

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 159ms
memory: 5792kb

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:

833782882.666666666686069220304489135742
435670789.666666667326353490352630615234
770302316.666666667093522846698760986328
608562705.000000000698491930961608886719
296293261.666666666802484542131423950195
319149416.333333334070630371570587158203
571816312.666666667384561151266098022461
223646002.333...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 62ms
memory: 5924kb

input:

10000
4
194123849 79274911 191162487 570110764
86
957917218 915359202 914726017 873273226 867724859 867674150 809652204 805531383 745262007 743835491 727071232 714782071 645394643 639432679 594879540 587173904 583418126 560538589 518721836 469558994 427721766 411582333 404948350 402948978 357228675 ...

output:

258668002.750000000640284270048141479492
527118856.755555555835599079728126525879
495489050.352941176621243357658386230469
525232841.150000000023283064365386962891
472025965.700000000302679836750030517578
546154003.125000000698491930961608886719
543366581.516129032301250845193862915039
254833443.200...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 61ms
memory: 5944kb

input:

1000
357
999039850 998470288 997001139 994662646 991895879 986310400 986201443 971759917 969292691 967648767 963962459 963603069 959189978 954532156 936459732 927268934 925199105 918559276 906725073 903024522 891346023 886340039 872105565 871168803 867996002 862017068 851751458 849013653 847967471 8...

output:

493655540.627450980391586199402809143066
515292672.416666667500976473093032836914
498032099.981481481838272884488105773926
481127839.625000000407453626394271850586
526924843.336283186567015945911407470703
488725771.457191781664732843637466430664
533287305.946428571478463709354400634766
438471966.333...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 58ms
memory: 8072kb

input:

100
1152
999672457 998726401 995956848 990786177 990411263 984766135 983346495 982593760 982250360 980153123 975942408 974567443 973232196 970303426 967381747 966555245 966400114 965308448 961378668 960953166 960451796 957742285 957273419 956986267 956737190 956352393 954265694 953272327 952096100 9...

output:

504372755.029159520170651376247406005859
495156421.177481974649708718061447143555
511090599.621761658228933811187744140625
497554816.124314442859031260013580322266
514036973.345568487362470477819442749023
509664056.912052117695566266775131225586
500937804.963666391849983483552932739258
515638734.543...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 58ms
memory: 10068kb

input:

10
29043
999960631 999958134 999901247 999737433 999520614 999519045 999460207 999379140 999279078 999214335 999048733 998866618 998693991 998649435 998636721 998575997 998542938 998513617 998477418 998422985 998403836 998262102 998124856 998017139 998013085 997959891 997944356 997893923 997524695 9...

output:

497704976.046566095028538256883621215820
500149119.648922160442452877759933471680
499456770.182770401646848767995834350586
500288732.702417855558451265096664428711
505548409.832386364520061761140823364258
502546060.651801801926922053098678588867
500560614.163130289700347930192947387695
502706676.399...

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 63ms
memory: 13196kb

input:

1
300000
999995409 999991717 999988340 999981078 999978323 999978096 999977575 999967796 999958049 999950023 999927083 999923421 999918905 999916153 999912740 999911175 999907902 999902376 999899096 999889548 999888902 999880881 999878324 999867494 999866296 999864006 999863565 999859765 999841183 9...

output:

499603654.397238609497435390949249267578

result:

ok found '499603654.397238612', expected '499603654.397238612', error '0.000000000'

Extra Test:

score: 0
Extra Test Passed