#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 |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
640 KB |
Output is correct |
23 |
Correct |
6 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
768 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
7 ms |
896 KB |
Output is correct |
27 |
Correct |
7 ms |
1024 KB |
Output is correct |
28 |
Correct |
7 ms |
896 KB |
Output is correct |
29 |
Correct |
7 ms |
896 KB |
Output is correct |
30 |
Correct |
7 ms |
896 KB |
Output is correct |
31 |
Correct |
7 ms |
896 KB |
Output is correct |
32 |
Correct |
7 ms |
948 KB |
Output is correct |
33 |
Correct |
7 ms |
896 KB |
Output is correct |
34 |
Correct |
7 ms |
768 KB |
Output is correct |
35 |
Correct |
7 ms |
768 KB |
Output is correct |