QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#717657#9540. Double 11lzr010506#WA 4ms6060kbC++141.3kb2024-11-06 18:37:302024-11-06 18:37:33

Judging History

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

  • [2024-11-06 18:37:33]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:6060kb
  • [2024-11-06 18:37:30]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define ldb long double
using namespace std;
const ldb eps = 1e-9;
int n, m, a[200010];
ldb D, f[200010];
struct Dat 
{
	int x, k;
} q[200010]; 
int hh, tt;
ldb val(int j, int i) 
{
	return sqrtl(1.0 * (a[i] - a[j]) * (i - j));
}

bool cmp(int i, int j, int k) 
{
	return f[i] + val(i, k) <= f[j] + val(j, k);
}

ldb DP() 
{
	q[0] = (Dat){1, 0}, hh = tt = 0;
	for(int i = 1; i <= n; i ++)
	{
		while (hh < tt && q[hh + 1].x <= i) hh ++;
		f[i] = f[q[hh].k] + val(q[hh].k, i) + D;
		int l = i + 1, r = n + 1;
		while (hh < tt && cmp(i, q[tt].k, q[tt].x)) r = q[tt --].x;
		if (l > q[tt].x) q[tt].x = l;
		else l = q[tt].x + 1;
		while(l < r)
		{
			int mid = l + r >> 1;
			if(cmp(i, q[tt].k, mid)) r = mid;
			else l = mid + 1;
		}
		q[++ tt] = (Dat){r, i};
	}
	return f[n] - m * D;
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++)
		scanf("%d", a + i);
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i ++)
		a[i] += a[i - 1];
	ldb l = 0, r = sqrtl(1.0 * n * a[n]), md, xl, xr, vl, vr;
	while (r - l > eps) 
	{
		md = (l + r) / 2.0;
		xl = D = md - eps / 6.0, vl = DP();
		xr = D = md + eps / 6.0, vr = DP();
		if (vl > vr) r = xr;
		else l = xl;
	}
	D = (l + r) / 2;
	printf("%.30Lf\n", DP());
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
1 2 3 4

output:

6.191147129557119483615063026960

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6060kb

input:

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

output:

22.591625366514128584946585753812

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

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

input:

1 1
1

output:

1.000000000000000000000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

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

input:

1 1
100000

output:

316.227766016837933238381452838439

result:

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

Test #5:

score: 0
Accepted
time: 1ms
memory: 6056kb

input:

7 1
10 47 53 9 83 33 15

output:

41.833001326703777397741923493868

result:

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

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

233.901654551943583834616724459465

result:

ok found '233.901654552', expected '233.901654552', error '0.000000000'

Test #7:

score: 0
Accepted
time: 4ms
memory: 5996kb

input:

58 1
888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983

output:

1355.265287683559022990920084339450

result:

ok found '1355.265287684', expected '1355.265287684', error '0.000000000'

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 6060kb

input:

88 30
67117 31903 93080 85196 16438 97116 11907 72959 83651 41273 52873 81892 81468 51323 99992 58869 54258 7183 87358 90990 80596 41252 90769 82705 61434 8524 13575 10787 53950 96768 12062 34637 27806 70937 69653 28380 90236 3352 27537 3873 91006 89790 25369 91825 82734 5588 4539 74118 47098 84741 ...

output:

18791.485568588896210684424659120850

result:

wrong answer 1st numbers differ - expected: '18791.4753541', found: '18791.4855686', error = '0.0000005'