A11360 | Shrink-Reverse
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $s_i$ with $s_j$ ;
- 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$ ?
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 $s_i$ with $s_j$ ;
- 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 \le n \le 5 \cdot 10^5$ ; $1 \le k \le 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.
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 $10^{9} + 7$ .
Note that you need to minimize the original value, not the remainder.
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:
1. 10010010 $\xrightarrow{\texttt{SWAP}}$ 00010110;
2. 00010110 $\xrightarrow{\texttt{SWAP}}$ 00000111.
The value of 00000111 is $7$ .In the second example, one of the optimal strategies is the following:
1. 01101000 $\xrightarrow{\texttt{SHRINK}}$ 1101000 $\xrightarrow{\texttt{REVERSE}}$ 0001011;
2. 0001011 $\xrightarrow{\texttt{SWAP}}$ 0000111.
The value of 0000111 is $7$ .
1. 10010010 $\xrightarrow{\texttt{SWAP}}$ 00010110;
2. 00010110 $\xrightarrow{\texttt{SWAP}}$ 00000111.
The value of 00000111 is $7$ .In the second example, one of the optimal strategies is the following:
1. 01101000 $\xrightarrow{\texttt{SHRINK}}$ 1101000 $\xrightarrow{\texttt{REVERSE}}$ 0001011;
2. 0001011 $\xrightarrow{\texttt{SWAP}}$ 0000111.
The value of 0000111 is $7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted