比赛 |
集训 |
评测结果 |
TTTTAAATTTA |
题目名称 |
兔子集团军 |
最终得分 |
36 |
用户昵称 |
pcx |
运行时间 |
14.069 s |
代码语言 |
C++ |
内存使用 |
27.81 MiB |
提交时间 |
2025-07-03 11:12:10 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const long long M=0x7FFFFFFFFFFFFFFF;
typedef long long LL;
LL n,c[N],v[N],f1,f[N];
pair <LL,LL> pos[N];
int main(){
freopen("RRR.in","r",stdin);
freopen("RRR.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>c[i];
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n;i++){
cin>>f1;f[i]=f1*f1;
}
for(int i=1;i<=n;i++){
pos[i]=make_pair(n+1,-1);
}
for(LL i=1;i<=n;i++){
int x=c[i];
pos[x].first=min(pos[x].first,i);
pos[x].second=max(pos[x].second,i);
}
long long minc=M;
for(int l=1;l<=n;l++){
int r=pos[c[l]].second;
for(int i=l;i<=r;i++){
r=max(r,(int)pos[c[i]].second);
if(r>n) break;
}
bool j=1;
for(int i=l;i<=r;i++){
if(pos[c[i]].first<l||pos[c[i]].second>r){
j=0;break;
}
}
if(j){
LL cost=0;
for(int i=l;i<=r;i++){
int k=i-l+1;
cost+=v[i]*f[k];
}
minc=min(minc,cost);
}
}
cout<<minc;
return 0;
}