CF1923F.Shrink-Reverse

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a binary string ss of length nn (a string consisting of nn characters, and each character is either 0 or 1).

Let's look at ss as at a binary representation of some integer, and name that integer as the value of string ss. For example, the value of 000 is 00, the value of 01101 is 1313, "100000" is 3232 and so on.

You can perform at most kk operations on ss. Each operation should have one of the two following types:

  • SWAP: choose two indices i<ji \lt j in ss and swap sis_i with sjs_j;
  • SHRINK-REVERSE: delete all leading zeroes from ss and reverse ss.

For example, after you perform SHRINK-REVERSE on 000101100, you'll get 001101.

What is the minimum value of ss you can achieve by performing at most kk operations on ss?

给你一个长度为 nn 的二进制字符串 ss(即由 nn 个字符组成的字符串,每个字符为 0 或 1)。

将 ss 视为某个整数的二进制表示,并称该整数为字符串 ss 的值。例如,000 的值为 00,01101 的值为 1313,100000 的值为 3232,依此类推。

你最多可以对 ss 执行 kk 次操作。每次操作必须是以下两种类型之一:

  • SWAP(交换):在 ss 中选择两个下标 i<ji < j,并交换 sis_i 与 sjs_j;
  • SHRINK-REVERSE(缩略-反转):删除 ss 中所有前导零,然后将 ss 反转。

例如,对 000101100 执行 SHRINK-REVERSE 后,得到 001101。

通过最多执行 kk 次操作,你能使 ss 达到的最小可能值是多少?

输入格式

The first line contains two integers nn and kk (2≤n≤5⋅1052 \le n \le 5 \cdot 10^5; 1≤k≤n1 \le k \le n) — the length of the string ss and the maximum number of operations.

The second line contains the string ss of length nn consisting of characters 0 and/or 1.

Additional constraint on the input: ss contains at least one 1.

第一行包含两个整数 nn 和 kk(2≤n≤5⋅1052 \le n \le 5 \cdot 10^5;1≤k≤n1 \le k \le n)—— 分别表示字符串 ss 的长度以及操作次数上限。

第二行包含一个长度为 nn 的字符串 ss,由字符 0 和/或 1 组成。

输入的附加约束:ss 中至少包含一个 1。

输出格式

Print a single integer — the minimum value of ss you can achieve using no more than kk operations. Since the answer may be too large, print it modulo 109+710^{9} + 7.

Note that you need to minimize the original value, not the remainder.

输出一个整数——在最多使用 kk 次操作的前提下,你能达到的 ss 的最小值。由于答案可能过大,请对 109+710^{9} + 7 取模后输出。

注意:你需要最小化的是原始值,而非其取模后的余数。

输入输出样例

  • 输入#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:

  1. 10010010 →SWAP\xrightarrow{\texttt{SWAP}} 00010110;
  2. 00010110 →SWAP\xrightarrow{\texttt{SWAP}} 00000111.

The value of 00000111 is 77.

In the second example, one of the optimal strategies is the following:

  1. 01101000 →SHRINK\xrightarrow{\texttt{SHRINK}} 1101000 →REVERSE\xrightarrow{\texttt{REVERSE}} 0001011;
  2. 0001011 →SWAP\xrightarrow{\texttt{SWAP}} 0000111.

The value of 0000111 is 77.

在第一个例子中,一种最优策略如下:

  1. 10010010 →SWAP\xrightarrow{\texttt{SWAP}} 00010110;
  2. 00010110 →SWAP\xrightarrow{\texttt{SWAP}} 00000111。

00000111 的值为 77。

在第二个例子中,一种最优策略如下:

  1. 01101000 →SHRINK\xrightarrow{\texttt{SHRINK}} 1101000 →REVERSE\xrightarrow{\texttt{REVERSE}} 0001011;
  2. 0001011 →SWAP\xrightarrow{\texttt{SWAP}} 0000111。

0000111 的值为 77。

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

首页