| 比赛 |
NOIP2025模拟赛2 |
评测结果 |
AAAAAAWWWWAATAAW |
| 题目名称 |
桥梁建设 |
最终得分 |
63 |
| 用户昵称 |
郑霁桓 |
运行时间 |
18.196 s |
| 代码语言 |
C++ |
内存使用 |
6.29 MiB |
| 提交时间 |
2025-11-25 12:18:54 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n;
long long h[100005],w[100005],b[100005],f[100005];
int sk[300005],ss,t;
const long long M=998244353;
int main(){
freopen("building.in","r",stdin);
freopen("building.out","w",stdout);
mt19937 rd(114514);
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<=n;i++){
cin>>w[i];
b[i]=b[i-1]+w[i];
}
sk[1]=ss=1;
for(int i=2;i<=n;i++){
int tt=333,pp=1;
f[i]=1e18;
for(int j=max(1,i-6666);j<i;j++){
if(f[i]>f[j]+b[i-1]-b[j]+(h[i]-h[j])*(h[i]-h[j])){
f[i]=f[j]+b[i-1]-b[j]+(h[i]-h[j])*(h[i]-h[j]);
pp=j;
}
}
for(int j=1;j<=min(5,i-1);j++){
if(f[i]>f[j]+b[i-1]-b[j]+(h[i]-h[j])*(h[i]-h[j])){
f[i]=f[j]+b[i-1]-b[j]+(h[i]-h[j])*(h[i]-h[j]);
pp=j;
}
}
while(tt--){
if(ss<=1) t=1;
else t=rd()%ss+1;
if(t<0) t=-t;
t=sk[t];
if(f[i]>f[t]+b[i-1]-b[t]+(h[i]-h[t])*(h[i]-h[t])) f[i]=f[t]+b[i-1]-b[t]+(h[i]-h[t])*(h[i]-h[t]),pp=t;
}
sk[++ss]=pp;
sk[++ss]=i;
}
cout<<f[n];
return 0;
}