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>
using namespace std;
stack<pair<char,int>>a;
int n,k,i,nr;
char s[200004],b[200004];
int main()
{
//freopen("input","r",stdin);
cin.sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
cin>>(s+1);
for(i=1; i<=n; ++i)
{
if(a.empty())
a.push({s[i],1});
else if(s[i]==a.top().first)
{
a.top().second++;
if(a.top().second==k)
a.pop();
}
else
a.push({s[i],1});
}
nr=0;
while(!a.empty())
{
for(i=1; i<=a.top().second; i++)
b[++nr]=a.top().first;
a.pop();
}
reverse(b+1,b+nr+1);
for(i=1; i<=nr; i++)
cout<<b[i];
cout<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |