1D Eraser
Problem
You are given a strip of paper s that is n cells long. Each cell is either black or white. In an operation you can take any k consecutive cells and make them all white.
Find the minimum number of operations needed to remove all black cells.
Input
The first line contains a single integer ttt (1≤t≤1000)(1≤t≤1000)(1≤t≤1000) — the number of test cases.
The first line of each test case contains two integers nnn and kkk (1≤k≤n≤2⋅105)(1≤k≤n≤2⋅10^5)(1≤k≤n≤2⋅105) — the length of the paper and the integer used in the operation.
The second line of each test case contains a string s of length n consisting of characters B
(representing a black cell) or W (representing a white cell).
The sum of n over all test cases does not exceed 2⋅1052⋅10^52⋅105.
Output
For each test case, output a single integer — the minimum number of operations needed to remove all black cells.
Example
Input
8
6 3
WBWWWB
7 3
WWBWBWW
5 4
BWBWB
5 5
BBBBB
8 2
BWBWBBBB
10 2
WBBWBBWBBW
4 1
BBBB
3 2
WWW
Output
2
1
2
1
4
3
4
0
Note
- In the first test case you can perform the following operations:
WBW
WWB→WWWWWB
→WWWWWW - In the second test case you can perform the following operations:
WWBWB
WW→WWWWWWW - In the third test case you can perform the following operations:
BWBWB
→BWWW
W→WWWWW
Code
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+10;
ll a[N];
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
string s;
cin>>s;
ll sum=0;
for(ll i=0,j=0;i<n;i++)
{
if(s[i]=='B')
{
sum++;
while(j-i<k) j++;
i=j-1;
}
else j++;
}
cout<<sum<<endl;
}
return 0;
}