QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#525113#2507. 方差wangjiaweishishabi100 ✓12ms7952kbC++231.5kb2024-08-20 13:04:422024-08-20 13:04:43

Judging History

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

  • [2024-08-20 13:04:43]
  • 评测
  • 测评结果:100
  • 用时:12ms
  • 内存:7952kb
  • [2024-08-20 13:04:42]
  • 提交

answer

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <assert.h>
using namespace std;
#define re register
#define sf scanf
#define pf printf
#define nl() putchar('\n')
#define ll long long
#define _for(i, a, b) for(re int (i) = (a); (i) < (b); ++(i))
#define _rfor(i, a, b) for(re int (i) = (a); (i) <= (b); ++(i))
#define inf 0x7ffffffffffffffll
#define maxn 10005
#define maxx 500005
int rdnt(){
   re int x = 0, sign = 1;
   re char c = getchar();
   while (c < '0' || c > '9') { if (c == '-') sign = -1; c = getchar(); }
   while (c >= '0' && c <= '9') x = (x<<3) + (x<<1) + (c ^ 48), c = getchar();
   return x * sign;
}
ll  a[maxn], d[maxn], s[maxn], f[maxx];
inline void ud(re ll &x, re ll y){ if (y < x) x = y; }
int main(){
   #ifndef ONLINE_JUDGE
   freopen("variance.in", "r", stdin);
   freopen("variance.out", "w", stdout);
   #endif
   re int n = rdnt(), rg = 0; re ll mx = 0, ma = a[1] = rdnt();
   _rfor(i, 2, n) d[i-1] = (a[i] = rdnt())-a[i-1], ma = max(ma, a[i]);
   _rfor(x, 1, ma*n) f[x] = inf; f[0] = s[0]= 0;
   sort(d+1, d+n);
   _for(i, 1, n){
   	s[i] = s[i-1] + d[i];
   	if (d[i] == 0) continue;
   	for(re int x = mx; x >= 0; --x){
   		if (f[x] == inf) continue;
   		ud(f[x+i*d[i]], f[x] + 2*x*d[i] + i*d[i]*d[i]);
   		ud(f[x+s[i]], f[x] + s[i]*s[i]);
   		mx = max(mx, max(x+i*d[i], x+s[i]));
   		f[x] = inf;
   	}
   }
   re ll ans = inf;
   _rfor(x, 0, mx) if (f[x] < inf) ud(ans, n*f[x] - (ll)x*x);
   pf("%lld\n", ans);
   return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

4
2 3 4 8

output:

83

result:

ok single line: '83'

Test #2:

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

input:

4
1 1 3 6

output:

51

result:

ok single line: '51'

Test #3:

score: 4
Accepted
time: 1ms
memory: 5784kb

input:

4
5 5 6 10

output:

59

result:

ok single line: '59'

Test #4:

score: 4
Accepted
time: 1ms
memory: 5844kb

input:

10
1 10 19 22 31 32 32 36 39 39

output:

9604

result:

ok single line: '9604'

Test #5:

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

input:

10
5 6 13 21 27 27 30 32 34 37

output:

6956

result:

ok single line: '6956'

Test #6:

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

input:

14
2 2 4 4 8 8 8 10 11 11 11 16 18 18

output:

2208

result:

ok single line: '2208'

Test #7:

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

input:

15
1 3 5 7 7 10 10 10 10 11 13 13 18 18 20

output:

4076

result:

ok single line: '4076'

Test #8:

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

input:

15
1 1 2 4 4 6 6 9 9 11 11 14 16 16 18

output:

3524

result:

ok single line: '3524'

Test #9:

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

input:

20
70 75 87 93 93 96 102 111 116 128 142 169 189 194 206 215 215 215 230 240

output:

613931

result:

ok single line: '613931'

Test #10:

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

input:

20
45 56 68 90 111 145 154 155 161 171 176 187 190 196 201 216 222 280 280 280

output:

955084

result:

ok single line: '955084'

Test #11:

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

input:

20
20 52 88 96 102 113 137 144 150 159 185 188 188 188 201 202 229 246 261 273

output:

1301784

result:

ok single line: '1301784'

Test #12:

score: 4
Accepted
time: 1ms
memory: 7828kb

input:

20
48 58 63 69 83 83 89 112 118 121 132 139 156 169 169 169 181 201 208 238

output:

742851

result:

ok single line: '742851'

Test #13:

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

input:

50
1 3 3 4 6 6 6 9 10 11 12 13 14 14 14 15 18 21 23 25 25 25 29 30 31 34 34 35 36 41 41 41 42 42 42 47 50 50 51 51 64 64 65 65 66 69 69 69 70 70

output:

329064

result:

ok single line: '329064'

Test #14:

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

input:

50
1 2 2 3 4 5 9 10 14 15 17 17 19 20 22 22 23 24 28 29 29 30 31 31 31 32 34 35 39 39 40 40 41 41 42 42 44 44 45 45 46 47 48 52 53 54 65 66 67 69

output:

393256

result:

ok single line: '393256'

Test #15:

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

input:

50
2 2 5 6 7 7 7 8 9 10 10 10 15 15 15 16 18 18 19 23 23 24 27 27 29 31 32 32 36 36 37 40 43 44 46 46 47 48 50 51 52 52 65 66 66 66 67 67 68 70

output:

336136

result:

ok single line: '336136'

Test #16:

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

input:

100
1 1 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 7 7 7 8 8 9 9 9 10 10 10 10 10 11 11 11 12 12 12 12 13 13 13 13 21 21 21 22 22 23 24 24 24 24 25 26 26 26 26 26 27 27 27 28 28 28 28 29 29 30 30 30 31 32 32 32 32 32 33 34 34 34 35 35 35 36 36 37 38 38 38 38 39 39 39 39 39 40 40 40 40

output:

302700

result:

ok single line: '302700'

Test #17:

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

input:

100
1 1 2 2 2 2 2 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 7 7 7 8 8 8 9 10 10 11 11 11 11 12 12 12 13 13 13 21 21 21 21 22 22 22 23 23 24 24 24 24 24 25 26 26 26 26 26 26 26 27 27 28 28 28 28 28 29 29 29 30 30 30 30 31 31 31 31 31 32 33 34 34 35 35 35 35 35 35 37 37 38 38 38 38 39

output:

276964

result:

ok single line: '276964'

Test #18:

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

input:

100
1 1 1 2 3 3 3 3 3 3 4 5 5 5 6 6 6 6 7 7 7 7 7 8 8 8 8 9 9 10 10 10 11 11 13 13 13 13 21 21 21 22 22 22 22 23 23 23 23 23 23 23 24 24 24 25 25 26 27 27 27 27 28 28 28 29 29 29 29 30 30 30 31 32 32 32 33 33 34 34 34 34 34 35 35 36 37 37 37 37 37 37 38 38 38 38 39 40 40 40

output:

302700

result:

ok single line: '302700'

Test #19:

score: 4
Accepted
time: 6ms
memory: 6740kb

input:

400
1 1 2 2 3 4 4 5 5 6 6 6 6 7 8 8 8 10 10 10 11 11 11 11 11 11 12 12 12 12 13 14 14 15 15 15 16 16 17 18 18 18 19 20 22 23 29 29 30 31 31 32 32 32 33 33 34 34 35 35 35 36 37 37 37 37 37 37 37 37 37 38 38 38 38 38 38 39 39 40 41 42 46 47 48 49 49 50 50 50 51 51 52 52 53 53 53 53 55 56 56 56 58 58 5...

output:

266737600

result:

ok single line: '266737600'

Test #20:

score: 4
Accepted
time: 2ms
memory: 5536kb

input:

400
1 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 6 6 7 8 9 10 10 16 17 18 19 19 20 20 20 20 20 21 22 23 23 24 25 25 25 25 25 25 25 25 26 26 27 27 28 29 29 29 29 29 29 29 30 30 30 30 30 30 30 30 30 30 30 31 31 32 33 34 34 35 35 35 35 37 37 38 38 38 38 39 39 40 43 44 45 45 45 45 46 47 48 49 50 50 50 58 59 59...

output:

271813084

result:

ok single line: '271813084'

Test #21:

score: 4
Accepted
time: 6ms
memory: 7396kb

input:

400
1 1 1 2 3 3 4 5 5 5 5 5 5 5 6 6 6 7 7 9 9 9 10 11 12 12 12 13 13 14 14 15 16 17 17 18 18 18 18 18 18 19 20 20 20 21 21 22 23 23 24 25 26 27 27 28 28 30 30 31 31 32 33 33 33 34 34 34 35 35 35 36 36 36 37 38 39 39 40 40 41 41 41 42 42 42 42 43 44 45 46 46 46 46 47 47 48 48 49 50 51 51 52 53 58 58 ...

output:

263380775

result:

ok single line: '263380775'

Test #22:

score: 4
Accepted
time: 2ms
memory: 6568kb

input:

400
1 2 3 4 5 5 5 14 15 15 15 16 16 16 17 18 18 18 18 19 19 19 20 21 26 27 28 29 29 29 29 29 30 30 31 31 31 31 32 33 34 34 34 35 36 37 37 37 38 39 40 40 41 41 43 44 44 45 46 46 46 47 47 48 49 50 50 50 51 52 52 55 55 55 56 57 57 57 58 58 58 59 59 59 59 60 62 63 64 64 64 65 65 65 66 66 67 68 68 68 69 ...

output:

256248151

result:

ok single line: '256248151'

Test #23:

score: 4
Accepted
time: 12ms
memory: 7948kb

input:

10000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

104249375

result:

ok single line: '104249375'

Test #24:

score: 4
Accepted
time: 9ms
memory: 7952kb

input:

10000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

104249375

result:

ok single line: '104249375'

Test #25:

score: 4
Accepted
time: 8ms
memory: 7940kb

input:

10000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

104249375

result:

ok single line: '104249375'

Extra Test:

score: 0
Extra Test Passed