You've got a string a1,a2,…,ana1,a2,…,an, consisting of zeros and ones.
Let's call a sequence of consecutive elements ai,ai+1,…,ajai,ai + 1,…, aj (1≤i≤j≤n1≤ i≤ j≤ n) a substring of string aa.
You can apply the following operations any number of times:
- Choose some substring of string aa (for example, you can choose entire string) and reverse it, paying xx coins for it (for example, «0101101» →→ «0111001»);
- Choose some substring of string aa (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying yy coins for it (for example, «0101101» →→ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers nn, xx and yy (1≤n≤300000,0≤x,y≤1091 ≤ n ≤ 300000,0≤x,y≤109) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string aa of length nn, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 00, if you do not need to perform any operations.
5 1 10 01000
11
5 10 1 01000
2
7 2 3 1111111
0
In the first sample, at first you need to reverse substring [1…2][1…2], and then you need to invert substring [2…5][2…5].
Then the string was changed as follows:
«01000» →→ «10000» →→ «11111».
The total cost of operations is 1+10=111+10=11.
In the second sample, at first you need to invert substring [1…1][1…1], and then you need to invert substring [3…5][3…5].
Then the string was changed as follows:
«01000» →→ «11000» →→ «11111».
The overall cost is 1+1=21+1=2.
#include<algorithm>
#include<iostream>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define maxn 300000
#define UB (maxn*64)
#define ll __int64
#define INF 10000000
using namespace std;
string s;
/*
题目大意:给定一串0-1序列,定义两种操作,
操作一:选取一段把数字互换,
操作二:把连续串转置。
操作到最后要把串全部置为一,问最小的操作代价。
首先因为可以选取任意连续的串,所以这个长串其实就等价于
01序列,每个值只连续出现一次,这样一个串的特征就提取出来了,就是这个串中0的个数(压缩后的串),
假定0的段数是m,其次是数学技巧体现的地方,初始操作肯定是最笨的,每个都使用第一种操作,
把所有的零全部置换。那么可以看到,每进行一次操作一,操作二的次数就减少一次。
所以操作综合不变,那么至此,已经可以枚举出答案了。
操作一和操作二的权重不一样,分别为x和y,枚举即可。
*/
int c;
int main()
{
int n,x,y;cin>>n>>x>>y; cin>>s;
int flag=1,cnt=0,l=s.size();
for(int i=0;i<l;i++)
{
c=s[i]-'0';
if(c==flag) continue;
else
{
if(c==0) cnt++;
flag=c;
}
}
if(cnt==0) cout<<0<<endl;
else
{
//if(flag==1) cnt--;
//cout<<cnt<<endl;
long long ans=1e18;
for(long long i=1;i<=cnt;i++)
{
long long tp=(cnt-i)*x+i*y;
if(ans>tp) ans=tp;
}
cout<<ans<<endl;
}
return 0;
}