Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B'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). 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 . For example, if n=8 and k=2 , then: 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. 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 . 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? 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. The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases in the test. Then t test cases follow. Each test case starts with a line containing two integers n and k ( 1 <= k <= n <= 2 cdot 10^5 ) -- the number of tables in the restaurant and the minimum allowed distance between two people. The second line of each test case co'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
84024288 |
rajvivek239 |
C |
June 16, 2020, 4:58 p.m. |
OK |
Clang++17 Diagnostics |
TESTS |
7 |
202 |
16179200 |
|
|
83985711 |
ruban |
C |
June 16, 2020, 3:27 p.m. |
OK |
Delphi |
TESTS |
4 |
46 |
121036800 |
|
|
84013821 |
EgorStar |
C |
June 16, 2020, 4:21 p.m. |
OK |
Delphi |
TESTS |
4 |
61 |
1331200 |
|
|
84011333 |
Kakoi-to-chelovechek |
C |
June 16, 2020, 4:15 p.m. |
OK |
FPC |
TESTS |
4 |
46 |
0 |
|
|
84012731 |
madv809 |
C |
June 16, 2020, 4:18 p.m. |
OK |
FPC |
TESTS |
4 |
46 |
614400 |
|
|
remove filters
Back to search problems