比赛 集训 评测结果 TTTTTTTTTTW
题目名称 兔子集团军 最终得分 0
用户昵称 rb_tree 运行时间 18.724 s
代码语言 C++ 内存使用 26.13 MiB
提交时间 2025-07-03 09:55:16
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
	int x=0,w=1;
	char ch=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*w;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>=10) write(x/10);
	putchar((x%10)^48);
}
const int N=1e6+5;
int c[N],v[N],f[N],n,cc[N],ccc[N];
int check()
{
    int aans=0x7fffffffffffffff;
    for(int l=1;l<=n;l++)
    {
        int ans=0,cnt=0,ccnt=0;
        memset(ccc,0,sizeof(ccc));
        for(int r=l;r<=n;r++)
        {
            ans+=v[r]*f[r-l+1]*f[r-l+1];
            ccc[c[r]]++;
            if(ccc[c[r]]==1) ccnt++;
            if(ccc[c[r]]==cc[c[r]]) cnt++;
        }
        if(cnt==ccnt) aans=min(aans,ans);
    }
    return aans;
}
signed main()
{
    freopen("RRR.in","r",stdin);
    freopen("RRR.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++) c[i]=read(),cc[c[i]]++;
    for(int i=1;i<=n;i++) v[i]=read();
    for(int i=1;i<=n;i++) f[i]=read();
    write(check());
    fclose(stdin);
    fclose(stdout);
    return 0;
}
/*
3
6 1 2
6 2 3
0 1 0
*/
/*
6
*/