#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 2e18;
const int sz = 2e5 + 5;
void _(){
int n,k;
cin >> n >> k;
vector<pair<char, int>> v;
string s;
cin >> s;
for(int i = 0; i < n; i++){
if(!v.empty() && v.back().second == k){
v.pop_back();
}if(!v.empty() && v.back().first==s[i]){
v.back().second++;
}else {
v.push_back({s[i], 1});
}
}if(!v.empty() && v.back().second == k){
v.pop_back();
}
for(auto i: v){
string c = string(i.second, i.first);
cout << c;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
_();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |