记录编号 |
385426 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[SDOI 2016 Round1] 征途 |
最终得分 |
100 |
用户昵称 |
Marvolo |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.194 s |
提交时间 |
2017-03-21 13:20:32 |
内存使用 |
0.34 MiB |
显示代码纯文本
#include<cstring>
#include<cstdio>
#include<cctype>
#define N 3010
#define INF 0x3f3f3f3f
using namespace std;
int n,m,i,temp,j,head,tail;
int a[N],f[N],g[N],z[N];
inline int read(){
int p=0; char c;
while(c=getchar(),!isdigit(c));
while(p=(p<<1)+(p<<3)+c-48,c=getchar(),isdigit(c));
return p;
}
inline int Sqrt(int x){return x*x;}
inline double K(int x,int y){
return (double)((g[x]-g[y])+Sqrt(a[x])-Sqrt(a[y]))/(double)(a[x]-a[y]);}
int main(){
freopen("menci_journey.in","r",stdin);
freopen("menci_journey.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++) scanf("%d",&a[i]),a[i]+=a[i-1];
memset(f,INF,sizeof(f)); f[0]=0;
for (j=1;j<=m;j++){
memcpy(g,f,sizeof(f)); memset(f,0,sizeof(f));
z[0]=head=tail=0;
for (i=1;i<=n;i++){
while (head<tail&&K(z[head+1],z[head])<2*a[i]) head++;
temp=z[head];
f[i]=g[temp]+Sqrt(a[i]-a[temp]);
while (head<tail&&K(z[tail],z[tail-1])>K(z[tail],i)) tail--;
z[++tail]=i;
}
}
printf("%d\n",m*f[n]-Sqrt(a[n]));
return 0;
}