#15774. [SDCPC 2023] Difficult Constructive Problem

    ID: 15774 传统题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P9566动态规划 DP贪心2023山东O2优化分类讨论省赛/邀请赛

[SDCPC 2023] Difficult Constructive Problem

[SDCPC 2023] Difficult Constructive Problem

题目描述

Given a string $s_1s_2\cdots s_n$ of length $n$ where $s_i \in \{\text{0}, \text{1}, \text{?}\}$ and an integer $k$, please fill out all the $\text{?}$ with $\text{0}$ or $\text{1}$ such that the number of indices $i$ satisfying $1 \le i

To make this problem even more difficult, we ask you to find the answer with the smallest possible lexicographic order if it exists.

Recall that a string a1a2⋯ana_1a_2\cdots a_n of length nn is lexicographically smaller than another string b1b2⋯bnb_1b_2\cdots b_n of length nn if there exists an integer kk (1≤k≤n1 \le k \le n) such that ai=bia_i = b_i for all 1≤i<k1 \le i < k and ak<bka_k < b_k.

输入格式

There are multiple test cases. The first line of the input contains an integer $T$ indicating the number of test cases. For each test case:

The first line contains two integers nn and kk (1≤n≤1051 \le n \le 10^5, 0≤k<n0 \le k < n) indicating the length of the string and the required number of indices satisfying the condition.

The second line contains a string s1s2,⋯sns_1s_2,\cdots s_n (si∈{0,1,?}s_i \in \{\text{0}, \text{1}, \text{?}\}).

It's guaranteed that the sum of nn of all test cases will not exceed 10610^6.

输出格式

For each test case output one line. If the answer exists output the lexicographically smallest one (you need to output the whole given string after filling out all the $\text{?}$ and make this string the lexicographically smallest); Otherwise output `Impossible`.
5
9 6
1?010??01
9 5
1?010??01
9 6
100101101
9 5
100101101
9 3
????????1
100100101
Impossible
100101101
Impossible
000000101

提示

(暂无提示) 标签: P9566|动态规划 DP|贪心|2023|山东|O2优化|分类讨论|省赛/邀请赛

来源

P9566|[SDCPC 2023] Difficult Constructive Problem