1367C.md (3300B)
1 Source: https://codeforces.com/problemset/problem/1367/C 2 3 C. Social Distance 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Polycarp and his friends want to visit a new restaurant. The restaurant has $n$ tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from $1$ to $n$ in the order from left to right. The state of the restaurant is described by a string of length $n$ which contains characters "1" (the table is occupied) and "0" (the table is empty). 22 23 Restaurant rules prohibit people to sit at a distance of $k$ or less from each other. That is, if a person sits at the table number $i$, then all tables with numbers from $i-k$ to $i+k$ (except for the $i$-th) should be free. In other words, the absolute difference of the numbers of any two occupied tables must be strictly greater than $k$. 24 25 For example, if $n=8$ and $k=2$, then: 26 27 * strings "10010001", "10000010", "00000000", "00100000" satisfy the rules of the restaurant; 28 * strings "10100100", "10011001", "11111111" do not satisfy to the rules of the restaurant, since each of them has a pair of "1" with a distance less than or equal to $k=2$. 29 30 In particular, if the state of the restaurant is described by a string without "1" or a string with one "1", then the requirement of the restaurant is satisfied. 31 32 You are given a binary string $s$ that describes the current state of the restaurant. It is guaranteed that the rules of the restaurant are satisfied for the string $s$. 33 34 Find the maximum number of free tables that you can occupy so as not to violate the rules of the restaurant. Formally, what is the maximum number of "0" that can be replaced by "1" such that the requirement will still be satisfied? 35 36 For example, if $n=6$, $k=1$, $s=$ "100010", then the answer to the problem will be $1$, since only the table at position $3$ can be occupied such that the rules are still satisfied. 37 38 Input 39 40 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. Then $t$ test cases follow. 41 42 Each test case starts with a line containing two integers $n$ and $k$ ($1 \le k \le n \le 2\cdot 10^5$) — the number of tables in the restaurant and the minimum allowed distance between two people. 43 44 The second line of each test case contains a binary string $s$ of length $n$ consisting of "0" and "1" — a description of the free and occupied tables in the restaurant. The given string satisfy to the rules of the restaurant — the difference between indices of any two "1" is more than $k$. 45 46 The sum of $n$ for all test cases in one test does not exceed $2\cdot 10^5$. 47 48 Output 49 50 For each test case output one integer — the number of tables that you can occupy so as not to violate the rules of the restaurant. If additional tables cannot be taken, then, obviously, you need to output $0$. 51 52 Example 53 54 Input 55 56 ``` 57 6 58 6 1 59 100010 60 6 2 61 000000 62 5 1 63 10101 64 3 1 65 001 66 2 2 67 00 68 1 1 69 0 70 ``` 71 72 Output 73 74 ``` 75 1 76 2 77 0 78 1 79 1 80 1 81 ``` 82 83 Note 84 85 The first test case is explained in the statement. 86 87 In the second test case, the answer is $2$, since you can choose the first and the sixth table. 88 89 In the third test case, you cannot take any free table without violating the rules of the restaurant.