#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
508 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
6 ms |
632 KB |
Output is correct |
23 |
Correct |
6 ms |
632 KB |
Output is correct |
24 |
Correct |
6 ms |
888 KB |
Output is correct |
25 |
Correct |
6 ms |
888 KB |
Output is correct |
26 |
Correct |
7 ms |
900 KB |
Output is correct |
27 |
Correct |
6 ms |
900 KB |
Output is correct |
28 |
Correct |
7 ms |
900 KB |
Output is correct |
29 |
Correct |
7 ms |
1028 KB |
Output is correct |
30 |
Correct |
7 ms |
900 KB |
Output is correct |
31 |
Correct |
7 ms |
1028 KB |
Output is correct |
32 |
Correct |
7 ms |
900 KB |
Output is correct |
33 |
Correct |
7 ms |
900 KB |
Output is correct |
34 |
Correct |
7 ms |
900 KB |
Output is correct |
35 |
Correct |
7 ms |
896 KB |
Output is correct |