QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276761#4105. 征途SoyTony80 93ms74352kbC++141023b2023-12-06 10:21:122023-12-06 10:21:14

Judging History

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

  • [2023-12-06 10:21:14]
  • 评测
  • 测评结果:80
  • 用时:93ms
  • 内存:74352kb
  • [2023-12-06 10:21:12]
  • 提交

answer

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

typedef long long ll;
const int maxn=3005;

inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}

int n,m;
int a[maxn],sum[maxn];
inline ll w(int l,int r){
    return 1ll*(sum[n]-m*(sum[r]-sum[l]))*(sum[n]-m*(sum[r]-sum[l]));
}
ll f[maxn][maxn];
void solve(int i,int l1,int r1,int l2,int r2){
    if(l1>r1) return;
    int mid=(l1+r1)>>1;
    int x=0;
    for(int j=l2;j<=min(mid,r2);++j){
        if(f[i-1][j]+w(j,mid)<f[i][mid]) f[i][mid]=f[i-1][j]+w(j,mid),x=j;
    }
    if(l1==r1) return;
    solve(i,l1,mid-1,l2,x),solve(i,mid+1,r1,x,r2);
}

int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i) a[i]=read(),sum[i]=sum[i-1]+a[i];
    memset(f,0x3f,sizeof(f));
    for(int i=1;i<=n;++i) f[1][i]=w(0,i);
    for(int i=2;i<=m;++i) solve(i,1,n,1,n);
    printf("%lld\n",f[m][n]/m);
    return 0;
}

详细

Test #1:

score: 10
Accepted
time: 3ms
memory: 74068kb

input:

9 5
440 546 398 3132 3121 2939 3139 1476 3075

output:

13040944

result:

ok single line: '13040944'

Test #2:

score: 10
Accepted
time: 3ms
memory: 74172kb

input:

10 6
1769 223 1182 1486 1251 30 373 164 1891 1657

output:

1108740

result:

ok single line: '1108740'

Test #3:

score: 10
Accepted
time: 4ms
memory: 74352kb

input:

8 3
1752 1914 1597 3051 2197 3279 266 3388

output:

5628350

result:

ok single line: '5628350'

Test #4:

score: 10
Accepted
time: 0ms
memory: 74352kb

input:

92 67
117 37 197 297 148 20 100 201 287 209 239 27 85 83 169 35 108 71 90 89 210 37 89 110 262 170 59 290 110 249 90 181 77 60 4 316 17 196 324 135 269 32 14 260 157 148 207 263 71 207 156 291 270 258 168 33 34 165 130 182 168 229 54 309 124 155 19 205 303 251 11 175 23 136 174 217 4 261 149 310 95 ...

output:

17552120

result:

ok single line: '17552120'

Test #5:

score: 10
Accepted
time: 0ms
memory: 74116kb

input:

76 18
296 195 25 355 334 311 266 394 13 345 169 29 55 114 257 159 253 285 180 368 21 149 11 315 184 209 347 11 194 26 50 92 150 27 80 1 17 178 382 257 259 391 114 173 262 278 136 381 83 234 303 161 358 153 88 167 214 367 146 360 278 355 136 107 115 1 352 333 341 14 83 51 345 8 249 88

output:

2106080

result:

ok single line: '2106080'

Test #6:

score: 10
Accepted
time: 0ms
memory: 74168kb

input:

82 29
309 40 38 259 308 59 200 235 308 327 77 122 238 23 351 156 227 225 158 135 253 253 1 277 25 53 257 171 92 13 10 342 17 103 137 11 64 131 258 60 225 363 63 130 24 290 252 237 80 152 77 150 312 294 163 330 232 351 211 191 29 153 330 56 306 89 261 93 124 62 58 329 291 68 30 3 119 39 221 123 140 75

output:

4050584

result:

ok single line: '4050584'

Test #7:

score: 10
Accepted
time: 93ms
memory: 74136kb

input:

2970 1905
1 6 1 10 3 2 4 6 2 2 6 7 4 9 3 6 4 8 9 7 1 6 7 1 6 9 4 8 9 9 3 4 5 6 5 6 8 3 8 8 5 9 3 6 2 9 7 2 9 10 9 7 7 3 2 6 6 3 9 2 3 8 5 2 3 4 4 1 10 2 9 2 10 7 2 4 2 9 9 4 5 7 4 1 7 2 7 2 9 5 9 8 5 5 10 8 3 4 7 9 5 2 7 10 9 2 5 4 4 9 10 8 2 6 10 1 6 9 8 8 7 8 1 6 8 7 6 6 2 1 8 8 9 3 4 6 8 6 5 4 5 ...

output:

10041174

result:

ok single line: '10041174'

Test #8:

score: 10
Accepted
time: 12ms
memory: 74320kb

input:

2583 171
8 5 6 11 11 2 7 8 10 4 7 7 2 2 3 7 11 4 1 11 7 10 10 1 11 4 8 1 1 8 3 3 1 7 5 2 6 11 4 2 11 11 3 10 4 2 6 8 6 2 6 3 2 3 3 5 5 11 6 5 4 10 1 9 1 1 7 2 5 8 9 9 1 8 6 1 11 11 11 2 3 9 8 3 9 8 10 6 6 7 9 3 1 6 3 5 2 1 8 11 3 3 3 6 8 1 3 9 11 9 10 8 3 3 11 7 1 6 6 3 3 8 6 6 11 10 1 7 3 8 3 1 7 4...

output:

112832

result:

ok single line: '112832'

Test #9:

score: 0
Time Limit Exceeded

input:

2146 152
6 1 4 6 15 20 15 13 20 20 20 13 11 9 14 15 3 4 16 16 16 3 1 10 16 3 16 12 2 12 14 20 14 4 10 20 2 8 16 4 1 8 12 16 3 9 20 15 9 14 13 9 17 9 16 11 11 14 18 6 5 20 11 3 7 20 5 3 6 20 2 11 11 13 4 9 8 19 11 16 13 4 7 3 15 4 12 13 20 17 13 1 12 20 9 19 13 1 6 15 10 14 16 8 6 11 10 10 2 18 19 6 ...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

2978 186
2 15 7 17 8 16 1 5 12 1 6 2 10 10 17 16 15 20 5 16 13 2 13 11 8 3 3 18 9 16 4 2 1 7 8 16 10 17 2 9 16 6 9 19 5 4 15 1 1 11 5 18 13 17 20 1 19 7 16 13 11 5 12 14 6 13 7 9 13 7 7 7 6 1 1 13 17 19 2 16 4 7 6 1 15 18 11 17 15 16 3 1 9 6 13 3 15 7 15 10 17 2 17 9 1 8 10 20 11 7 17 11 4 12 12 1 1...

output:


result: