This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
string s;
int main()
{
IOS
int n,k;
cin>>n>>k;
cin>>s;
stack<pair<char,int>>st;
for(int i=0;i<n;i++){
if(!st.size()){
st.push({s[i],1});
continue;
}
if(st.top().first!=s[i]){
st.push({s[i],1});
continue;
}
st.top().second++;
if(st.top().second==k){
st.pop();
}
}
string ans;
while(st.size()){
for(int i=0;i<st.top().second;i++){
ans.pb(st.top().first);
}
st.pop();
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |