比赛 2024国庆练习3 评测结果 AAAAAATTTTTTTTTTTTTT
题目名称 信号传递 最终得分 30
用户昵称 ┭┮﹏┭┮ 运行时间 42.003 s
代码语言 C++ 内存使用 3.48 MiB
提交时间 2024-10-06 17:17:24
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;
const ll inf = 1e17;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}


int n,m,k;
int s[N],a[50],id[50];
ll ans = inf; 
ll work(){
	for(int i = 1;i <= m;i++)id[a[i]] = i;
	ll sum = 0;
	for(int i = 1;i < n;i++)
		sum += (id[s[i+1]] >= id[s[i]] ? id[s[i+1]] - id[s[i]] : (ll)k * (id[s[i+1]] + id[s[i]]));
	return sum;
}
int main(){
	freopen("haoi2020_transfer.in","r",stdin);
	freopen("haoi2020_transfer.out","w",stdout);
	n = read(),m = read(),k = read();
	for(int i = 1;i <= n;i++)s[i] = read();
	for(int i = 1;i <= m;i++)a[i] = i;
	do{
//		for(int i = 1;i <= m;i++)cout<<a[i]<<' ';
//		printf("\n--- %lld\n",work());
		ans = min(ans,work());
	}while(next_permutation(a+1,a+1+m));
	printf("%lld\n",ans);

	return 0;

}