1873D - 1D Eraser - CodeForces Solution


greedy implementation

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
	  using namespace std;
	  #define ll long long
	  #define vv vector<long long> 
	  #define mm map<long long, longlong>
	  #define st set<long long>
	  #define at for(int i=0; i<n ; i++)
	  int main(){
        int t; cin>>t; while(t--){
          int n, k;
		  cin>>n>>k;
		  string s;
		  cin>>s;
		  int count = 0;
			for(int i=0; i<n; i++){
				if(s[i]=='B') {
					s[i]='w';
					int x = min(i+k, n);
					for(int j=i; j<x; j++){
						if(s[j]=='B') {s[j]='w'; i=j-1;}
					}
					count++;
				}
			}
			cout<<count<<endl;
	  }}


Comments

Submit
0 Comments
More Questions

279A - Point on Spiral
1294D - MEX maximizing
447A - DZY Loves Hash
23B - Party
63D - Dividing Island
1203E - Boxers
1547F - Array Stabilization (GCD version)
358A - Dima and Continuous Line
1385C - Make It Good
651A - Joysticks
1474D - Cleaning
1588A - Two Arrays
816A - Karen and Morning
9D - How many trees
918B - Radio Station
15A - Cottage Village
1737B - Ela's Fitness and the Luxury Number
1425H - Huge Boxes of Animal Toys
1737A - Ela Sorting Books
768C - Jon Snow and his Favourite Number
1006C - Three Parts of the Array
81A - Plug-in
276C - Little Girl and Maximum Sum
1738D - Permutation Addicts
1348B - Phoenix and Beauty
186A - Comparing Strings
1281A - Suffix Three
1421C - Palindromifier
1443A - Kids Seating
963A - Alternating Sum