Devu and binary String
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Devu loves to play with binary strings a lot. One day he borrowed a binary string s of size n from his friend Churu. Before starting to play with it, he wants to make sure that string does not contain more than k consecutive equal characters. For achieving that, only kind of operation he is allowed to perform is to flip any ith character of the string.
As Devu is always in hurry to meet his girlfriend, he wants you to help him in finding out the minimum number of operations he will need. Also he wants you to print one of the possible modified string too.
- First line of input contains an integer T denoting the number of test cases.
- For each test case, there are two lines.
- First line contains two space separated integers n, k as defined in the problem.
- Next line contains string s of size n.
- For each test case, print two lines.
- First line should contain an integer corresponding to minimum number of operations Devu needs.
- In second line, print one of the possible modified strings.
Subtask #1: 20 points
- 1 ≤ T ≤ 100, 1 ≤ n ≤ 20, 1 ≤ k ≤ n
Subtask #2: 35 points
- 1 ≤ T ≤ 102, 1 ≤ n ≤ 103, 1 ≤ k ≤ n
Subtask #3: 45 points
- 1 ≤ T ≤ 105, 1 ≤ n ≤ 105, 1 ≤ k ≤ n
- Sum of n over all the test cases is ≤ 106
Input: 3 2 1 11 2 2 11 4 1 1001 Output: 1 10 0 11 2 1010
Example case 1: As 1 is occurring twice consecutively, we can convert 11 to 10 in a single operation.
Example case 2: You don't need to modify the string as it does not have more than 2 equal consecutive character.
Example case 3: As 0 is occurring twice consecutively, we can convert 1001 to 1010 in a two operations (Flip third and fourth character).
|Tags||admin, admin2, basic-math, easy, may15|
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions