#P15650. [省选联考 2026] 摩卡串

    ID: 17713 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>字符串各省省选Special JudgeO2优化最短路哈希 hashingKMP 算法有限状态自动机构造2026DP 套 DP

[省选联考 2026] 摩卡串

Background

Little Mocha is a genius, especially in string theory, where she has an extraordinary talent. To praise her talent, people often name strings that satisfy certain beautiful properties as “Mocha strings”.

Problem Description

Little H has a binary string ss of length nn and a positive integer kk. He defines a binary string t=t1tmt = t_1 \dots t_m of length mm to be a Mocha string if and only if tt satisfies the following two conditions:

  • ss is a substring of tt, i.e., there exist 1lrm1 \le l \le r \le m such that s=tltrs = t_l \dots t_r;
  • There are exactly kk substrings of tt whose lexicographic order is strictly smaller than ss. Two substrings are different if and only if they have different lengths or different positions. Formally, there exist exactly kk pairs (l,r)(l, r) such that 1lrm1 \le l \le r \le m and tltrt_l \dots t_r is lexicographically strictly smaller than ss.

Since there may be many Mocha strings that satisfy the conditions, Little H wants to find a shortest Mocha string among them. You need to help him find any one of them.

Input Format

This problem contains multiple test cases.

The first line of input contains two non-negative integers c,tc, t, representing the test point ID and the number of test cases, respectively. c=0c = 0 means this test point is a sample.

Then the test cases follow. For each test case:

  • The first line contains two positive integers n,kn, k.
  • The second line contains a binary string ss of length nn.

Output Format

For each test case, output one line with a binary string, representing any shortest Mocha string. In particular, if no Mocha string exists, output Impossible.

0 5
1 1
1
1 1
0
3 9
101
4 17
1100
4 20
1100
10
Impossible
0101
011100
001100

Hint

Sample 2

See string/string2.in and string/string2.ans in the contestant directory.

This sample satisfies the constraints of test points 464 \sim 6.

Sample 3

See string/string3.in and string/string3.ans in the contestant directory.

This sample satisfies the constraints of test points 797 \sim 9.

Sample 4

See string/string4.in and string/string4.ans in the contestant directory.

This sample satisfies the constraints of test points 101210 \sim 12.

Sample 5

See string/string5.in and string/string5.ans in the contestant directory.

This sample satisfies the constraints of test points 131513 \sim 15.

Sample 6

See string/string6.in and string/string6.ans in the contestant directory.

This sample satisfies the constraints of test points 161816 \sim 18.

Sample 7

See string/string7.in and string/string7.ans in the contestant directory.

This sample satisfies the constraints of test points 19,2019, 20.

Constraints

For all testdata, we have:

  • 1t51 \le t \le 5;
  • 1n2001 \le n \le 200, 1k3,0001 \le k \le 3,000;
  • For all 1in1 \le i \le n, we have si{0,1}s_i \in \{0, 1\}.

::cute-table{tuack}

Test Point ID nn \le kk \le Special Property
131 \sim 3 1515 200200 A
464 \sim 6 5050 2,0002,000 B
797 \sim 9 ^ ^ C
101210 \sim 12 D
131513 \sim 15 500500 None
161816 \sim 18 150150 2,0002,000 ^
19,2019, 20 200200 3,0003,000
  • Special Property A: If a Mocha string exists, then there exists a Mocha string of length at most 1515.
  • Special Property B: For all 1in1 \le i \le n, we have si=0s_i = 0.
  • Special Property C: For all 1in1 \le i \le n, we have si=1s_i = 1.
  • Special Property D: There exists a positive integer p[1,n]p \in [1,n] such that s1==sp=0s_1 = \dots = s_p = 0 and sp+1==sn=1s_{p+1} = \dots = s_n = 1.

Translated by ChatGPT 5