CF 797, got stuck on E and had to leave, went pretty well

This commit is contained in:
2022-06-07 21:38:41 +02:00
parent a2acadbf3e
commit 6de228cf8a
7 changed files with 346 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
#include <bits/stdc++.h>
using namespace std;
void test_case(int tc){
int n, k;
cin >> n >> k;
vector<bool> strip;
int blacks = 0;
int whites = 0;
for(int i = 0; i < k; ++i){
char c;
cin >> c;
if(c == 'B'){
blacks++;
strip.push_back(true);
} else{
whites++;
strip.push_back(false);
}
}
int min_whites = whites;
for(int i = 0; i < n - k; ++i){
char c;
cin >> c;
if(strip[i]){
blacks--;
} else {
whites--;
}
if(c == 'B'){
blacks++;
strip.push_back(true);
} else {
whites++;
strip.push_back(false);
}
min_whites = min(min_whites, whites);
}
cout << min_whites << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int tc = 1; tc <= t; ++tc){
test_case(tc);
}
cout << flush;
return 0;
}