-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1690D.cpp
More file actions
66 lines (53 loc) · 1.05 KB
/
1690D.cpp
File metadata and controls
66 lines (53 loc) · 1.05 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// coded by Cocane
#include <bits/stdc++.h>
#define ll long long
#define forn(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define foru(i, n) for (int i = n - 1; i >= 0; i--)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ppb pop_back
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef double dl;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n, k;
string s;
cin >> n >> k >> s;
if (k == 1)
{
int x = count(all(s), 'B');
cout << (x == 0 ? 1 : 0) << endl;
}
else
{
int currWhite = 0;
for (int i = 0; i < k; i++)
{
if (s[i] == 'W')
currWhite++;
}
int mnWhite = currWhite;
for (int i = k; i < n; i++)
{
if (s[i - k] == 'W')
currWhite--;
if (s[i] == 'W')
currWhite++;
mnWhite = min(mnWhite, currWhite);
}
cout << mnWhite << endl;
}
}
return 0;
}