-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1367C.cpp
49 lines (44 loc) · 1.11 KB
/
1367C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int myceil(int a, int b) {
return (a+b-1)/b;
}
int divider(int slot, int k, bool edgeL, bool edgeR) {
int res = 0;
if (!edgeL) slot -= k;
if (!edgeR) slot -= k;
if (slot > 0)
res = (int)ceil((double)slot / (double)(k+1));
else slot = 0;
return res;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector <int> pos;
FOR(i, 1, n+1) {
char w;
cin >> w;
if (w == '1') pos.push_back(i);
}
int siz = pos.size(), ans = 0;
FOR(i, 0, siz) {
if (i == 0) {
ans += divider(pos[i]-1, k, true, false);
}
else {
ans += divider(pos[i]-pos[i-1]-1, k, false, false);
}
if (i == siz-1) {
ans += divider(n-pos[i], k, false, true);
}
}
if (pos.empty()) ans = divider(n, k, true, true);
cout << ans << '\n';
}
}