CF997A.Convert to Ones
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
- Choose some substring of string a (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?
你有一个由 0 和 1 组成的字符串 a1,a2,…,an。
我们称连续的一段元素 ai,ai + 1,…,aj(其中 1≤ i≤ j≤ n)为字符串 a 的一个子串。
你可以任意次执行以下两种操作:
- 选择字符串 a 的某个子串(例如,可以选整个字符串),将其反转,花费 x 枚硬币(例如,「0101101」→ 「0111001」);
- 选择字符串 a 的某个子串(例如,可以选整个字符串,也可以只选单个字符),将其中每个字符取反(即 0 变为 1,1 变为 0),花费 y 枚硬币(例如,「0101101」→ 「0110001」)。
你可以按任意顺序执行这些操作,且允许对同一子串多次执行操作。
问:要将字符串变为全为 1 的字符串,最少需要花费多少枚硬币?
输入格式
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.
输入的第一行包含整数 n、x 和 y(1 ≤ n ≤ 300000,0≤x,y≤109)—— 分别表示字符串长度、第一种操作(子串翻转)的代价和第二种操作(子串中所有元素取反)的代价。
第二行包含一个长度为 n 的字符串 a,由字符 0 和 1 组成。
输出格式
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.
输出一个整数——为得到仅由数字 1 组成的字符串所需执行操作的最小总代价。若无需执行任何操作,则输出 0。
输入输出样例
输入#1
5 1 10 01000
输出#1
11
输入#2
5 10 1 01000
输出#2
2
输入#3
7 2 3 1111111
输出#3
0
说明/提示
In the first sample, at first you need to reverse substring [1…2], and then you need to invert substring [2…5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1+10=11.
In the second sample, at first you need to invert substring [1…1], and then you need to invert substring [3…5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1+1=2.
In the third example, string already consists only of ones, so the answer is 0.
在第一个样例中,首先需要翻转子串 [1…2],然后需要取反子串 [2…5]。
字符串变化过程如下:
«01000» → «10000» → «11111»。
操作的总代价为 1+10=11。
在第二个样例中,首先需要取反子串 [1…1],然后需要取反子串 [3…5]。
字符串变化过程如下:
«01000» → «11000» → «11111»。
总代价为 1+1=2。
在第三个样例中,字符串已全为 1,因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?