| 比赛 |
NOIP2025模拟赛2 |
评测结果 |
AAAAATTTTTTTTTTT |
| 题目名称 |
桥梁建设 |
最终得分 |
31 |
| 用户昵称 |
李金泽 |
运行时间 |
23.112 s |
| 代码语言 |
C++ |
内存使用 |
3.23 MiB |
| 提交时间 |
2025-11-25 09:59:48 |
显示代码纯文本
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define N 100005
#define int long long
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int n,h[N],w[N],s[N],f[N];
int min(int x,int y){return x<y?x:y;}
int po(int x){return x*x;}
int read(){
int sum=0;bool f=0;char c=getchar();
for(;c<48||c>57;c=getchar())if(c==45)f=1;
for(;c>=48&&c<=57;c=getchar())sum=sum*10+(c&15);
return f?-sum:sum;
}
signed main(){
freopen("building.in","r",stdin);freopen("building.out","w",stdout);
n=read();
fo(i,1,n)h[i]=read();
fo(i,1,n)w[i]=read(),s[i]=s[i-1]+w[i];
fo(i,2,n)
{
f[i]=f[1]+s[i-1]-s[1]+po(h[i]-h[1]);
fo(j,2,i-1)f[i]=min(f[i],f[j]+s[i-1]-s[j]+po(h[i]-h[j]));
}
printf("%lld",f[n]);
return 0;
}