A12988 | Binary String Minimizing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a binary string of length $n$ (i. e. a string consisting of $n$ characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $k$ moves? It is possible that you do not perform any moves at all.
Note that you can swap the same pair of adjacent characters with indices $i$ and $i+1$ arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.
You have to answer $q$ independent test cases.
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $k$ moves? It is possible that you do not perform any moves at all.
Note that you can swap the same pair of adjacent characters with indices $i$ and $i+1$ arbitrary (possibly, zero) number of times. Each such swap is considered a separate move.
You have to answer $q$ independent test cases.
输入格式
The first line of the input contains one integer $q$ ( $1 \le q \le 10^4$ ) — the number of test cases.
The first line of the test case contains two integers $n$ and $k$ ( $1 \le n \le 10^6, 1 \le k \le n^2$ ) — the length of the string and the number of moves you can perform.
The second line of the test case contains one string consisting of $n$ characters '0' and '1'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ( $\sum n \le 10^6$ ).
The first line of the test case contains two integers $n$ and $k$ ( $1 \le n \le 10^6, 1 \le k \le n^2$ ) — the length of the string and the number of moves you can perform.
The second line of the test case contains one string consisting of $n$ characters '0' and '1'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ( $\sum n \le 10^6$ ).
输出格式
For each test case, print the answer on it: the lexicographically minimum possible string of length $n$ you can obtain from the given one if you can perform no more than $k$ moves.
输入输出样例
输入 #1
3 8 5 11011010 7 9 1111100 7 11 1111100
输出 #1
01011110 0101111 0011111
In the first example, you can change the string as follows: $1\underline{10}11010 \rightarrow \underline{10}111010 \rightarrow 0111\underline{10}10 \rightarrow 011\underline{10}110 \rightarrow 01\underline{10}1110 \rightarrow 01011110$ .
In the third example, there are enough operations to make the string sorted.
In the third example, there are enough operations to make the string sorted.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted