CF1923F.Shrink-Reverse
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a binary string s of length n (a string consisting of n characters, and each character is either 0 or 1).
Let's look at s as at a binary representation of some integer, and name that integer as the value of string s . For example, the value of 000 is 0 , the value of 01101 is 13 , "100000" is 32 and so on.
You can perform at most k operations on s . Each operation should have one of the two following types:
- SWAP: choose two indices i<j in s and swap si with sj ;
- SHRINK-REVERSE: delete all leading zeroes from s and reverse s .
For example, after you perform SHRINK-REVERSE on 000101100, you'll get 001101.What is the minimum value of s you can achieve by performing at most k operations on s ?
输入格式
The first line contains two integers n and k ( 2≤n≤5⋅105 ; 1≤k≤n ) — the length of the string s and the maximum number of operations.
The second line contains the string s of length n consisting of characters 0 and/or 1.
Additional constraint on the input: s contains at least one 1.
输出格式
Print a single integer — the minimum value of s you can achieve using no more than k operations. Since the answer may be too large, print it modulo 109+7 .
Note that you need to minimize the original value, not the remainder.
输入输出样例
输入#1
8 2 10010010
输出#1
7
输入#2
8 2 01101000
输出#2
7
输入#3
30 30 111111111111111111111111111111
输出#3
73741816
输入#4
14 1 10110001111100
输出#4
3197
说明/提示
In the first example, one of the optimal strategies is the following:
- 10010010 SWAP 00010110;
- 00010110 SWAP 00000111.
The value of 00000111 is 7 .In the second example, one of the optimal strategies is the following:
- 01101000 SHRINK 1101000 REVERSE 0001011;
- 0001011 SWAP 0000111.
The value of 0000111 is 7 .