CF1411D.Grime Zoo

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write xx angry comments for every occurrence of subsequence 01 and yy angry comments for every occurrence of subsequence 10. You should replace all the question marks with 0 or 1 in such a way that the number of angry comments would be as small as possible.

String bb is a subsequence of string aa, if it can be obtained by removing some characters from aa. Two occurrences of a subsequence are considered distinct if sets of positions of remaining characters are distinct.

目前,XXOC 的说唱是一段由数字 0、1 和问号 ? 组成的字符串。不幸的是,黑粉总会黑你。对于每一个子序列 01 的出现,他们会留下 xx 条愤怒评论;对于每一个子序列 10 的出现,他们会留下 yy 条愤怒评论。你需要将所有问号 ? 替换为 0 或 1,使得愤怒评论的总数尽可能少。

若字符串 bb 可通过从字符串 aa 中删除若干字符得到,则称 bb 是 aa 的一个子序列。若两个子序列出现所对应保留字符的位置集合不同,则认为它们是两个不同的出现。

输入格式

The first line contains string ss — XXOC's rap (1≤∣s∣≤1051 \le |s| \leq 10^5). The second line contains two integers xx and yy — the number of angry comments XXOC will recieve for every occurrence of 01 and 10 accordingly (0≤x,y≤1060 \leq x, y \leq 10^6).

第一行包含字符串 ss — XXOC 的说唱内容(1≤∣s∣≤1051 \le |s| \leq 10^5)。第二行包含两个整数 xx 和 yy — 分别表示每出现一次子串 01 和 10 时,XXOC 将收到的愤怒评论数(0≤x,y≤1060 \leq x, y \leq 10^6)。

输出格式

Output a single integer — the minimum number of angry comments.

输出一个整数——愤怒评论的最少数量。

输入输出样例

  • 输入#1

    0?1
    2 3

    输出#1

    4
  • 输入#2

    ?????
    13 37

    输出#2

    0
  • 输入#3

    ?10?
    239 7

    输出#3

    28
  • 输入#4

    01101001
    5 7

    输出#4

    96

说明/提示

In the first example one of the optimum ways to replace is 001. Then there will be 22 subsequences 01 and 00 subsequences 10. Total number of angry comments will be equal to 2⋅2+0⋅3=42 \cdot 2 + 0 \cdot 3 = 4.

In the second example one of the optimum ways to replace is 11111. Then there will be 00 subsequences 01 and 00 subsequences 10. Total number of angry comments will be equal to 0⋅13+0⋅37=00 \cdot 13 + 0 \cdot 37 = 0.

In the third example one of the optimum ways to replace is 1100. Then there will be 00 subsequences 01 and 44 subsequences 10. Total number of angry comments will be equal to 0⋅239+4⋅7=280 \cdot 239 + 4 \cdot 7 = 28.

In the fourth example one of the optimum ways to replace is 01101001. Then there will be 88 subsequences 01 and 88 subsequences 10. Total number of angry comments will be equal to 8⋅5+8⋅7=968 \cdot 5 + 8 \cdot 7 = 96.

在第一个例子中,一种最优的替换方式是 001。此时将有 22 个子序列 01 和 00 个子序列 10。愤怒评论的总数为 2⋅2+0⋅3=42 \cdot 2 + 0 \cdot 3 = 4。

在第二个例子中,一种最优的替换方式是 11111。此时将有 00 个子序列 01 和 00 个子序列 10。愤怒评论的总数为 0⋅13+0⋅37=00 \cdot 13 + 0 \cdot 37 = 0。

在第三个例子中,一种最优的替换方式是 1100。此时将有 00 个子序列 01 和 44 个子序列 10。愤怒评论的总数为 0⋅239+4⋅7=280 \cdot 239 + 4 \cdot 7 = 28。

在第四个例子中,一种最优的替换方式是 01101001。此时将有 88 个子序列 01 和 88 个子序列 10。愤怒评论的总数为 8⋅5+8⋅7=968 \cdot 5 + 8 \cdot 7 = 96。

输入解题思路,AI测评打分。不知道怎么写?

首页