#abc346d. D - Gomamayo Sequence
D - Gomamayo Sequence
Score: points
问题陈述
给定一个由0
和1
组成的字符串,长度为。
一个由0
和1
组成的字符串是好字符串,当且仅当它满足以下条件:
- 存在一个且只有一个整数,使得,并且的第个和第个字符相同。
对于每个,你可以选择是否执行以下操作一次:
- 如果的第个字符是
0
,则将其替换为1
,反之亦然。如果执行了这个操作,其成本为。
找出使成为好字符串所需的最小总成本。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of 0
and 1
.
A string of length consisting of 0
and 1
is a good string if and only if it satisfies the following condition:
- There is exactly one integer such that and the -th and -th characters of are the same.
For each , you can choose whether or not to perform the following operation once:
- If the -th character of is
0
, replace it with1
, and vice versa. The cost of this operation, if performed, is .
Find the minimum total cost required to make a good string.
Constraints
- is a string of length consisting of
0
and1
. - and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5
00011
3 9 2 6 4
Sample Output 1
7
Performing the operation for and not performing it for makes 10010
, which is a good string. The cost incurred in this case is , and it is impossible to make a good string for less than , so print .
Sample Input 2
4
1001
1 2 3 4
Sample Output 2
0
Sample Input 3
11
11111100111
512298012 821282085 543342199 868532399 690830957 973970164 928915367 954764623 923012648 540375785 925723427
Sample Output 3
2286846953
update @ 2024/5/16 17:17:59