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.
In the third example, string already consists only of ones, so the answer is 00.
题意就是有两种处理字符串的方法 选取子串逆转或者取反,分别给出代价X和Y,问最少花多少代价可以变成只含1的串
仔细思考一下其实无非两种情况
如果x<y 就优先逆转,把所有0块区间合成一个0块区间 然后取反 代价(sum-1)*x+y
如果x>y 直接把每个0块区间取反好了 代价 sum*y
记得操作之前统计好有多少个0块区间sum
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <assert.h>
#include <fstream>
using namespace std;
int main(){
long long n,x,y;
cin>>n>>x>>y;
string s;
cin>>s;
int len=s.size();
int sum=0;
for(int i=0;i<len-1;i++){
if(s[i]=='0'&&s[i+1]=='1')
sum++;
}
if(s[len-1]=='0')
sum++;
long long res=0;
if(x<y){
res=(sum-1)*x+y;
}
else{
res=sum*y;
}
if(sum==0) res=0;
cout<<res<<endl;
}