fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. void pVec(vector<int> f){
  6. for(auto i : f) cout << f[i] << " ";
  7. cout << endl;
  8. }
  9. int main() {
  10. int t; cin >> t;
  11. while(t--){
  12. int n,k; cin >> n >> k;
  13. string s; cin >> s;
  14. char p = 'B';
  15. vector<int> b(n+1,0);
  16. for(int i=0;i<n;i++){
  17. if(s[i] == 'B') b[i+1] = b[i] + 1;
  18. else if(s[i] == '?' && k>0) b[i+1] = b[i] + 1,k--;
  19. else b[i+1] = b[i];
  20. }
  21. int sub = 0, bs = b.size();
  22. pVec(b);
  23. // for(int i = 0;i<n;i++){
  24. // sub += b[n-i] - b[i+1];
  25. // }
  26. cout << sub << endl;
  27.  
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5268KB
stdin
2
6 2
AABC?B
3 3
?B?
stdout
0 0 0 0 0 0 1 
0
0 1 2 3 
0