이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |