Convert to Ones(CF-998C)

Problem Description

You've got a string a1,a2,…,an, consisting of zeros and ones.

Let's call a sequence of consecutive elements ai,ai + 1,…, aj (1≤ i≤ j≤ n) a substring of string a.

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 x 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 y 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?

Input

The first line of input contains integers n, x and y (1 ≤ 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 a of length n, consisting of zeros and ones.

Output

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.

Examples

Input

5 1 10
01000

Output

11

Input

5 10 1
01000

Output

2

Input

7 2 3
1111111

Output

0

题意:给出一个长度为 n 的二进制串,有两种操作:将某一段反序,花费为 x;将某一段取反,花费为 y,求将这个串全都变为1的最小花费

思路:假设 0 的段数为cnt,则:如果 x<=y,那么就进行 cnt-1 次操作 1 和一次操作 2 ;如果 x>y,那么就进行 cnt 次操作 2 

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 100001
#define MOD 1e9+7
#define E 1e-6
#define LL long long
using namespace std;
int main()
{
    int n,x,y;
    string str;
    cin>>n>>x>>y;
    cin>>str;

    LL cnt=0;
    for(LL i=0;i<n;i++)
        if(str[i]=='0'&&str[i+1]=='1')
            cnt++;
    if(str[n-1]=='0')
        cnt++;

    LL minn;

    if(x<y)
        minn=x*(cnt-1)+y;
    else
        minn=y*cnt;

    if(cnt==0)
        minn=0;

    cout<<minn<<endl;

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值