Submission #206653

#TimeUsernameProblemLanguageResultExecution timeMemory
206653mayhoubsalehTreasure (info1cup19_treasure)C++14
100 / 100
7 ms1028 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...